Sha256: 6f3acae631d0d0273d42e930d3ac25ccfcc8ce5a31116d5e22611da0af5cba78

Contents?: true

Size: 1.71 KB

Versions: 9

Compression:

Stored size: 1.71 KB

Contents

# frozen_string_literal: true

require "core"
require "refinements/structs"

module Hanamismith
  module CLI
    module Parsers
      # Handles parsing of Command Line Interface (CLI) core options.
      class Core
        include Import[:specification]

        using Refinements::Structs

        def self.call(...) = new(...).call

        def initialize(configuration = Container[:configuration], client: Parser::CLIENT, **)
          super(**)
          @configuration = configuration
          @client = client
        end

        def call arguments = ::Core::EMPTY_ARRAY
          client.banner = specification.labeled_summary
          client.separator "\nUSAGE:\n"
          collate
          client.parse arguments
          configuration
        end

        private

        attr_reader :configuration, :client

        def collate = private_methods.sort.grep(/add_/).each { |method| __send__ method }

        def add_build
          client.on "-b", "--build NAME [options]", "Build new project." do |name|
            configuration.merge! action_build: true, project_name: name
          end
        end

        def add_config
          client.on "-c",
                    "--config ACTION",
                    %i[edit view],
                    "Manage gem configuration: edit or view." do |action|
            configuration.merge! action_config: action
          end
        end

        def add_version
          client.on "-v", "--version", "Show gem version." do
            configuration.merge! action_version: true
          end
        end

        def add_help
          client.on "-h", "--help", "Show this message." do
            configuration.merge! action_help: true
          end
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
hanamismith-0.12.0 lib/hanamismith/cli/parsers/core.rb
hanamismith-0.11.0 lib/hanamismith/cli/parsers/core.rb
hanamismith-0.10.0 lib/hanamismith/cli/parsers/core.rb
hanamismith-0.9.0 lib/hanamismith/cli/parsers/core.rb
hanamismith-0.8.0 lib/hanamismith/cli/parsers/core.rb
hanamismith-0.7.0 lib/hanamismith/cli/parsers/core.rb
hanamismith-0.6.0 lib/hanamismith/cli/parsers/core.rb
hanamismith-0.5.0 lib/hanamismith/cli/parsers/core.rb
hanamismith-0.4.0 lib/hanamismith/cli/parsers/core.rb