Giter Site home page Giter Site logo

args_parser's People

Contributors

shokai avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

ymrl

args_parser's Issues

validateとfilterのtestを書く

今はexit 1してしまっているのでtestできない
on_validate_error, on_filter_errorブロックを宣言させて、例外を全部キャッチしてそっちに投げるようにする

on_validate_errorとon_filter_errorのデフォルトがexit 1になってるようにすればok

bug: filter and has_param?

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

lib/args_parser/parser.rb

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

validation

入力値チェックしてエラー投げる

必要なargumentを指定する

必要な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

ArgsParser#argv

paramsにもoptionsにもならなかったARGVをArgsParser#argvに保存する

LensBar用JSONを出力

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]
]

こういうのを検索結果毎に出す

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.