From 5d0a0b65e7eb219eff2eee198b8b7e266b36c016 Mon Sep 17 00:00:00 2001 From: Matias Linares Date: Wed, 19 Jun 2024 18:09:43 -0300 Subject: Use Getopt::Long --- ssg | 60 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/ssg b/ssg index cb125b2..e372d84 100755 --- a/ssg +++ b/ssg @@ -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; -- cgit v1.2.3-70-g09d2