Change print usage dynamic.

This commit is contained in:
2026-04-01 12:50:09 +02:00
parent 20bb5319c9
commit bea46f9017

42
ccc
View File

@@ -33,19 +33,24 @@ use Math::Base36 ':all';
my $VERSION = '0.1'; my $VERSION = '0.1';
my $PROG_NAME = 'ccc'; my $PROG_NAME = 'ccc';
my $arg = shift or usage(); 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') { } elsif($arg eq '-v' || $arg eq '--version') {
print "$PROG_NAME v$VERSION\n"; print "$PROG_NAME v$VERSION\n";
exit 0 exit;
} }
my ($start_section, $end_section); my ($start_section, $end_section);
@@ -92,17 +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 " -v, --version Show version information\n";
print STDERR "Examples:\n"; sub print_help {
print STDERR " ccc -l # Build cache\n"; print_usage();
print STDERR " ccc 270 # Single section\n"; print "\nOptions:\n";
print STDERR " ccc 1691-1698 # Range of sections\n"; print " -l, --load-cache Build the section cache from Vatican server\n";
exit 1; 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 {