조건부로 명령을 실행하기 위해 arara 규칙을 작성하는 방법

조건부로 명령을 실행하기 위해 arara 규칙을 작성하는 방법

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의 보안 엔지니어이고 이것은 내 잘못입니다. :)

어떻게 코드를 최적화할 것인지에 집중해야 할 것 같은데, 급해서 당장은 직접적인 접근 방법이 생각나지 않습니다.:)

제기된 오류는 명령 시작 부분에 사용할 때 주의해야 할 사항 중 하나입니다 .<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다음을 수행합니다.

  1. 발생이 있으므로 평가에 default전념하십시오 .engine
  2. 지시문에 항목이 없으므로 engine그대로 유지하십시오.

결국에는 engine가 될 것입니다 pdflatex. 이제 두 번째 사례를 살펴보겠습니다.

% arara: foo: { engine: xelatex }

arara이제 다음과 같이 동작합니다:

  1. 발생이 있으므로 평가를 default해결하십시오 .enginepdflatex
  2. 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 " }'

이제 귀하의 규칙이 작동합니다.:)

도움이 되길 바랍니다!:)

관련 정보