#command-runner #runner #command-arguments #task #customizable #clippy #coverage

app rxe

使用Rust 🦀轻松可定制的命令运行器

1 个不稳定版本

0.1.0 2022年5月25日

18#clippy

MIT 许可证

56KB
1K SLoC

Header image (light theme) Header image (dark theme)

Clippy check Test with coverage codecov

使用Rust 🦀轻松可定制的命令运行器

📦 使用方法

使用以下命令安装

cargo install rxe

或从源代码构建。

git clone https://github.com/loxygenK/rxe
cargo run

🏃‍♀️ 运行脚本

在同一当前目录下准备 rxe.yaml(或 rxe.yml.rxe.yml.rxe.yaml),然后运行

rxe (your command) (and some arguments)

有关更详细的说明,请参阅 示例创建配置

🔎 指定配置

通过设置环境变量 RXE_CONFIG,您可以使用任何名称来指定配置。

RXE_CONFIG=rxe.config.yml rxe
# Now rxe will use rxe.config.yml as the configuration file

📝 示例

创建以下配置

cmd:
  test:
    args:
      type:
        choice: [core, frontend, types]
      snapshot:
        flag:

    run:
      echo "Executing the test for {type} {snapshot|true=(with snapshot)}"

然后您可以像这样运行命令

$ rxe test --type core --snapshot
#...

如果参数与配置不符,则会显示错误。

$ rxe test --type backend  # There is no `backend` in the choice for `type` argument.
Could not parse the command argument: The value of the argument is invalid: The value was not appropriate: 'backend' is not available as the choice.
Please check the argument you passed to `rxe`, or configuration file.
Exiting abnormally due to the above error.

🛠 创建配置

TL;DR:

  • 参数有四种类型:文本数字标志选择
  • 参数的值填充到 占位符 中,占位符是 {} 包围的文本。
    • 可以使用 \ 进行转义。请参阅 占位符 部分了解转义的行为。

🔭 概述

配置文件使用 YAML 编写。配置看起来像这样

cmd:
  {Command name here}:
    args:
      {argument name here}:
        {argument type here}:
          {some additional argument configuration if neccesary}
      # other arguments can continue.

    run: |
      echo "commands. Can include the placeholder."
      
  # other commands can continue.

🔖 参数

    args:
      {name}:
        {type}:
          {some additional configuration}

可以在 args 中定义命令的参数。参数有两个信息:名称类型[^1]。请参阅 类型 了解可用的类型。

📝 运行脚本

    run: |
      echo "commands"

脚本在 run 中定义。脚本可以包含用于嵌入参数值的 占位符

占位符

run: |
  # The result assumes that the rxe is executed by following command line:
  #   rxe {command name} --arg "Some text" --flag

  # This is the placeholder
  echo "{arg}"     # => Some text
  
  # The placeholder can be omitted using "\"
  echo "\{arg}"    # => \{arg}
  
  # The placeholder is not omitted if there was more than two "\"
  echo "\\{arg}"   # => \Some text
  echo "\\\{arg}"  # => \\Some text
  
  # Some argument type like Flag type require more information, called Property.
  # Properties can be specified using "|".
  echo "{flag|true=enabled|false=disabled}"
                   # => enabled

占位符是 {} 包围的文本。它包含信息:名称属性。占位符由参数的值(称为 填充)替换。

占位符语法如下

{name of the argument|property name=config value|property name=config value|...}

例如,对于占位符 {flag|true=enabled|false=disabled}...

  • 填充参数 "flag" 的值。

    以下属性将用于填充

    • trueenabled
    • false: disabled

🧩 类型

目前有四种类型。

文本类型

cmd:
  exec:
    args:
      name:
        text:
    run: |
      echo "Filled: >{name}<"
$ rxe exec --name "Some text"
Filled: >some text<

任何文本。如果没有指定值,rxe 在执行 run 中指定的脚本之前会失败。

数字类型

cmd:
  exec:
    args:
      name:
        number:
    run: |
      echo "Filled: >{name}<"
$ rxe exec --name "12345"
Filled: >12345<

$ rxe exec --name "abcde"
Could not parse the command argument: The value of the argument is invalid: The value was not appropriate: 'abcde' could not be parsed as the number (esp. f64)
Please check the argument you passed to `rxe`, or configuration file.
Exiting abnormally due to the above error.

任何数字。如果使用非数字值(如 abcde0x12345)或未指定值,rxe 会失败。

标志类型

cmd:
  exec:
    args:
      name:
        flag:
    run: |
      echo "Filled 1: >{name|true=specified|false=not specified}<"
      echo "Filled 2: >{name|true=specified}<"
$ rxe exec --name
Filled 1: >specified<
Filled 2: >specified<

$ rxe exec
Filled 1: >not specified<
Filled 2: ><

$ rxe exec --name "bruh"
Could not parse the command argument: The value of the argument is invalid: The value of the argument should not be given.
Please check the argument you passed to `rxe`, or configuration file.
Exiting abnormally due to the above error.

参数变为标志。参数可以省略,不取值。如果向标志类型参数传递了任何值,rxe 会失败。

属性
name value 可选?
true 当使用参数时应该填充的文本。
false 当未使用参数时应填充的文本。
  • truefalse 可以同时指定,但不能同时省略。

选择类型

cmd:
  exec:
    args:
      name:
        choice:
          - rust
          - ruby
          - python
    run: |
      echo "Filled: >{name}<"
$ rxe exec --name "rust"
Filled: rust

$ rxe exec --name "p"
Filled: python

$ rxe exec --name "ru"
Could not parse the command argument: The value of the argument is invalid: The value was not appropriate: 'ru' is too ambiguous. Type the choice longer
Please check the argument you passed to `rxe`, or configuration file.

[^1]: Constraint 代码中的。

依赖项

~4.5–6.5MB
~115K SLoC