Sha256: 69818bb5057d94c8314697320472630f89e6378177d8991022240449500816f7

Contents?: true

Size: 978 Bytes

Versions: 3

Compression:

Stored size: 978 Bytes

Contents

# frozen_string_literal: true

module I18nJSON
  class CLI
    attr_reader :ui

    def initialize(argv:, stdout:, stderr:)
      @argv = argv.dup
      @ui = UI.new(stdout: stdout, stderr: stderr)
    end

    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 def command_classes
      [InitCommand, ExportCommand]
    end

    private def commands
      command_classes.map do |command_class|
        command_class.new(argv: @argv, ui: ui)
      end
    end

    private 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
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
i18n-json-0.0.3 lib/i18n-json/cli.rb
i18n-json-0.0.2 lib/i18n-json/cli.rb
i18n-json-0.0.1 lib/i18n-json/cli.rb