Class: I18nFlow::CLI

Inherits:
Object
  • Object
show all
Defined in:
lib/i18n_flow/cli.rb,
lib/i18n_flow/cli/color.rb,
lib/i18n_flow/cli/command_base.rb,
lib/i18n_flow/cli/copy_command.rb,
lib/i18n_flow/cli/help_command.rb,
lib/i18n_flow/cli/lint_command.rb,
lib/i18n_flow/cli/split_command.rb,
lib/i18n_flow/cli/format_command.rb,
lib/i18n_flow/cli/search_command.rb,
lib/i18n_flow/cli/version_command.rb,
lib/i18n_flow/cli/read_config_command.rb

Defined Under Namespace

Modules: Color Classes: CommandBase, CopyCommand, FormatCommand, HelpCommand, LintCommand, ReadConfigCommand, SearchCommand, SplitCommand, VersionCommand

Constant Summary collapse

COMMANDS =
{
  'copy'        => CopyCommand,
  'format'      => FormatCommand,
  'help'        => HelpCommand,
  'lint'        => LintCommand,
  'read_config' => ReadConfigCommand,
  'search'      => SearchCommand,
  'split'       => SplitCommand,
  'version'     => VersionCommand,
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ CLI

Returns a new instance of CLI.



28
29
30
31
# File 'lib/i18n_flow/cli.rb', line 28

def initialize(args)
  @global_options = I18nFlow::Util.parse_options(args)
  @command, *@args = args
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



24
25
26
# File 'lib/i18n_flow/cli.rb', line 24

def args
  @args
end

#commandObject (readonly)

Returns the value of attribute command.



25
26
27
# File 'lib/i18n_flow/cli.rb', line 25

def command
  @command
end

#global_optionsObject (readonly)

Returns the value of attribute global_options.



26
27
28
# File 'lib/i18n_flow/cli.rb', line 26

def global_options
  @global_options
end

Instance Method Details

#runObject



33
34
35
36
37
38
39
40
41
42
43
# File 'lib/i18n_flow/cli.rb', line 33

def run
  if global_options['v'] || global_options['version']
    @command = 'version'
  end
  if global_options['h']
    @command = 'help'
  end

  command_class = COMMANDS[command] || COMMANDS['help']
  command_class.new(args).invoke!
end