Julliaとか聞いたこともない珍しい言語もサポート
docopt/docopt.rb · GitHub
と、Rubyも対応はしているのですが
docopt has been confirmed to work with 1.8.7p370 and 1.9.3p194. If you have noticed it working (or not working) with an earlier version, please raise an issue and we will investigate support.
と、釣れない事が書いて有ります。
バージョン落とせばいけますけど。
require File.expand_path("../../lib/docopt.rb", __FILE__) doc = <<DOCOPT Usage: #{__FILE__} remote [-v | --verbose] #{__FILE__} remote add [-t <branch>] [-m <master>] [-f] [--tags|--no-tags] [--mirror] <name> <url> #{__FILE__} remote rename <old> <new> #{__FILE__} remote rm <name> #{__FILE__} remote set-head <name> (-a | -d | <branch>) #{__FILE__} remote set-branches <name> [--add] <branch>... #{__FILE__} remote set-url [--push] <name> <newurl> [<oldurl>] #{__FILE__} remote set-url --add [--push] <name> <newurl> #{__FILE__} remote set-url --delete [--push] <name> <url> #{__FILE__} remote [-v | --verbose] show [-n] <name> #{__FILE__} remote prune [-n | --dry-run] <name> #{__FILE__} remote [-v | --verbose] update [-p | --prune] [(<group> | <remote>)...] Options: -v, --verbose -t <branch> -m <master> -f --tags --no-tags --mittor -a -d -n, --dry-run -p, --prune --add --delete --push --mirror DOCOPT begin require "pp" pp Docopt::docopt(doc) rescue Docopt::Exit => e puts e.message end
というスクリプトの場合
$ ruby git_example.rb
と呼び出せばよくある簡易ヘルプな状況
$ ruby git_example.rb Usage: git_example.rb remote [-v | --verbose] git_example.rb remote add [-t <branch>] [-m <master>] [-f] [--tags|--no-tags] [--mirror] <name> <url> git_example.rb remote rename <old> <new> git_example.rb remote rm <name> git_example.rb remote set-head <name> (-a | -d | <branch>) git_example.rb remote set-branches <name> [--add] <branch>... git_example.rb remote set-url [--push] <name> <newurl> [<oldurl>] git_example.rb remote set-url --add [--push] <name> <newurl> git_example.rb remote set-url --delete [--push] <name> <url> git_example.rb remote [-v | --verbose] show [-n] <name> git_example.rb remote prune [-n | --dry-run] <name> git_example.rb remote [-v | --verbose] update [-p | --prune] [(<group> | <remote>)...]
一方、
$ ruby git_example.rb remote rm "hoge"
とコマンド調に呼び出した場合
$ ruby git_example.rb remote rm "hoge" {"remote"=>true, "--verbose"=>false, "add"=>false, "-t"=>nil, "-m"=>nil, "-f"=>false, "--tags"=>false, "--no-tags"=>false, "--mirror"=>false, "<name>"=>"hoge", "<url>"=>nil, "rename"=>false, "<old>"=>nil, "<new>"=>nil, "rm"=>true, "set-head"=>false, "-a"=>false, "-d"=>false, "<branch>"=>[], "set-branches"=>false, "--add"=>false, "set-url"=>false, "--push"=>false, "<newurl>"=>nil, "<oldurl>"=>nil, "--delete"=>false, "show"=>false, "--dry-run"=>false, "prune"=>false, "update"=>false, "--prune"=>false, "<group>"=>[], "<remote>"=>[], "--mittor"=>false}
てな感じで、ハッシュを返してくれます。
便利すぎだろこれ(驚愕