Compare commits

...

2 Commits

Author SHA1 Message Date
bea46f9017 Change print usage dynamic. 2026-04-01 12:50:09 +02:00
20bb5319c9 Add version flag. 2026-04-01 12:40:29 +02:00

45
ccc
View File

@@ -31,19 +31,28 @@ use File::HomeDir;
use File::Path qw(make_path); use File::Path qw(make_path);
use Math::Base36 ':all'; use Math::Base36 ':all';
my $arg = shift or usage(); my $VERSION = '0.1';
my $PROG_NAME = 'ccc';
my $arg = shift;
if($arg eq '--help' || $arg eq '-h') { unless(defined($arg)) {
usage(); print STDERR "No arguments given.\n\n";
print_usage();
exit 1;
} elsif($arg eq '--help' || $arg eq '-h') {
print_help();
exit;
} elsif($arg eq '-l' || $arg eq '--load-cache') { } elsif($arg eq '-l' || $arg eq '--load-cache') {
my $cache_dir = get_xdg_cache_dir(); my $cache_dir = get_xdg_cache_dir();
make_path($cache_dir) unless -d $cache_dir; make_path($cache_dir) unless -d $cache_dir;
my $cache_file = File::Spec->catfile($cache_dir, 'section_map.json'); my $cache_file = File::Spec->catfile($cache_dir, 'section_map.json');
build_section_map($cache_file); build_section_map($cache_file);
exit 0; exit;
} elsif($arg eq '-v' || $arg eq '--version') {
print "$PROG_NAME v$VERSION\n";
exit;
} }
# Parse argument - can be single number or range (e.g., "1691-1698")
my ($start_section, $end_section); my ($start_section, $end_section);
if($arg =~ /^(\d+)-(\d+)$/) { if($arg =~ /^(\d+)-(\d+)$/) {
$start_section = $1; $start_section = $1;
@@ -88,16 +97,22 @@ unless($found_any) {
exit 1; exit 1;
} }
sub usage { sub print_usage {
print STDERR "Usage: ccc [OPTIONS] [section_number|range]\n"; print "Usage:\n";
print STDERR "Options:\n"; print " ccc <section|range>\n";
print STDERR " -l, --load-cache Build the section cache from Vatican server\n"; print " ccc [OPTION]\n";
print STDERR " -h, --help Show this help message\n"; }
print STDERR "Examples:\n";
print STDERR " ccc -l # Build cache\n"; sub print_help {
print STDERR " ccc 270 # Single section\n"; print_usage();
print STDERR " ccc 1691-1698 # Range of sections\n"; print "\nOptions:\n";
exit 1; print " -l, --load-cache Build the section cache from Vatican server\n";
print " -h, --help Show this help message\n";
print " -v, --version Show version information\n";
print "\nExamples:\n";
print " ccc -l # Build cache\n";
print " ccc 270 # Single section\n";
print " ccc 1691-1698 # Range of sections\n";
} }
sub load_cache { sub load_cache {