|
| 1 | +#!/usr/bin/perl -w |
| 2 | + |
| 3 | +=pod |
| 4 | + |
| 5 | +=head1 SYNOPSIS |
| 6 | +
|
| 7 | + install_batch.pl [OPTIONS] |
| 8 | + Options: |
| 9 | + --help Brief help message |
| 10 | + --dry-run Doesn't execute the command, only prints it to STDOUT |
| 11 | + --file Input file with each line represents a input. |
| 12 | + A line can have multiple elements separated by --element-separator. |
| 13 | + Lines everything after a # is interpreted as comment |
| 14 | + --element-separator Separates elements in a line of the input file |
| 15 | + --combining-template Templates which combines all joined templates |
| 16 | + for the lines of the input file into one string. |
| 17 | + The templates are addressed with <<<<0>>>>, ,,, |
| 18 | + --templates Pairs of template and separator pair. |
| 19 | + The template is applied for each line in the input file and |
| 20 | + than joined together with the separator. |
| 21 | + The elements of a line are addressed with <<<<0>>>>, ,,, |
| 22 | + |
| 23 | +=cut |
| 24 | + |
| 25 | +use strict; |
| 26 | +use File::Basename; |
| 27 | +use lib dirname (__FILE__); |
| 28 | +use utils; |
| 29 | +use Getopt::Long; |
| 30 | +use Pod::Usage; |
| 31 | + |
| 32 | +my $help = 0; |
| 33 | +my $dry_run = 0; |
| 34 | +my $file = ''; |
| 35 | +my $element_separator = ''; |
| 36 | +my $combining_template = ''; |
| 37 | +my @template_separator_array = (); |
| 38 | + |
| 39 | +GetOptions ( |
| 40 | + "help" => \$help, |
| 41 | + "dry-run" => \$dry_run, |
| 42 | + "file=s" => \$file, |
| 43 | + "element-separator=s" => \$element_separator, |
| 44 | + "combining-template=s" => \$combining_template, |
| 45 | + "templates=s{2,}" => \@template_separator_array |
| 46 | + ) or pod2usage(2); |
| 47 | +pod2usage(1) if $help; |
| 48 | + |
| 49 | + |
| 50 | +if($file eq ''){ |
| 51 | + pod2usage("Error in command line arguments: --file was not specified"); |
| 52 | +} |
| 53 | +if($element_separator eq ''){ |
| 54 | + pod2usage("Error in command line arguments: --element-separator was not specified"); |
| 55 | +} |
| 56 | +if($combining_template eq ''){ |
| 57 | + pod2usage("Error in command line arguments: --combining_template was not specified"); |
| 58 | +} |
| 59 | + |
| 60 | + |
| 61 | +if($#template_separator_array < 1 and ($#template_separator_array+1) % 2 != 0){ |
| 62 | + pod2usage("Error in command line arguments: --templates need to be specified in pairs of template and separator"); |
| 63 | +} |
| 64 | +my @templates = (); |
| 65 | +my @separators = (); |
| 66 | +for (my $i = 0; $i < $#template_separator_array; $i += 2) { |
| 67 | + push(@templates,$template_separator_array[$i]); |
| 68 | + push(@separators,$template_separator_array[$i+1]); |
| 69 | +} |
| 70 | + |
| 71 | +my $cmd = |
| 72 | + utils::generate_joined_and_transformed_string_from_file( |
| 73 | + $file,$element_separator,$combining_template,\@templates,\@separators); |
| 74 | + |
| 75 | +utils::execute("$cmd",$dry_run) |
0 commit comments