Class: Opener::TreeTagger::CLI
- Inherits:
-
Object
- Object
- Opener::TreeTagger::CLI
- Defined in:
- lib/opener/tree_tagger/cli.rb
Instance Attribute Summary collapse
-
#option_parser ⇒ Object
readonly
Returns the value of attribute option_parser.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ CLI
constructor
A new instance of CLI.
- #run(input) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ CLI
Returns a new instance of CLI.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/opener/tree_tagger/cli.rb', line 9 def initialize( = {}) = DEFAULT_OPTIONS.merge() @option_parser = OptionParser.new do |opts| opts.program_name = 'tree-tagger' opts.summary_indent = ' ' opts.on('-l', '--log', 'Enable logging to STDERR') do [:logging] = true end opts.separator "\nExamples:\n\n cat example.kaf | \#{opts.program_name} # Basic usage\n cat example.kaf | \#{opts.program_name} -l # Logs information to STDERR\n EOF\n end\nend\n" |
Instance Attribute Details
#option_parser ⇒ Object (readonly)
Returns the value of attribute option_parser.
4 5 6 |
# File 'lib/opener/tree_tagger/cli.rb', line 4 def option_parser @option_parser end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/opener/tree_tagger/cli.rb', line 4 def end |
Instance Method Details
#run(input) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/opener/tree_tagger/cli.rb', line 33 def run(input) option_parser.parse!([:args]) tagger = TreeTagger.new() stdout, stderr, process = tagger.run(input) if process.success? puts stdout if [:logging] and !stderr.empty? STDERR.puts(stderr) end else abort stderr end end |