shokai / args_parser Goto Github PK
View Code? Open in Web Editor NEWParse/Filter/Validate ARGV from command line with DSL.
Home Page: http://shokai.github.com/args_parser
License: MIT License
Parse/Filter/Validate ARGV from command line with DSL.
Home Page: http://shokai.github.com/args_parser
License: MIT License
今はexit 1してしまっているのでtestできない
on_validate_error, on_filter_errorブロックを宣言させて、例外を全部キャッチしてそっちに投げるようにする
on_validate_errorとon_filter_errorのデフォルトがexit 1になってるようにすればok
args = ArgsParser.parse ARGV do
arg :input, "input data"
filter :input do |v|
JSON.parse v # => convert arg with Hash
end
end
args.has_param? :input # => return false, but it should return true
def has_param?(*param_)
!(param_.flatten.map{|i|
v = self[i]
(v and [String, Fixnum, Float].include? v.class) ? true : false ## here
}.include? false)
end
parser[:help] == parser['help']
arg名を*arrで受け渡すようにする
arg :time, 'time', :default => lambda{ Time.now }
が現状では実行されない。
シリアルポートのデフォルトを
Dir.filelist("/dev").grep(/^tty.usbmodem/)[0]
にしたりするのに有用
入力値チェックしてエラー投げる
newgem -> bundler
数値にする。
--width 1024
とかを、"1024" -> 1024にする
--pi 3.14
は小数にする
parser = ArgsParser.parse ARGV do
arg :help, 'show help', :alias => :h
on :help do |v|
puts help
exit
end
end
みたいな感じで
必要なargにrequired => trueをつける
parser = ArgsParser.parse ARGV do
arg :url, 'URL', :alias => :u, :required => true
arg :output, 'output file', :alias => :o, :default => 'out.html'
arg :verbose, 'verbose mode'
arg :help, 'show help', :alias => :h
validate :url do |v|
v =~ /^https?:\/\/.+$/
end
filter :url do |v|
v.strip
end
end
一、二文字くらいの間違いなら候補を出す
paramsにもoptionsにもならなかったARGVをArgsParser#argvに保存する
equal styleで-30とか-3.14がstringのままになっている
正規表現が悪い
var data = [
['usr', 0],
['bin', 1],
['.DS_Store', 2],
['a2p', 2],
['acid', 2],
['aclocal', 2],
['aclocal-1.10', 2],
['addftinfo', 2],
['afconvert', 2],
['afinfo', 2],
['afmtodit', 2]
]
こういうのを検索結果毎に出す
% app start --user shokai
to
% app start --user=shokai
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.