Add USAGE

This commit is contained in:
Aoran Zeng 2025-07-16 03:29:51 +08:00
parent 902a40bed7
commit 04b15fec17
No known key found for this signature in database
GPG Key ID: 8F8BA8488E10ED98

View File

@ -15,20 +15,12 @@
# #
# --------------------------------------------------------------- # ---------------------------------------------------------------
use lib 'lib';
use Parser; use Parser;
use Generator; use Generator;
sub MAIN( sub USAGE() {
# 必须声明为可选,否则一直报奇怪的错
Str $input-path?,
Bool :$debug = False, #= --debug
Bool :$help #= --help
)
{
if $help || !$input-path {
print q:to/END/; print q:to/END/;
Usage: rawstr4c <FILE.md|DIR> [--debug] Usage: rawstr4c <FILE.md|DIR> [--debug] [--help]
Arguments: Arguments:
FILE.md Process a specific markdown file FILE.md Process a specific markdown file
@ -37,23 +29,34 @@ sub MAIN(
Options: Options:
--debug Show debug information during processing --debug Show debug information during processing
--help Show this help message --help Show this help message
END
# exit($help ?? 0 !! 1);
exit(0);
}
Error: Unknown option or invalid arguments provided.
END
exit(1);
}
sub MAIN(
# 一定要声明为必选,强制用户输入,未输入时直接进入 USAGE
Str $input-path,
Bool :$debug = False, #= --debug
Bool :$help #= --help USAGE
)
{
my $markdown-file; my $markdown-file;
if $input-path.IO.d { if $input-path.IO.d {
$markdown-file = $input-path.IO.add("rawstr4c.md"); $markdown-file = $input-path.IO.add("rawstr4c.md");
unless $markdown-file.e { unless $markdown-file.e {
die "Error: No 'rawstr4c.md' file found in directory '$input-path'"; # 也可以 warn
note "Error: No 'rawstr4c.md' file found in directory '$input-path'";
exit(1);
} }
} }
elsif $input-path.IO.f { elsif $input-path.IO.f {
$markdown-file = $input-path.IO; $markdown-file = $input-path.IO;
} else { } else {
die "Error: '$input-path' is neither a file nor a directory"; note "Error: '$input-path' is neither a file nor a directory";
exit(1);
} }
my $parser = Parser::Parser.new($markdown-file.Str); my $parser = Parser::Parser.new($markdown-file.Str);