From a813429924dcceab15bd5b9edddb7123f828ecbb Mon Sep 17 00:00:00 2001 From: Aoran Zeng Date: Wed, 16 Jul 2025 23:53:29 +0800 Subject: [PATCH] Better help --- tool/rawstr4c/lib/Version.rakumod | 10 ++++++ tool/rawstr4c/rawstr4c.raku | 58 +++++++++++++++++++++---------- 2 files changed, 49 insertions(+), 19 deletions(-) diff --git a/tool/rawstr4c/lib/Version.rakumod b/tool/rawstr4c/lib/Version.rakumod index 333a2fd..622e391 100644 --- a/tool/rawstr4c/lib/Version.rakumod +++ b/tool/rawstr4c/lib/Version.rakumod @@ -15,3 +15,13 @@ constant RELEASE_DATE = "2025/07/16"; 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 VERSION_CONTENT_FOR_-version = qq:to/EOF/ + rawstr4c {VERSION} + Copyright (C) 2025 Aoran Zeng + License GPLv3+: GNU GPL version 3 or later + 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 diff --git a/tool/rawstr4c/rawstr4c.raku b/tool/rawstr4c/rawstr4c.raku index f110b5a..86f958f 100644 --- a/tool/rawstr4c/rawstr4c.raku +++ b/tool/rawstr4c/rawstr4c.raku @@ -17,38 +17,54 @@ use Parser; use Generator; +use Version; sub USAGE() { - usage; -} + print qq:to/END/; + rawstr4c: Raw String for C (GPLv3+) {Version::VERSION}-{Version::RELEASE_DATE} -sub usage() { - print q:to/END/; - Usage: rawstr4c [--debug] [--help] + Usage: rawstr4c [options] Arguments: - FILE.md Process a specific markdown file - DIR Process rawstr4c.md file in the given directory + FILE.md Process a specific markdown file + DIR Process rawstr4c.md file in the given directory Options: - --debug Show debug information during processing - Value can be [generator|parser]. Default to generator. + -d|--debug Show debug information during processing + 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 } sub MAIN( - # 一定要声明为必选,强制用户输入,未输入时直接进入 USAGE - Str $input-path, + Str $input-path?, # 如果是 Str 类型,则 --debug 缺少命令行参数 # 如果是 Any 类型,则可以直接使用 --debug,值为 True 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; if $input-path.IO.d { @@ -73,13 +89,17 @@ sub MAIN( if ($debug.defined) { given $debug { - when 'parser' { - $parser.debug; - } - default { - $generator.debug; - } + when 'parser' {$parser.debug;} + default {$generator.debug;} } } + + if ($d.defined) { + given $d { + when 'parser' {$parser.debug;} + default {$generator.debug;} + } + } + $generator.generate; }