diff options
-rwxr-xr-x | ssg | 60 |
1 files changed, 30 insertions, 30 deletions
@@ -2,16 +2,17 @@ use v5.38; use strict; use warnings; +use experimental 'signatures'; use local::lib; use File::Path qw(make_path remove_tree); use Path::Class; -use Getopt::Std; +use Getopt::Long; # Root in directory. -my $indir; -my $outdir; +our $indir; +our $outdir; my $VERSION = "v0.1"; my @exlude_files = ( @@ -203,33 +204,32 @@ sub run_on { } } -my %opts = ( - 'v' => 0, - 'h' => 0, - 'o' => "site.static/", - 's' => 1, -); -getopts('svho:', \%opts); -$indir = shift @ARGV; - -if($opts{h}) { - help; - exit 0; -} elsif($opts{v}) { - version; - exit 0; -} +sub main { + my $help; + my $version; + my $output_path = 'site.static/'; + my $sidebar = 1; + GetOptions(help => \$help, + version => \$version, + "output-path=s", \$output_path, + "sidebar" => \$sidebar) or die "Error in command line arguments\n"; + $indir = shift @ARGV; + + if($help) { + help; + exit 0; + } elsif ($version) { + version(); + exit 0; + } -if(-d $opts{o}) { - print STDERR "removing $opts{o}\n"; - remove_tree($opts{o}); -} + if (-d $output_path) { + print STDERR "Removing $output_path\n"; + remove_tree($output_path); + } -if($opts{s}) { - $with_sidebar = $opts{s}; + $outdir = $output_path; + mkdir $output_path; + run_on $indir; } - -mkdir $opts{o}; -$outdir = $opts{o}; - -run_on $indir; +main; |