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 remove]

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, computer_klass: Computer) ⇒ 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, computer_klass: Computer)
  @command_name = check_command_name(command_name)
  @computer_klass = computer_klass
  @args = args
  @out = out 
  @repo = nil
  @branches = nil
end

Instance Method Details

#callObject



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

def call
  parser.parse!(@args)
  @origin ||= Branch::ORIGIN
  @default ||= Branch::DEFAULT
  computer = @computer_klass.new(repo: @repo, branches: @branches, origin: @origin, default: @default)
  computer.send(@command_name)
rescue Repository::PathError, Computer::GitError, AbortError, Repository::InvalidError => e
  error(e.message)  
  exit
end