Class: Opener::PropertyTagger::CLI

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

Overview

CLI wrapper around Opener::PropertyTagger using OptionParser.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCLI

Returns a new instance of CLI.



14
15
16
# File 'lib/opener/property_tagger/cli.rb', line 14

def initialize
  @parser = configure_slop
end

Instance Attribute Details

#parserSlop (readonly)

Returns:

  • (Slop)


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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/opener/property_tagger/cli.rb', line 11

class CLI
  attr_reader :parser

  def initialize
    @parser = configure_slop
  end

  ##
  # @param [Array] argv
  #
  def run(argv = ARGV)
    parser.parse(argv)
  end

  ##
  # @return [Slop]
  #
  def configure_slop
    return Slop.new(:strict => false, :indent => 2, :help => true) do
      banner 'Usage: property-tagger [OPTIONS] -- [PYTHON OPTIONS]'

      separator "\nAbout:\n\nComponent for finding the properties in a KAF document. This command reads\ninput from STDIN.\n\nExamples:\n\nProcessing a KAF file:\n\n    cat some_file.kaf | property-tagger\n\nDisplaying the underlying kernel options:\n\n    property-tagger -- --help\n\n      EOF\n\n      separator \"\\nOptions:\\n\"\n\n      on :v, :version, 'Shows the current version' do\n        abort \"property-tagger v\#{VERSION} on \#{RUBY_DESCRIPTION}\"\n      end\n\n      on :'no-time', 'Disables adding of timestamps'\n\n      on :ugly, 'Disables pretty formatting of XML (faster)'\n\n      run do |opts, args|\n        tagger = PropertyTagger.new(\n          :args    => args,\n          :no_time => opts[:'no-time'],\n          :pretty  => !opts[:ugly]\n        )\n\n        input  = STDIN.tty? ? nil : STDIN.read\n\n        puts tagger.run(input)\n      end\n    end\n  end\nend\n".chomp

Instance Method Details

#configure_slopSlop

Returns:

  • (Slop)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/opener/property_tagger/cli.rb', line 28

def configure_slop
  return Slop.new(:strict => false, :indent => 2, :help => true) do
    banner 'Usage: property-tagger [OPTIONS] -- [PYTHON OPTIONS]'

    separator "\nAbout:\n\n    Component for finding the properties in a KAF document. This command reads\n    input from STDIN.\n\nExamples:\n\n    Processing a KAF file:\n\n  cat some_file.kaf | property-tagger\n\n    Displaying the underlying kernel options:\n\n  property-tagger -- --help\n\n    EOF\n\n    separator \"\\nOptions:\\n\"\n\n    on :v, :version, 'Shows the current version' do\n      abort \"property-tagger v\#{VERSION} on \#{RUBY_DESCRIPTION}\"\n    end\n\n    on :'no-time', 'Disables adding of timestamps'\n\n    on :ugly, 'Disables pretty formatting of XML (faster)'\n\n    run do |opts, args|\n      tagger = PropertyTagger.new(\n        :args    => args,\n        :no_time => opts[:'no-time'],\n        :pretty  => !opts[:ugly]\n      )\n\n      input  = STDIN.tty? ? nil : STDIN.read\n\n      puts tagger.run(input)\n    end\n  end\nend\n".chomp

#run(argv = ARGV) ⇒ Object

Parameters:

  • argv (Array) (defaults to: ARGV)


21
22
23
# File 'lib/opener/property_tagger/cli.rb', line 21

def run(argv = ARGV)
  parser.parse(argv)
end