mirror of
https://github.com/RubyMetric/chsrc
synced 2025-07-21 23:59:33 +08:00
Move files handler back to main
This commit is contained in:
parent
66e5c1f7e0
commit
902a40bed7
@ -161,22 +161,9 @@ class Parser {
|
||||
#| 所有sections的扁平数组,已经是深度遍历的了
|
||||
has Section @!sections;
|
||||
|
||||
#| $path 可能是文件,也可能是目录
|
||||
method new($path) {
|
||||
my $markdown-file;
|
||||
|
||||
if $path.IO.d {
|
||||
$markdown-file = $path.IO.add("rawstr4c.md");
|
||||
unless $markdown-file.e {
|
||||
die "Error: No 'rawstr4c.md' file found in directory '$path'\n";
|
||||
}
|
||||
}
|
||||
elsif $path.IO.f {
|
||||
$markdown-file = $path.IO;
|
||||
} else {
|
||||
die "Error: '$path' is neither a file nor a directory\n";
|
||||
}
|
||||
self.bless(:input-file($markdown-file.Str));
|
||||
#| $markdown-file 必须是一个存在的 markdown 文件路径
|
||||
method new($markdown-file) {
|
||||
self.bless(:input-file($markdown-file));
|
||||
}
|
||||
|
||||
# 获取根section(level 0)
|
||||
|
@ -7,43 +7,58 @@
|
||||
# File Authors : Aoran Zeng <ccmywish@qq.com>
|
||||
# Contributors : Nul None <nul@none.org>
|
||||
# Created On : <2025-07-12>
|
||||
# Last Modified : <2025-07-14>
|
||||
# Last Modified : <2025-07-16>
|
||||
#
|
||||
# rawstr4c:
|
||||
#
|
||||
# Raw strings for C programming language
|
||||
#
|
||||
# Usage:
|
||||
# rawstr4c <FILE.md> # 指定具体某文件名
|
||||
# rawstr4c <DIR> # 使用某一目录寻找 rawstr4c.md 文件
|
||||
#
|
||||
# 要注意的是,该程序一次性只能处理唯一一个文件
|
||||
# ---------------------------------------------------------------
|
||||
|
||||
use lib 'lib';
|
||||
use Parser;
|
||||
use Generator;
|
||||
|
||||
sub MAIN(
|
||||
Str $input-path,
|
||||
Bool :$debug = False #= --debug
|
||||
) {
|
||||
# 必须声明为可选,否则一直报奇怪的错
|
||||
Str $input-path?,
|
||||
Bool :$debug = False, #= --debug
|
||||
Bool :$help #= --help
|
||||
)
|
||||
{
|
||||
if $help || !$input-path {
|
||||
print q:to/END/;
|
||||
Usage: rawstr4c <FILE.md|DIR> [--debug]
|
||||
|
||||
Arguments:
|
||||
FILE.md Process a specific markdown file
|
||||
DIR Process rawstr4c.md file in the given directory
|
||||
|
||||
Options:
|
||||
--debug Show debug information during processing
|
||||
--help Show this help message
|
||||
END
|
||||
# exit($help ?? 0 !! 1);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
my $markdown-file;
|
||||
|
||||
if $input-path.IO.d {
|
||||
$markdown-file = $input-path.IO.add("rawstr4c.md");
|
||||
unless $markdown-file.e {
|
||||
die "Error: No 'rawstr4c.md' file found in directory '$input-path'\n";
|
||||
die "Error: No 'rawstr4c.md' file found in directory '$input-path'";
|
||||
}
|
||||
}
|
||||
elsif $input-path.IO.f {
|
||||
$markdown-file = $input-path.IO;
|
||||
} else {
|
||||
die "Error: '$input-path' is neither a file nor a directory\n";
|
||||
die "Error: '$input-path' is neither a file nor a directory";
|
||||
}
|
||||
|
||||
my $parser = Parser::Parser.new($markdown-file);
|
||||
my $parser = Parser::Parser.new($markdown-file.Str);
|
||||
$parser.parse;
|
||||
$parser.debug if $debug;
|
||||
$parser.debug-print-summary if $debug;
|
||||
|
||||
Generator::Generator.new($parser).generate;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user