Class: TraceLocation::CLI
- Inherits:
-
Object
- Object
- TraceLocation::CLI
- Defined in:
- lib/trace_location/cli.rb
Instance Attribute Summary collapse
-
#argv ⇒ Object
readonly
Returns the value of attribute argv.
Instance Method Summary collapse
-
#initialize(argv) ⇒ CLI
constructor
A new instance of CLI.
- #run ⇒ Object
Constructor Details
#initialize(argv) ⇒ CLI
Returns a new instance of CLI.
7 8 9 |
# File 'lib/trace_location/cli.rb', line 7 def initialize(argv) @argv = argv end |
Instance Attribute Details
#argv ⇒ Object (readonly)
Returns the value of attribute argv.
5 6 7 |
# File 'lib/trace_location/cli.rb', line 5 def argv @argv end |
Instance Method Details
#run ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/trace_location/cli.rb', line 11 def run opt = OptionParser.new opt.on('-f FORMAT', '--format=FORMAT', 'Report format (default: :md)', &:to_sym) opt.on('-m REGEXP', '--match=REGEXP') { |str| Regexp.new(str) } opt.on('-i REGEXP', '--ignore=REGEXP') { |str| Regexp.new(str) } opt.on('-d DIR', '--dest-dir=DIR') opt.on('-e code') params = {} opt.order!(argv, into: params) params.transform_keys! { |k| k.to_s.gsub('-', '_').to_sym } if code = params.delete(:e) exec_code code, params else file = argv.shift unless file puts opt.help exit 1 end exec_command file, params end end |