Sha256: f3457175719d04883d04c54559d926de17c8174cc6eb95dd7b9cb85423f70a73

Contents?: true

Size: 1.95 KB

Versions: 14

Compression:

Stored size: 1.95 KB

Contents

# frozen_string_literal: true

require "refinements/structs"

module Rubysmith
  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,
                       **dependencies
          super(**dependencies)
          @configuration = configuration
          @client = client
        end

        def call arguments = []
          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_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_build
          client.on "-b", "--build NAME [options]", "Build new project." do |name|
            configuration.merge! action_build: true, project_name: name
          end
        end

        def add_publish
          client.on "-p", "--publish VERSION", "Publish project." do |version|
            configuration.merge! action_publish: true, project_version: version
          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

14 entries across 14 versions & 1 rubygems

Version Path
rubysmith-4.2.0 lib/rubysmith/cli/parsers/core.rb
rubysmith-4.1.0 lib/rubysmith/cli/parsers/core.rb
rubysmith-4.0.1 lib/rubysmith/cli/parsers/core.rb
rubysmith-4.0.0 lib/rubysmith/cli/parsers/core.rb
rubysmith-3.8.0 lib/rubysmith/cli/parsers/core.rb
rubysmith-3.7.0 lib/rubysmith/cli/parsers/core.rb
rubysmith-3.6.0 lib/rubysmith/cli/parsers/core.rb
rubysmith-3.5.0 lib/rubysmith/cli/parsers/core.rb
rubysmith-3.4.0 lib/rubysmith/cli/parsers/core.rb
rubysmith-3.3.0 lib/rubysmith/cli/parsers/core.rb
rubysmith-3.2.0 lib/rubysmith/cli/parsers/core.rb
rubysmith-3.1.0 lib/rubysmith/cli/parsers/core.rb
rubysmith-3.0.1 lib/rubysmith/cli/parsers/core.rb
rubysmith-3.0.0 lib/rubysmith/cli/parsers/core.rb