Better help

This commit is contained in:
Aoran Zeng
2025-07-16 23:53:29 +08:00
parent c989f250b0
commit a813429924
2 changed files with 49 additions and 19 deletions

View File

@@ -15,3 +15,13 @@ constant RELEASE_DATE = "2025/07/16";
constant Maintain_URL = "https://github.com/RubyMetric/chsrc/blob/dev/tool/rawstr4c"; constant Maintain_URL = "https://github.com/RubyMetric/chsrc/blob/dev/tool/rawstr4c";
constant Maintain_URL2 = "https://gitee.com/RubyMetric/chsrc/blob/dev/tool/rawstr4c"; constant Maintain_URL2 = "https://gitee.com/RubyMetric/chsrc/blob/dev/tool/rawstr4c";
constant VERSION_CONTENT_FOR_-version = qq:to/EOF/
rawstr4c {VERSION}
Copyright (C) 2025 Aoran Zeng
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by Aoran Zeng.
EOF

View File

@@ -17,38 +17,54 @@
use Parser; use Parser;
use Generator; use Generator;
use Version;
sub USAGE() { sub USAGE() {
usage; print qq:to/END/;
} rawstr4c: Raw String for C (GPLv3+) {Version::VERSION}-{Version::RELEASE_DATE}
sub usage() { Usage: rawstr4c [options] <FILE.md|DIR>
print q:to/END/;
Usage: rawstr4c [--debug] [--help] <FILE.md|DIR>
Arguments: Arguments:
FILE.md Process a specific markdown file FILE.md Process a specific markdown file
DIR Process rawstr4c.md file in the given directory DIR Process rawstr4c.md file in the given directory
Options: Options:
--debug Show debug information during processing -d|--debug Show debug information during processing
Value can be [generator|parser]. Default to generator. Value can be [generator|parser]. Default to generator.
--help Show this help message -v|--version Show version information
-h|--help Show this help message
Error: Unknown option or invalid arguments provided.
END END
} }
sub MAIN( sub MAIN(
# 一定要声明为必选,强制用户输入,未输入时直接进入 USAGE Str $input-path?,
Str $input-path,
# 如果是 Str 类型,则 --debug 缺少命令行参数 # 如果是 Str 类型,则 --debug 缺少命令行参数
# 如果是 Any 类型,则可以直接使用 --debug值为 True # 如果是 Any 类型,则可以直接使用 --debug值为 True
Any :$debug, Any :$debug,
Any :$version,
:$d, :$v, :$h
) )
{ {
if ($version || $v) {
print Version::VERSION_CONTENT_FOR_-version;
exit(0);
}
if ($h) {
USAGE;
exit(0);
}
if (!$input-path) {
USAGE;
exit(0);
}
my $markdown-file; my $markdown-file;
if $input-path.IO.d { if $input-path.IO.d {
@@ -73,13 +89,17 @@ sub MAIN(
if ($debug.defined) { if ($debug.defined) {
given $debug { given $debug {
when 'parser' { when 'parser' {$parser.debug;}
$parser.debug; default {$generator.debug;}
}
default {
$generator.debug;
}
} }
} }
if ($d.defined) {
given $d {
when 'parser' {$parser.debug;}
default {$generator.debug;}
}
}
$generator.generate; $generator.generate;
} }