
arara
外部ファイルの存在に基づいて条件付きでコマンドを実行するルールを記述したいと考えました。
私が動作させることができたルールの例を次に示します。
!config
# open rule for arara
# author: AEllett
# requires arara 3.0+
identifier: echo
name: echo
command: /bin/echo "-->@{getBasename(file)}<--"
arguments: []
条件付きでファイルをテストすることもできます
!config
# open rule for arara
# author: AEllett
# requires arara 3.0+
identifier: test
name: testing
commands:
- <arara> /bin/echo @{ isTrue ( isFile ("./dir/file") , "TRUE" , "FALSE") }
arguments: []
実行している内容、つまり「/bin/echo」の部分を変更したいと思います。しかし、次のようなことを試した場合:
!config
# open rule for arara
# author: AEllett
# requires arara 3.0+
identifier: test
name: testing
commands:
- <arara> @{mycommand} @{ isTrue ( isFile ("./dir/file") , "TRUE" , ".") }
arguments:
- identifier: mycommand
flag: <arara> @{ isTrue ( isFile ("./dir/file") , "/bin/echo " , "/bin/ls ") }
これはエラーなしで実行されますが、私が望む動作はしません。
次のようなことも試しました:
!config
# open rule for arara
# author: AEllett
# requires arara 3.0+
identifier: test
name: testing
commands:
- <arara> @{mycommand} @{ isTrue ( isFile ("./dir/file") , "TRUE" , ".") }
arguments:
- identifier: mycommand
flag: <arara> @{ isFile ("./dir/file") == true ? "/bin/echo " : "/bin/ls " }
これによりエラーが発生します
It appears that the 'test' task has a YAML syntax error or an
invalid field. Could you take a look at the 'test.yaml' file
located at '/Users/acellett/projects/ini/arara/rules'. I tried my
best to dump the error message, so here it is:
Problem: mapping values are not allowed here
Error found in line 12, column 60.
... ("./dir/file") ? "/bin/echo " : "/bin/ls " }
^
私のテスト ファイル (名前は「example_01.tex」) は次のようになります。
% arara: test: { files: [example_01.tex] }
私が発行しているコマンドラインから
$ arara -v example_01.tex
ログの結果は次のとおりです。
01 Jan 2014 10:58:59.870 INFO Arara - Welcome to arara!
01 Jan 2014 10:58:59.874 INFO Arara - Processing file 'example_01.tex', please wait.
01 Jan 2014 10:58:59.875 INFO DirectiveExtractor - Reading directives from example_01.tex.
01 Jan 2014 10:58:59.876 TRACE DirectiveExtractor - Directive found in line 1 with test: { files: [example_01.tex] }.
01 Jan 2014 10:58:59.884 INFO DirectiveParser - Parsing directives.
01 Jan 2014 10:58:59.889 INFO TaskDeployer - Deploying tasks into commands.
01 Jan 2014 10:58:59.889 TRACE TaskDeployer - Task 'test' found in '/Users/acellett/projects/ini/arara/rules'.
01 Jan 2014 10:58:59.933 INFO CommandTrigger - Ready to run commands.
01 Jan 2014 10:58:59.934 INFO CommandTrigger - Running 'testing'.
01 Jan 2014 10:58:59.934 TRACE CommandTrigger - Command: TRUE
01 Jan 2014 10:59:00.063 TRACE CommandTrigger - Output logging:
01 Jan 2014 10:59:00.064 TRACE CommandTrigger -
01 Jan 2014 10:59:00.064 INFO CommandTrigger - 'testing' was successfully executed.
01 Jan 2014 10:59:00.064 INFO CommandTrigger - All commands were successfully executed.
01 Jan 2014 10:59:00.065 INFO Arara - Done.
ただし、これをどう解釈したらよいのかよくわかりません。
つまり、基本的に私が知りたいのは、他のファイルの存在に応じて異なる実行を行うルールの書き方です。
ちなみに、私は次のように書くことができます:
!config
# open rule for arara
# author: AEllett
# requires arara 3.0+
identifier: test
name: testing
commands:
- <arara> @{ isTrue ( isFile ("./dir/file") , "/bin/echo " , "/bin/ls ") } @{ isTrue ( isFile ("./dir/file") , "TRUE" , ".") }
arguments: []
しかし、私は引数を介してコマンドを選択できるようにしたいと考えていました。
答え1
どうやら、同調圧力は効果があるようだ。:)
トム、君のことだよ。:P
プラン B、800 票を獲得できるか見てみましょう: 私は Facebook のセキュリティ エンジニアですが、これは私の責任です。 :)
おそらくコードを最適化する方法に焦点を当てるべきですが、急いでいるので、今は直接的なアプローチが思いつきません。:)
発生したエラーは、内部的には、コマンドの先頭で を使用する場合の注意点の 1 つです<arara>
。引用符をいくつか節約できますが、YAML マッピングに起因する問題が発生する可能性があります。
この:
文字は YAML 形式で頻繁に使用されるため、文字列の後半でこの文字が出現するとパーサーが混乱し、エラーが発生します。解決策は、古き良き引用符 (一重引用符または二重引用符) を使用することです。すでに二重引用符がある場合は、一重引用符を使用します。
flag: '@{ isFile ("./dir/file") == true ? "/bin/echo " : "/bin/ls " }'
これで動作するはずです。まあ、ある程度は。:)
flag
引数がディレクティブに提示されている場合にのみ評価され、そうでない場合は引数は空の文字列として解決されます。この評価が行われるようにするには、持っているディレクティブに含める必要がありますmycommand
。指定しない場合は、呼び出される@{mycommand}
メイン行で空になります。command
mycommand
ディレクティブ内での出現に関係なく評価したい場合は、default
の代わりにを使用しますflag
。例を見てみましょう。
- identifier: engine
flag: <arara> @{parameters.engine}
default: pdflatex
どのエンジンを使用するか定義できるルールが欲しいので、引数を用意しますengine
。最初のケース:
% arara: foo
arara
次のようにします:
- 何か出来事があったので
default
、engine
その評価を決意する。 engine
指令には何も発生していません。現状のままにしておきます。
結局のところ、engine
になりますpdflatex
。では、2 番目のケースを見てみましょう。
% arara: foo: { engine: xelatex }
arara
次のように動作します:
- 発生している
default
ので、engine
その評価を解決しますpdflatex
。これは です。 engine
ディレクティブ内にが出現し、評価されflag
てデフォルト値が置き換えられます。
さて、engine
になりますxelatex
。:)
若干の編集を加えて、
!config
identifier: test
name: testing
commands:
- <arara> @{mycommand} @{ isTrue ( isFile ("./dir/file") , "TRUE" , ".") }
arguments:
- identifier: mycommand
default: '@{ isFile ("./dir/file") == true ? "/bin/echo " : "/bin/ls " }'
ルールが機能するようになりました。:)
それが役に立てば幸い!:)