Repository navigation
Expand file tree
/
Copy pathgenerate_commandline.pl
More file actions
executable file
·85 lines (75 loc) · 1.77 KB
/
Copy pathgenerate_commandline.pl
File metadata and controls
executable file
·85 lines (75 loc) · 1.77 KB
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Long;
sub usage {
print "generate_commandline.pl >>> create API commandline scripts\n";
print "generate_commandline.pl -template <template file name> -config <configuration file name> [ -outdir <output directory> ]\n";
}
my $template = '';
my $outdir = '';
my $config = '';
GetOptions ( 'template=s' => \$template,
'config=s' => \$config,
'outdir=s' => \$outdir );
unless ($template && $config) {
&usage();
exit 0;
}
my $t = [];
if (open(FH, "<$template")) {
while (<FH>) {
chomp;
push(@$t, $_);
}
close FH;
$t = join("###", @$t);
} else {
print "could not open template file '$template': $@\n";
exit;
}
my $data = {};
if (open(FH, "<$config")) {
my $curr = undef;
while (<FH>) {
chomp;
my ($key, $val) = split /\t/;
next unless ($key && $val);
next if ($key =~ /^#/);
if ($key eq 'resource') {
$curr = $val;
$data->{$curr} = { resource => $val };
} else {
$data->{$curr}->{$key} = $val;
}
}
close FH;
foreach my $key (keys(%$data)) {
next if ($key eq "default");
my $currt = $t;
foreach my $k (keys(%{$data->{$key}})) {
my $v = $data->{$key}->{$k};
$currt =~ s/##$k##/$v/g;
}
if (exists($data->{default})) {
foreach my $k (keys(%{$data->{default}})) {
my $v = $data->{default}->{$k};
$currt =~ s/##$k##/$v/g;
}
}
my @rows = split(/###/, $currt);
if (open(FH, ">$outdir/$key")) {
foreach my $row (@rows) {
print FH $row."\n";
}
close FH;
} else {
print "could not open script file for output '$outdir/$key': $@\n";
exit;
}
}
} else {
print "could not open config file '$config': $@\n";
exit;
}
print "all done.\nHave a nice day :)\n\n";