Class: GitHub::Command
- Includes:
- FileUtils
- Defined in:
- lib/github/command.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Shell
Instance Method Summary collapse
- #call(*args) ⇒ Object
- #current_user?(user) ⇒ Boolean
- #die(message) ⇒ Object
- #git(command) ⇒ Object
- #git_exec(command) ⇒ Object
- #github_token ⇒ Object
- #github_user ⇒ Object
- #helper ⇒ Object
- #highline ⇒ Object
-
#initialize(block) ⇒ Command
constructor
A new instance of Command.
- #options ⇒ Object
- #pgit(*command) ⇒ Object
- #request_github_credentials ⇒ Object
- #run(method, command) ⇒ Object
- #sh(*command) ⇒ Object
- #shell_user ⇒ Object
Constructor Details
#initialize(block) ⇒ Command
Returns a new instance of Command.
18 19 20 |
# File 'lib/github/command.rb', line 18 def initialize(block) (class << self;self end).send :define_method, :command, &block end |
Instance Method Details
#call(*args) ⇒ Object
22 23 24 25 26 |
# File 'lib/github/command.rb', line 22 def call(*args) arity = method(:command).arity args << nil while args.size < arity send :command, *args end |
#current_user?(user) ⇒ Boolean
111 112 113 |
# File 'lib/github/command.rb', line 111 def current_user?(user) user == github_user || user == shell_user end |
#die(message) ⇒ Object
64 65 66 67 |
# File 'lib/github/command.rb', line 64 def die() puts "=> #{}" exit! end |
#git(command) ⇒ Object
40 41 42 |
# File 'lib/github/command.rb', line 40 def git(command) run :sh, command end |
#git_exec(command) ⇒ Object
44 45 46 |
# File 'lib/github/command.rb', line 44 def git_exec(command) run :exec, command end |
#github_token ⇒ Object
78 79 80 81 82 83 84 85 |
# File 'lib/github/command.rb', line 78 def github_token token = git("config --get github.token") if token.empty? request_github_credentials token = github_token end token end |
#github_user ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/github/command.rb', line 69 def github_user user = git("config --get github.user") if user.empty? request_github_credentials user = github_user end user end |
#helper ⇒ Object
28 29 30 |
# File 'lib/github/command.rb', line 28 def helper @helper ||= Helper.new end |
#highline ⇒ Object
103 104 105 |
# File 'lib/github/command.rb', line 103 def highline @highline ||= HighLine.new end |
#pgit(*command) ⇒ Object
36 37 38 |
# File 'lib/github/command.rb', line 36 def pgit(*command) puts git(*command) end |
#request_github_credentials ⇒ Object
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/github/command.rb', line 87 def request_github_credentials puts "Please enter your GitHub credentials:" user = highline.ask("Username: ") while user.nil? || user.empty? git("config --global github.user '#{user}'") puts("Your account token is at https://github.com/account under 'Account Admin'.") puts("Press Enter to launch page in browser.") token = highline.ask("Token: ") while token.strip.empty? helper.open "https://github.com/account" token = highline.ask("Token: ") end git("config --global github.token '#{token}'") true end |
#run(method, command) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/github/command.rb', line 48 def run(method, command) if command.is_a? Array command = [ 'git', command ].flatten GitHub.learn command.join(' ') else command = 'git ' + command GitHub.learn command end send method, *command end |
#sh(*command) ⇒ Object
60 61 62 |
# File 'lib/github/command.rb', line 60 def sh(*command) Shell.new(*command).run end |
#shell_user ⇒ Object
107 108 109 |
# File 'lib/github/command.rb', line 107 def shell_user ENV['USER'] end |