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
variables
のhello.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で簡単に書けるので使いどころを間違えなければとても良いかも。