venus-acm-cpp-tool v0.0.1
前言
这个命令行工具是为热爱 acm 的同学定制的,它只为解决一个问题:在本地直接引用自己写好的数据结构、算法,而不必丑陋的复制粘贴,在提交代码的时候,通过执行此命令行工具,将所有的依赖都写入到一个文件中。 使用本工具需要一个条件,就是需要在工程中定义一个 CMakeLists.txt,你可以在 demo 中查看,强烈建议使用 CLion 构建工程,事实上,本工具就是基于本人 在 CLion 中的使用设计的:
- 在 CLion 的 
File -> Settings -> Tools -> Terminal的Shell Path中填上'<your git installer path>/bin/sh.exe' --login -i,它可以让在 Clion 下方的 Terminal 中直接使用 shell (此命令行工具需要在 shell 环境下执行) - 将你的本地类库文件夹中右键(在 CLion 中操作),
Mark directory as=>Library Files/Project Sources and Headers - 在你新建的工程中 
Edit Configurations -> Templates -> Application的Working directory中填入当前工程的根路径 - 在工程中新建 
CMakeLists.txt,填入 demo 中的内容,强烈建议你构造形如 demo 中的结构 - 每次新建文件时,通过 
create/new子命令创建,可以将当前文件在CMakeLists.txt中注册一个add_executable字段,然后就可以直接 CLion 中调试、运行新创建的文件了 - 在需要提交的时候,通过 
generate子命令生成拥有所有依赖的外部文件的单一源文件(你可以通过一些压缩选项来压缩代码的大小) 
安装
npm install -g venus-acm使用
执行 venus --help 可以看到命令的用法:
  Usage: main [options] [command]
  Options:
    -V, --version                    output the version number
    --log-level <level>              index logger's level.
    --log-option <option>            index logger' option. (date,colorful)
    --cmake-lists <cmakeLists-name>  index cmakeLists name. (default is CMakeLists.txt)
    --encoding <encoding>            index encoding of all files.
    --config-path <config-path>      index config path, related with the project root directory where the CMakeLists.txt exists.
    --no-config                      don't use config.
    -h, --help                       output usage information
  Commands:
    generate|g [options] <source> [target]
    create|new [options] [source...]
    register|r [options] <source...>
    remove|d [options] <source...>
    clean|c [options] [directory]
    *其中 Commands 下方的是子命令,见下文;同时,需要注意的是,你可以通过在工程根目录下指定一个 venus.config.yml 来定义命令选项的默认值,见 demo
命令选项
--version: 显示命令的版本--log-level <level>: 指定输出的日志级别,可选值有debug,verbose,info,warn,error,默认值为info--log-option <option>: 指定输出的日志选项,可选值有date,colorful--cmake-lists <cmakeLists-name>: 指定CMakeLists.txt名称,默认值为CMakeLists.txt,--encoding <encoding>: 指定工程下文件的默认编码格式--config-path <config-path>: 指定配置文件所在的路径(相对于工程的根目录),默认值为venus.config.yml,--no-config: 不使用配置文件--help: 显示命令的帮助
子命令 generate
执行 venus generate --help 可以看到 generate 的用法:
  Usage: generate|g [options] <source> [target]
  Options:
    -d, --output-directory <output-directory>  specify output directory, related with the project root directory where the CMakeLists.txt exists.
    --rc, --remove-comments                    remove comments.
    --rs, --remove-spaces                      remove spaces.
    --rf, --remove-freopen                     remove freopen statements.
    --ra, --remove-assert                      remove assert statements.
    -u, --uglify                               shortcut of --rc --rs.
    -c, --copy                                 copy to system clipboard, this option will invalidate the output options: '-f', -d' and '-p'.
    -f, --force                                if the target file is exists, overwrite it without confirmation.
    -h, --help                                 output usage information其中 source 为你需要打包的文件的路径,target 为打包后的文件名,若不指定则为生成一个默认的名称
命令选项
--output-directory <output-directory>: 指定输出目录,路径相对于工程的根目录--remove-comments: 删除源码中所有的注释(请放心使用,它不会删除正常的输出中的形如printf("/* */")的代码)--remove-spaces: 删除源码中所有多余的空格(请放心使用,它不会删除正常的输出中的形如printf(" ")的代码)--remove-freopen: 删除源码中的 freopen 代码--remove-assert: 删除源码中的 assert 代码--uglify: 相当于同时指定--remove-comments和--remove-spaces--copy: 不将打包后的内容输出的文件,而是输出到系统剪切板中,若指定该选项,则--outputDirectory和target都将失效--force: 当输出文件已存在时,会在命令行中发起一个确认删除的交互,若指定该选项,则将无需确认就覆盖掉文件--help: 显示命令的帮助
子命令 create/new
venus new 和 venus create 是完全等价的命令,执行 venus create --help 可以看到 create/new 的用法:
  Usage: create|new [options] [source...]
  Options:
    -t, --template-path [template-path]                  specify template path, related with the project root directory where the CMakeLists.txt exists.
    -T, --no-template                                    don't use template.
    -d, --data-path [template-path]                      specify data path, related with sourcePath
    -D, --no-data                                        don't use data.
    -c, --contest <contest-phase>                        specify contest which defined in config.
    -r, --round <contest-round>                          specify contest round, valid only when the option '-c' specified..
    -p, --problem-number <contest-round-problem-number>  specify contest round's problem number, valid only when the option '-c' specified..
    -h, --help                                           output usage information这个命令用于创建新的程序文件,其中,source 是待创建的文件列表。
命令选项
--template-path [template-path]: 指定模板的路径--no-template: 不使用模板--data-path: 数据文件的路径--no-data: 不生成data.in,(之所以这么古怪,是因为本工具使用了commander.js,目前版本的commander.js有一个 bug,若同时声明了--data和--no-data选项,则后声明的将覆盖掉之前声明的,目前commander.js将这 bug 的修复放入了下一个大版本更新计划中,此后本人将会做更新;由于本人擅自认为使用freopen是更常用的场景(且 generate 时会自动移除掉),因此目前只提供--no-data选项--contest <contest-phase: 解释比较复杂,试试在 demo 中执行venus create --contest=codeforces --round=512 --problem-number=4--round <contest-round>: 指定比赛的场次,和--contest选项配套使用,不可独立出现,且在指定了--contest选项时,必须同时也指定此选项--problem-number <contest-round-problem-number>: 指定本场比赛的题目个数,和--contest选项配套使用,不可独立出现,且在指定了--contest选项时,必须同时也指定此选项--help: 显示命令的帮助
子命令 register
执行 venus register --help 可以看到 register 的用法:
  Usage: register|r [options] <source...>
  Options:
    -r, --recursive  register all files in the directory recursively.
    -h, --help       output usage information这个命令用于将一个程序文件 “注册” 进 CMakeLists.txt 中,即在 CMakeLists.txt 中注册一个 add_executable 字段,使得你可以在如 CLion 中调试运行该程序
命令选项
--recursive: 当 source 为文件夹时,若指定该选项,则将扫描该文件夹下的整棵目录树--help: 显示命令的帮助
子命令 remove
执行 venus remove --help 可以看到 remove 的用法:
  Usage: remove|d [options] <source...>
  Options:
    -r, --recursive  remove all files in the directory recursively.
    -f, --force      remove file without confirmation.
    -h, --help       output usage information这个命令用于将一个程序文件移除,同时也清理 CMakeLists.txt 中的相应 add_executable 字段
命令选项
--recursive: 当 source 为文件夹时,若指定该选项,则将扫描该文件夹下的整棵目录树--force: 删除时,无需用户确认--help: 显示命令的帮助
子命令 clean
执行 venus clean --help 可以看到 clean 的用法:
  Usage: clean|c [options] [directory]
  Options:
    -r, --recursive          remove all files in the directory recursively.
    -f, --force              clean file without confirmation.
    -p, --pattern <pattern>  clean file which should matched the pattern. (default: )
    -h, --help               output usage information这个命令用于清理指定文件夹下的无用文件,并清理 CMakeLists.txt 中无用的 add_executable 条目,当未指定路径时,则当前执行命令的路径作为参数
命令选项
--recursive: 递归清理--force: 删除时,无需用户确认--pattern: 指定需要删除的模式(minimatch 匹配的模式),可以多次指定该选项,也可以在venus.config.yml中配置默认的模式--help: 显示命令的帮助
7 years ago