Class: Octocat::CommandLine
- Inherits:
-
Object
- Object
- Octocat::CommandLine
- 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
- #current_branch ⇒ Object
- #help ⇒ Object
-
#initialize(arguments) ⇒ CommandLine
constructor
A new instance of CommandLine.
- #run ⇒ Object
- #run_command ⇒ Object
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_branch ⇒ Object
45 46 47 |
# File 'lib/octocat/command_line.rb', line 45 def current_branch `git rev-parse --abbrev-ref HEAD`.chomp end |
#help ⇒ Object
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 |
#run ⇒ Object
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_command ⇒ Object
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 |