Sha256: 2a9eb3e138c39def5fd503b8242eba539361642c53442890edbeae082e012096

Contents?: true

Size: 1.1 KB

Versions: 11

Compression:

Stored size: 1.1 KB

Contents

require "chandler/cli/parser"
require "chandler/commands/push"
require "chandler/logging"
require "forwardable"

module Chandler
  # Handles constructing and invoking the appropriate chandler command
  # based on command line arguments and options provided by the CLI::Parser.
  # Essentially this is the "router" for the command-line app.
  #
  class CLI
    include Logging
    extend Forwardable
    def_delegator :@parser, :args
    def_delegator :@parser, :config

    def initialize(parser: Chandler::CLI::Parser.new(ARGV))
      @parser = parser
    end

    def run
      command.call
    end

    private

    def command # rubocop:disable Metrics/MethodLength
      case (command = args.shift)
      when "push"
        push
      when nil
        error("Please specify a command")
        info(@parser.usage)
        exit(1)
      else
        error("Unrecognized command: #{command}")
        info(@parser.usage)
        exit(1)
      end
    end

    def push
      Chandler::Commands::Push.new(
        :tags => args.empty? ? config.git.version_tags : args,
        :config => config
      )
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
chandler-0.9.0 lib/chandler/cli.rb
chandler-0.8.0 lib/chandler/cli.rb
chandler-0.7.0 lib/chandler/cli.rb
chandler-0.6.0 lib/chandler/cli.rb
chandler-0.5.0 lib/chandler/cli.rb
chandler-0.4.0 lib/chandler/cli.rb
chandler-0.3.1 lib/chandler/cli.rb
chandler-0.3.0 lib/chandler/cli.rb
chandler-0.2.0 lib/chandler/cli.rb
chandler-0.1.2 lib/chandler/cli.rb
chandler-0.1.1 lib/chandler/cli.rb