LoginSignup
12
12

More than 5 years have passed since last update.

YAMLベースのタスクランナーroboを試してみたメモ

Last updated at Posted at 2015-04-29

Simple YAML-based task runner written in Go. なroboを試して見たメモ。README.mdに記述してあるものをそのまま試してみただけ。

Terminal
$ go get github.com/tj/robo

go getでインストールできる。各OS向けのバイナリも用意されているのでgoコマンドがなくてもすぐにインストールできる。

とりあえずroboコマンドを実行してみる。

Terminal
$ robo

  error loading configuration: open robo.yml: no such file or directory

robo.ymlないです。あっ、はい。

とりあえず--helpつけて実行してみる。

Terminal
$ robo --help

  Usage:
    robo [--config file]
    robo <task> [<arg>...] [--config file]
    robo help [<task>] [--config file]
    robo variables [--config file]
    robo -h | --help
    robo --version

  Options:
    -c, --config file   config file to load [default: robo.yml]
    -h, --help          output help information
    -v, --version       output version

  Examples:

    output tasks
    $ robo

    output task help
    $ robo help mytask

とりあえずrobo.ymlを書いてみる。

robo.yml
hello:
  summary: print "hello"
  command: echo 'hello'

テキトーにコマンドを実行してみる。

Terminal
$ robo

  hello – print "hello"

helloのsummaryが出力された。helloサブコマンドを実行してみる。

Terminal
$ robo hello
hello

commandが実行されてhelloが出力された。

helloworldサブコマンドを追加してみる。

robo.yml
hello:
  summary: print "hello"
  command: echo 'hello'

helloworld:
  summary: print "hello world"
  command: |
    echo 'hello'
    echo 'world'

summaryが増えてる。

Terminal
$ robo

  hello – print "hello"
  helloworld – print "hello world"

helloworldサブコマンドを実行してみる。

Terminal
$ robo helloworld
hello
world

2行でhello worldが出力された。

スクリプトのファイルが指定できるみたいなので指定してみる。

robo.yml
test:
  script: ./test.sh
test.sh
#!/bin/bash

echo 'test'
Terminal
$ robo test
test

スクリプトが実行されてtestが出力された。

usageを指定すると引数が渡せるっぽい。

robo.yml
echo:
  command: echo
  usage: "[string]"
Terminal
$ robo echo

$ robo echo 123
123

おー。

examplesを指定すると例を表示できるっぽい。

robo.yml
echo:
  summary: print arguments
  command: echo
  usage: "[string]"
  examples:
    - description: print "hello"
      command: echo hello
    - description: print "world"
      command: echo world
Terminal
$ robo help echo

  Usage:

    echo [string]

  Description:

    print arguments

  Examples:

    print "hello"
    $ echo hello

    print "world"
    $ echo world

表示された。例示には良いかも。

variablesを指定して{{ }}を記述すると変数を扱えるみたいだ。

robo.yml
hello:
  summary: print hello
  command: echo {{.hello.string}}

variables:
  hello:
    string: hello
Terminal
$ robo hello
hello

variableshello.stringが出力された。

templatesを指定するとhelpの出力を変更できるっぽい。

robo.yml
task1:
  summary: task1
  command: echo task1
task2:
  summary: task2
  command: echo task2
task3:
  summary: task3
  command: echo task3

templates:
  list: |
    {{range .Tasks}}
      name: {{cyan .Name}}
      summary: {{.Summary}}
      usage: {{.Usage}}
    {{end}}
Terminal
$ robo help

  name: task1
  summary: task1
  usage:

  name: task2
  summary: task2
  usage:

  name: task3
  summary: task3
  usage:


YAMLで簡単に書けるので使いどころを間違えなければとても良いかも。

12
12
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
12