Skip to content

Commit a813429

Browse files
committed
Better help
1 parent c989f25 commit a813429

File tree

2 files changed

+49
-19
lines changed

2 files changed

+49
-19
lines changed

tool/rawstr4c/lib/Version.rakumod

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,13 @@ constant RELEASE_DATE = "2025/07/16";
1515

1616
constant Maintain_URL = "https://github.com/RubyMetric/chsrc/blob/dev/tool/rawstr4c";
1717
constant Maintain_URL2 = "https://gitee.com/RubyMetric/chsrc/blob/dev/tool/rawstr4c";
18+
19+
constant VERSION_CONTENT_FOR_-version = qq:to/EOF/
20+
rawstr4c {VERSION}
21+
Copyright (C) 2025 Aoran Zeng
22+
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>
23+
This is free software: you are free to change and redistribute it.
24+
There is NO WARRANTY, to the extent permitted by law.
25+
26+
Written by Aoran Zeng.
27+
EOF

tool/rawstr4c/rawstr4c.raku

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,54 @@
1717

1818
use Parser;
1919
use Generator;
20+
use Version;
2021

2122
sub USAGE() {
22-
usage;
23-
}
23+
print qq:to/END/;
24+
rawstr4c: Raw String for C (GPLv3+) {Version::VERSION}-{Version::RELEASE_DATE}
2425
25-
sub usage() {
26-
print q:to/END/;
27-
Usage: rawstr4c [--debug] [--help] <FILE.md|DIR>
26+
Usage: rawstr4c [options] <FILE.md|DIR>
2827
2928
Arguments:
30-
FILE.md Process a specific markdown file
31-
DIR Process rawstr4c.md file in the given directory
29+
FILE.md Process a specific markdown file
30+
DIR Process rawstr4c.md file in the given directory
3231
3332
Options:
34-
--debug Show debug information during processing
35-
Value can be [generator|parser]. Default to generator.
33+
-d|--debug Show debug information during processing
34+
Value can be [generator|parser]. Default to generator.
35+
36+
-v|--version Show version information
3637
37-
--help Show this help message
38+
-h|--help Show this help message
3839
39-
Error: Unknown option or invalid arguments provided.
4040
END
4141
}
4242

4343

4444
sub MAIN(
45-
# 一定要声明为必选,强制用户输入,未输入时直接进入 USAGE
46-
Str $input-path,
45+
Str $input-path?,
4746
# 如果是 Str 类型,则 --debug 缺少命令行参数
4847
# 如果是 Any 类型,则可以直接使用 --debug,值为 True
4948
Any :$debug,
49+
Any :$version,
50+
:$d, :$v, :$h
5051
)
5152
{
53+
if ($version || $v) {
54+
print Version::VERSION_CONTENT_FOR_-version;
55+
exit(0);
56+
}
57+
58+
if ($h) {
59+
USAGE;
60+
exit(0);
61+
}
62+
63+
if (!$input-path) {
64+
USAGE;
65+
exit(0);
66+
}
67+
5268
my $markdown-file;
5369

5470
if $input-path.IO.d {
@@ -73,13 +89,17 @@ sub MAIN(
7389

7490
if ($debug.defined) {
7591
given $debug {
76-
when 'parser' {
77-
$parser.debug;
78-
}
79-
default {
80-
$generator.debug;
81-
}
92+
when 'parser' {$parser.debug;}
93+
default {$generator.debug;}
94+
}
95+
}
96+
97+
if ($d.defined) {
98+
given $d {
99+
when 'parser' {$parser.debug;}
100+
default {$generator.debug;}
82101
}
83102
}
103+
84104
$generator.generate;
85105
}

0 commit comments

Comments
 (0)