新版 arara 破坏了我的自定义规则

新版 arara 破坏了我的自定义规则

免责声明:由于arara4.0 现已在 TeX Live 上线,我预见到了不可避免的事情,并亲自提出了这个问题。希望它能有所帮助!:)

我今天更新了我的 TeX Live 发行版,发现它arara已经更新到期待已久的 4.0 版本:

[paulo@cambridge ~] $ /opt/texbin/tlmgr info arara
package:     arara
...
installed:   Yes
revision:    48183
sizes:       src: 625k, doc: 2793k, run: 5177k, bin: 5k
relocatable: No
cat-version: 4.0
cat-date:    2018-07-10 16:34:23 +0200

这意味着好消息,对吧?但是,当我尝试使用自定义规则运行它时,出现以下错误:

  __ _ _ __ __ _ _ __ __ _ 
 / _` | '__/ _` | '__/ _` |
| (_| | | | (_| | | | (_| |
 \__,_|_|  \__,_|_|  \__,_|

Processing 'doc4.tex' (size: 31 bytes, last modified: 05/27/2018
21:05:57), please wait.

I have spotted an error in rule 'ls' located at '/home/paulo'. I
could not parse the rule, something bad happened. Apparently, the
provided YAML file is invalid. I will do my best to help you in
any way I can. There are more details available on this
exception:

DETAILS ---------------------------------------------------------
Cannot create property=command for
JavaBean=com.github.cereda.arara.model.Rule@29774679
 in
'reader', line 1, column 1:
    !config
    ^
Unable to find
property 'command' on class: com.github.cereda.arara.model.Rule

in 'reader', line 4, column 10:
    command: ls @{details}

      ^


Total: 0.03 seconds

我发誓,自定义规则之前一直有效!我做错了什么?为什么arara我的自定义规则被破坏了?我可以在此期间吃点蛋糕吗?

这是有问题的ls规则,在 4.0 版本之前有效,但现在已被破坏:

!config
identifier: ls
name: LS
command: ls @{details}
arguments:
- identifier: details
  flag: '@{ isTrue(parameters.details, "-l", "") }'

任何帮助都将不胜感激!:)

答案1

免责声明:新手册中有一个迁移指南,其中介绍了如何将自定义规则更新为新的 4.0 格式。这绝对值得一看。谢谢!:)

实际上,这段文字的大部分内容都是从我自己的用户手册中提取出来的!哎呀。:)

事实上,版本 4.0 中的规则与旧版本的 不兼容arara。做出如此重大决定的原因是为了标准化和统一命令条目。因此,我们选择了更通用、更广泛的方法:我们需要使用commands而不是command并提供上下文元素,如下所述。

ls规则并没有做任何重要的事情,它只是运行系统命令ls,列出当前目录的内容。但是,当我们尝试在arara包含引用此规则的指令的文件上运行它时,我们会收到错误,如问题所示。为了修复该规则,我们需要将键作为列表元素移动到上下文commandcommands,如下所示:

!config
identifier: ls
name: LS
commands:
- command: ls @{details}
arguments:
- identifier: details
  flag: '@{ isTrue(parameters.details, "-l", "") }'

此修复足以使规则在新格式下有效。:)

现在,让我们考虑一个包含命令列表的示例,该示例也基于旧格式。ls规则已更新,包括在当前目录中运行两次同名的系统命令:

!config
identifier: ls
name: LS
commands:
- ls @{details}
- ls @{details}
arguments:
- identifier: details
  flag: '@{ isTrue(parameters.details, "-l", "") }'

为了修复规则,我们需要在commands上下文中的每个列表元素前面加上command键,如下所示:

!config
identifier: ls
name: LS
commands:
- command: ls @{details}
- command: ls @{details}
arguments:
- identifier: details
  flag: '@{ isTrue(parameters.details, "-l", "") }'

就是这样。:)

有一个辅助工具可用发布部分我们的项目存储库尝试自动将旧格式的规则转换为新格式。如果您想尝试,请rc.jar从存储库下载文件并将其放在旧规则所在的同一目录中。您也可以提供完整路径。

需要注意的是,尽管该工具可能指示转换成功,但由于 的内部工作方式可能会发生变化,因此无法保证生成的规则完全符合新格式,arara因此您的情况可能会有所不同。一般来说,它应该可以正常工作。

规则转换器是用 Java 编写的,需要虚拟机才能运行。该工具的工作流程简单明了,仅接受一个指向要转换的规则的参数。整个过程无需干预即可完成:

$ java -jar rc.jar ls.yaml
         _                                _
 ___ _ _| |___    ___ ___ ___ _ _ ___ ___| |_ ___ ___
|  _| | | | -_|  |  _| . |   | | | -_|  _|  _| -_|  _|
|_| |___|_|___|  |___|___|_|_|\_/|___|_| |_| |___|_|

version 1.0 (rules < 4.0)

The provided YAML rule looks OK. I will try my best to
convert it to the new version 4.0 format adopted by arara.
The new rule name will be written in the same directory of
the original one and will have a '_v4' suffix to it. Keep in
mind that the base name must match the identifier!

YAY! -------------------------------------------------------
Good news, everybody! The provided YAML rule was updated
successfully to the new version 4.0 format of arara! Of
course, there are no guarantees this new rule will work out
of the box, so fingers crossed! Take a closer look at the
manual and update your rule to use the new enhancements of
arara. Have a great time!

生成的规则与本节中手动转换的规则相同。请注意,在创建文件时,生成的 YAML 文件可能会按字母顺序写入键。这意味着,虽然两个文件在语义上代表相同的规则,但键的位置不同。但是,只要正确定义键,这根本不会造成问题。

一切准备就绪。尽情:)享受arara4.0 吧!

最后说明:由于您正在从旧格式迁移到新格式,请考虑用适当的Command对象替换命令中的纯字符串。有关此功能的更多详细信息,请参阅用户手册。

相关内容