From 52a314f2a94c579a422f31a0fd9dbab01d880fd4 Mon Sep 17 00:00:00 2001 From: Roan Horning Date: Fri, 19 Aug 2022 22:11:38 -0400 Subject: [PATCH] Add command line option all Use --all or -a when calling site-generator instead of special page ALL to generate all the configured pages for a website. --- README.md | 2 +- site-generator | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 1b91dfe..1bdf28f 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ Generate two specific pages: `site-generator index about` Generate the whole site: -`site-generator ALL` +`site-generator --all` Generate pages based on the same template: `site-generator correspondent=1,3,5..10` diff --git a/site-generator b/site-generator index 562b6a6..63ff568 100755 --- a/site-generator +++ b/site-generator @@ -8,6 +8,7 @@ site-generator [OPTION]... PAGE|PAGE=... + -a, --all generate all pages defined in configuration file -l, --list print list of configured pages -p, --preview print generated pages to standard out -q, --quiet suppress progress information while generating pages @@ -92,33 +93,32 @@ exit main(); sub main { # Argument parsing + my $all; my $preview; my $verbose; my $quiet; GetOptions( + 'all' => \$all, 'list' => \&print_available_pages, 'preview' => \$preview, 'verbose' => \$verbose, 'quiet' => \$quiet, ) or pod2usage(1); - pod2usage(1) unless @ARGV; + pod2usage(1) unless @ARGV || $all; my (@page_args) = @ARGV; if ($quiet) { $verbose = 'quiet'; }; - # Set flag indicating whether or not to generate all pages. - # The flag is set to true if the special argument ALL is - # passed into the generator - my $ALL = grep { $_ eq 'ALL' } @page_args; - # Load config file read_config "site.cfg" => my %config; my $tt = get_template_html($config{DBI}); - if ($ALL) { + # If command line option all is set, parse configuration file + # for all pages + if ($all) { @page_args = keys %config; # Remove non page sections of the configuration file