class Tocer::CLI::Parsers::Core

Handles parsing of Command Line Interface (CLI) core options.

Public Class Methods

call(options: {}, client: CLIENT) click to toggle source
# File lib/tocer/cli/parsers/core.rb, line 10
    def self.call(options: {}, client: CLIENT) = new(options: options, client: client).call

    def initialize options: {}, client: CLIENT
      @options = options
      @client = client
    end

    def call arguments = []
      client.banner = "#{Identity::LABEL} - #{Identity::SUMMARY}"
      client.separator "\nUSAGE:\n"
      collate
      arguments.empty? ? arguments : client.parse!(arguments)
    end

    private

    attr_reader :options, :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|
        options[:config] = action
      end
    end

    def add_build
      client.on "-b", "--build [PATH]", %(Build table of contents. Default path: ".") do |value|
        options[:build] = value || "."
      end
    end

    def add_version
      client.on "-v", "--version", "Show gem version." do
        options[:version] = Identity::VERSION_LABEL
      end
    end

    def add_help
      client.on "-h", "--help", "Show this message." do
        options[:help] = true
      end
    end
  end
end
new(options: {}) click to toggle source
# File lib/tocer/cli/parsers/core.rb, line 12
def initialize options: {}, client: CLIENT
  @options = options
  @client = client
end

Public Instance Methods

add_build() click to toggle source
# File lib/tocer/cli/parsers/core.rb, line 41
def add_build
  client.on "-b", "--build [PATH]", %(Build table of contents. Default path: ".") do |value|
    options[:build] = value || "."
  end
end
add_config() click to toggle source
# File lib/tocer/cli/parsers/core.rb, line 30
def add_config
  client.on(
    "-c",
    "--config ACTION",
    %i[edit view],
    "Manage gem configuration: edit or view."
  ) do |action|
    options[:config] = action
  end
end
add_help() click to toggle source
# File lib/tocer/cli/parsers/core.rb, line 53
def add_help
  client.on "-h", "--help", "Show this message." do
    options[:help] = true
  end
end
add_version() click to toggle source
# File lib/tocer/cli/parsers/core.rb, line 47
def add_version
  client.on "-v", "--version", "Show gem version." do
    options[:version] = Identity::VERSION_LABEL
  end
end
call(arguments = []) click to toggle source
# File lib/tocer/cli/parsers/core.rb, line 17
def call arguments = []
  client.banner = "#{Identity::LABEL} - #{Identity::SUMMARY}"
  client.separator "\nUSAGE:\n"
  collate
  arguments.empty? ? arguments : client.parse!(arguments)
end
collate(= private_methods.sort.grep(/add_/).each { |method| __send__ method }) click to toggle source
# File lib/tocer/cli/parsers/core.rb, line 28
  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|
      options[:config] = action
    end
  end

  def add_build
    client.on "-b", "--build [PATH]", %(Build table of contents. Default path: ".") do |value|
      options[:build] = value || "."
    end
  end

  def add_version
    client.on "-v", "--version", "Show gem version." do
      options[:version] = Identity::VERSION_LABEL
    end
  end

  def add_help
    client.on "-h", "--help", "Show this message." do
      options[:help] = true
    end
  end
end