Skip to content

Commit 7669a04

Browse files
committed
Better MAIN
1 parent 174ba78 commit 7669a04

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

tool/rawstr4c/rawstr4c.raku

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,34 @@ use Parser;
1919
use Generator;
2020

2121
sub USAGE() {
22+
usage;
23+
}
24+
25+
sub usage() {
2226
print q:to/END/;
23-
Usage: rawstr4c <FILE.md|DIR> [--debug] [--help]
27+
Usage: rawstr4c [--debug] [--help] <FILE.md|DIR>
2428
2529
Arguments:
2630
FILE.md Process a specific markdown file
2731
DIR Process rawstr4c.md file in the given directory
2832
2933
Options:
3034
--debug Show debug information during processing
35+
Value can be [generator|parser]. Default to generator.
36+
3137
--help Show this help message
3238
3339
Error: Unknown option or invalid arguments provided.
3440
END
35-
exit(1);
3641
}
3742

43+
3844
sub MAIN(
3945
# 一定要声明为必选,强制用户输入,未输入时直接进入 USAGE
40-
Str $input-path,
41-
Bool :$debug = False, #= --debug
42-
Bool :$help #= 命令行指定 --help 的时候强制进入 USAGE
46+
Str $input-path,
47+
# 如果是 Str 类型,则 --debug 缺少命令行参数
48+
# 如果是 Any 类型,则可以直接使用 --debug,值为 True
49+
Any :$debug,
4350
)
4451
{
4552
my $markdown-file;
@@ -61,7 +68,18 @@ sub MAIN(
6168

6269
my $parser = Parser::Parser.new($markdown-file.Str);
6370
$parser.parse;
64-
$parser.debug-print-summary if $debug;
6571

66-
Generator::Generator.new($parser).generate;
72+
my $generator = Generator::Generator.new($parser);
73+
74+
if ($debug.defined) {
75+
given $debug {
76+
when 'parser' {
77+
$parser.debug;
78+
}
79+
default {
80+
$generator.debug;
81+
}
82+
}
83+
}
84+
$generator.generate;
6785
}

0 commit comments

Comments
 (0)