Class: Octocat::CommandLine

Inherits:
Object
  • Object
show all
Defined in:
lib/octocat/command_line.rb

Constant Summary collapse

COMMANDS =
%w(open-branch new-pr open-pr compare-branch help)

Instance Method Summary collapse

Constructor Details

#initialize(arguments) ⇒ CommandLine

Returns a new instance of CommandLine.



7
8
9
10
# File 'lib/octocat/command_line.rb', line 7

def initialize arguments
  @command = arguments.first
  @api = API.new
end

Instance Method Details

#current_branchObject



45
46
47
# File 'lib/octocat/command_line.rb', line 45

def current_branch
  `git rev-parse --abbrev-ref HEAD`.chomp
end

#helpObject



38
39
40
41
42
43
# File 'lib/octocat/command_line.rb', line 38

def help
  COMMANDS.each do |command|
    puts "- #{command}"
  end
  puts
end

#runObject



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

def run
  if command
    run_command
  else
    puts "Octocat Version #{VERSION}"
    help
  end
end

#run_commandObject



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/octocat/command_line.rb', line 21

def run_command
  if command == "open-branch"
    api.open_branch(project, current_branch)
  elsif command == "new-pr"
    api.new_pr(project, current_branch)
  elsif command == "open-pr"
    api.open_pr(project, current_branch)
  elsif command == "compare-branch"
    api.compare_branch(project, current_branch)
  elsif command == "help"
    help
  else
    puts "Unknown Command. The known commands are:"
    help
  end
end