summaryrefslogtreecommitdiff
path: root/scripts/update-helpstring.pl
blob: 54a0eb16501959bac09f5a0ea1c0e3063e57e8d6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/perl

# Author: Arthur Xiong
# Date: 06/21/2010
# Description: Script to automatically update help string for each 
#              node.def according to the inputs 

# **** License ****
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# This code was originally developed by Vyatta, Inc.
# Portions created by Vyatta are Copyright (C) 2006-2010 Vyatta, Inc.
# All Rights Reserved.
#
# **** End License ****

use strict;
use warnings;

die "Usage: update-helpstring.pl <helpstring-file> <path-to-template>"
 unless $#ARGV == 1;

my $helpstring;
my $path;
my $comment;
my $help_line;
my $node_def;
my $helpstring_file = $ARGV[0];
my $prefix  = $ARGV[1];

open my $hf, '<', $helpstring_file or die "$helpstring_file can't be opened";
while (<$hf>) {    
    chomp;
    next if /^#.*/ or /^\s*$/;
    die "Syntax Error \"$_\"" unless /^(\S+)\s+\|\s*(\S.*)$/;
    $path = $1;
    $helpstring = $2;

    $help_line = "";
    $help_line = "help: " . $helpstring . "\n";
    print "$help_line";

    $node_def = "";
    $node_def = $prefix . "/" . $path . "/" . "node.def";

    open my $nf, '<', $node_def  or die "$node_def can't be opened";
    open my $nfn, '>', "$node_def.new" or die "$node_def.new can't be opened";
    while (<$nf>) {
        if ( /^help:/ ) {
            print $nfn $help_line;
        } else {
            print $nfn $_;
        }
    }
    close $nfn;
    close $nf;

    rename "$node_def.new", "$node_def"
     or die "$node_def.new can't be renamed to $node_def";

    print "Updated $node_def\n\n";
}
close $hf;