Class: I18nJSON::CLI::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/i18n-json/cli/command.rb

Direct Known Subclasses

ExportCommand, InitCommand

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(argv:, ui:) ⇒ Command

Returns a new instance of Command.



28
29
30
31
# File 'lib/i18n-json/cli/command.rb', line 28

def initialize(argv:, ui:)
  @argv = argv.dup
  @ui = ui
end

Instance Attribute Details

#argvObject (readonly)

Returns the value of attribute argv.



6
7
8
# File 'lib/i18n-json/cli/command.rb', line 6

def argv
  @argv
end

#uiObject (readonly)

Returns the value of attribute ui.



6
7
8
# File 'lib/i18n-json/cli/command.rb', line 6

def ui
  @ui
end

Class Method Details

.command(&block) ⇒ Object



24
25
26
# File 'lib/i18n-json/cli/command.rb', line 24

def self.command(&block)
  define_method(:command, &block)
end

.command_name(name) ⇒ Object



8
9
10
# File 'lib/i18n-json/cli/command.rb', line 8

def self.command_name(name)
  define_method(:name) { name }
end

.description(description) ⇒ Object



12
13
14
# File 'lib/i18n-json/cli/command.rb', line 12

def self.description(description)
  define_method(:description) { description }
end

.parse(&block) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/i18n-json/cli/command.rb', line 16

def self.parse(&block)
  define_method(:parse) do
    OptionParser
      .new {|opts| instance_exec(opts, &block) }
      .parse!(argv)
  end
end

Instance Method Details

#callObject



33
34
35
36
# File 'lib/i18n-json/cli/command.rb', line 33

def call
  parse
  command
end

#optionsObject



38
39
40
# File 'lib/i18n-json/cli/command.rb', line 38

def options
  @options ||= {}
end