Class: GitCommands::CLI

Inherits:
Object
  • Object
show all
Includes:
Prompt
Defined in:
lib/git_commands/cli.rb

Defined Under Namespace

Classes: UnknownCommandError

Constant Summary collapse

VALID_COMMANDS =
%w[rebase aggregate purge]

Constants included from Prompt

Prompt::VALID_ANSWERS

Instance Method Summary collapse

Methods included from Prompt

#confirm, #error, #out, #success, #warning

Constructor Details

#initialize(command_name:, args: ARGV, out: STDOUT, command_klass: Command) ⇒ CLI

Returns a new instance of CLI.



12
13
14
15
16
17
18
19
# File 'lib/git_commands/cli.rb', line 12

def initialize(command_name:, args: ARGV, out: STDOUT, command_klass: Command)
  @command_name = check_command_name(command_name)
  @command_klass = command_klass
  @args = args
  @out = out 
  @repo = nil
  @branches = nil
end

Instance Method Details

#callObject



21
22
23
24
25
26
27
# File 'lib/git_commands/cli.rb', line 21

def call
  parser.parse!(@args)
  command = @command_klass.new(repo: @repo, branches: @branches)
  command.send(@command_name)
rescue Command::GitError, AbortError, ArgumentError => e
  error(e.message)  
end