Add command line option for path to configuration file

Allow user to pass the path to the configuration file into the
site-generator.
This commit is contained in:
Roan Horning 2023-03-08 22:23:56 -05:00
parent 0f4fdc2d46
commit 14bafbc3ab
Signed by untrusted user: rho_n
GPG Key ID: 234AEF20B72D5769

View File

@ -8,12 +8,13 @@
site-generator [OPTION]... PAGE|PAGE=<comma separated list of ids>... site-generator [OPTION]... PAGE|PAGE=<comma separated list of ids>...
-a, --all generate all pages defined in configuration file -a, --all generate all pages defined in configuration file
-l, --list print list of configured pages -c, --configure path to configuration file
-p, --preview print generated pages to standard out -l, --list print list of configured pages
-q, --quiet suppress progress information while generating pages -p, --preview print generated pages to standard out
-v, --verbose print extended progress information while generating pages -q, --quiet suppress progress information while generating pages
--help print this help message -v, --verbose print extended progress information while generating pages
--help print this help message
Where I<PAGE> is a file name of a web page Where I<PAGE> is a file name of a web page
or the special I<ALL> (to generate all pages). or the special I<ALL> (to generate all pages).
@ -109,15 +110,17 @@ sub main {
# Argument parsing # Argument parsing
my $all; my $all;
my $configuration_path;
my $preview; my $preview;
my $verbose; my $verbose;
my $quiet; my $quiet;
GetOptions( GetOptions(
'all' => \$all, 'all' => \$all,
'list' => \&print_available_pages, 'configuration=s' => \$configuration_path,
'preview' => \$preview, 'list' => \&print_available_pages,
'verbose' => \$verbose, 'preview' => \$preview,
'quiet' => \$quiet, 'verbose' => \$verbose,
'quiet' => \$quiet,
) or pod2usage(1); ) or pod2usage(1);
pod2usage(1) unless @ARGV || $all; pod2usage(1) unless @ARGV || $all;
my (@page_args) = @ARGV; my (@page_args) = @ARGV;
@ -126,8 +129,19 @@ sub main {
$verbose = 'quiet'; $verbose = 'quiet';
}; };
# Load config file if (!$configuration_path) {
read_config "site.cfg" => my %config; $configuration_path = "site.cfg";
}
my %config;
if ( -f $configuration_path ) {
# Load config file
read_config $configuration_path => %config;
}
else {
print STDOUT "Could not read configuration file: $configuration_path\n";
exit 1;
}
my $tt = get_template_html($config{DBI}); my $tt = get_template_html($config{DBI});