class I18nJSON::CLI

Attributes

ui[R]

Public Class Methods

new(argv:, stdout:, stderr:) click to toggle source
# File lib/i18n-json/cli.rb, line 7
def initialize(argv:, stdout:, stderr:)
  @argv = argv.dup
  @ui = UI.new(stdout: stdout, stderr: stderr)
end

Public Instance Methods

call() click to toggle source
# File lib/i18n-json/cli.rb, line 12
def call
  command_name = @argv.shift
  command = commands.find {|cmd| cmd.name == command_name }

  ui.fail_with(root_help) unless command

  command.call
end

Private Instance Methods

command_classes() click to toggle source
# File lib/i18n-json/cli.rb, line 21
        def command_classes
  [InitCommand, ExportCommand]
end
commands() click to toggle source
# File lib/i18n-json/cli.rb, line 25
        def commands
  command_classes.map do |command_class|
    command_class.new(argv: @argv, ui: ui)
  end
end
root_help() click to toggle source
# File lib/i18n-json/cli.rb, line 31
            def root_help
      commands_list = commands
                      .map {|cmd| "- #{cmd.name}: #{cmd.description}" }
                      .join("\n")

      <<~TEXT
        Usage: i18n-json COMMAND FLAGS

        Commands:

        #{commands_list}

        Run `i18n-json COMMAND --help` for more information on specific commands.
      TEXT
    end