Sha256: a8ac55b244c5fdb90b6113000705cb1fa943bf1ff670025ecea5548b559c1f02

Contents?: true

Size: 1.41 KB

Versions: 9

Compression:

Stored size: 1.41 KB

Contents

# frozen_string_literal: true

require "refinements/structs"

module Pennyworth
  module CLI
    module Parsers
      # Handles parsing of Command Line Interface (CLI) GitHub options.
      class GitHub
        using Refinements::Structs

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

        def initialize configuration = Configuration::Loader.call, client: CLIENT
          @configuration = configuration
          @client = client
        end

        def call arguments = []
          client.separator "\nGITHUB OPTIONS:\n"
          private_methods.sort.grep(/add_/).each { |method| __send__ method }
          arguments.empty? ? arguments : client.parse!(arguments)
        end

        private

        attr_reader :configuration, :client

        def add_organization
          client.on(
            "--organization [HANDLE]",
            %(Set organization. Default: "#{organization}".)
          ) do |handle|
            configuration.merge! action_git_hub: :organization,
                                 git_hub_organization: handle || organization
          end
        end

        def add_user
          client.on "--user [HANDLE]", %(Set user. Default: "#{user}".) do |handle|
            configuration.merge! action_git_hub: :user, git_hub_user: handle || user
          end
        end

        def organization = configuration.git_hub_organization

        def user = configuration.git_hub_user
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
pennyworth-11.2.2 lib/pennyworth/cli/parsers/git_hub.rb
pennyworth-11.2.1 lib/pennyworth/cli/parsers/git_hub.rb
pennyworth-11.2.0 lib/pennyworth/cli/parsers/git_hub.rb
pennyworth-11.1.3 lib/pennyworth/cli/parsers/git_hub.rb
pennyworth-11.1.2 lib/pennyworth/cli/parsers/git_hub.rb
pennyworth-11.1.1 lib/pennyworth/cli/parsers/git_hub.rb
pennyworth-11.1.0 lib/pennyworth/cli/parsers/git_hub.rb
pennyworth-11.0.1 lib/pennyworth/cli/parsers/git_hub.rb
pennyworth-11.0.0 lib/pennyworth/cli/parsers/git_hub.rb