Class: Opener::TreeTagger::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/opener/tree_tagger/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv, options = {}) ⇒ CLI

Returns a new instance of CLI.

Parameters:

  • argv (Array)
  • options (Hash) (defaults to: {})


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/opener/tree_tagger/cli.rb', line 10

def initialize(argv, options = {})
  @argv    = argv
  @options = DEFAULT_OPTIONS.merge(options)

  @option_parser = OptionParser.new do |opts|
    opts.program_name   = 'tree-tagger'
    opts.summary_indent = '  '

    opts.separator "\nOptions:\n\n"

    opts.on('-l', '--log', 'Enable logging to STDERR') do
      @options[:logging] = true
    end

    opts.on('--no-time', 'Disables adding of timestamps') do
      @options[:args] << '--no-time'
    end

    opts.separator <<-EOF

Examples:

  cat example.kaf | #{opts.program_name}    # Basic usage
  cat example.kaf | #{opts.program_name} -l # Logs information to STDERR
    EOF
  end
end

Instance Attribute Details

#argvObject (readonly)

Returns the value of attribute argv.



4
5
6
# File 'lib/opener/tree_tagger/cli.rb', line 4

def argv
  @argv
end

#option_parserObject (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

#optionsObject (readonly)

Returns the value of attribute options.



4
5
6
# File 'lib/opener/tree_tagger/cli.rb', line 4

def options
  @options
end

Instance Method Details

#run(input) ⇒ Object

Parameters:

  • input (String)


41
42
43
44
45
46
47
# File 'lib/opener/tree_tagger/cli.rb', line 41

def run(input)
  option_parser.parse!(argv)

  tagger = TreeTagger.new(options)

  puts tagger.run(input)
end