Class: Circle::CLI
- Inherits:
-
Object
- Object
- Circle::CLI
- Defined in:
- lib/circle/cli.rb,
lib/circle/cli/version.rb
Constant Summary collapse
- VERSION =
'0.0.2'
Class Method Summary collapse
Instance Method Summary collapse
- #dispatch!(argv) ⇒ Object
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #run_github_token(token = nil) ⇒ Object
- #run_open ⇒ Object
- #run_status ⇒ Object
- #run_token(token = nil) ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
18 19 20 21 22 23 |
# File 'lib/circle/cli.rb', line 18 def initialize @options = {} @parser ||= OptionParser.new do |opts| # future options will go here end end |
Class Method Details
.run(*args) ⇒ Object
12 13 14 |
# File 'lib/circle/cli.rb', line 12 def run(*args) new.dispatch!(*args) end |
Instance Method Details
#dispatch!(argv) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/circle/cli.rb', line 25 def dispatch!(argv) @parser.parse! command, *args = argv command = 'status' unless command method = "run_#{command.gsub('-', '_')}" if respond_to?(method) send(method, *args) else abort!("Unknown command: #{command}") end end |
#run_github_token(token = nil) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/circle/cli.rb', line 66 def run_github_token(token=nil) if token repository.config['github.token'] = token else puts github_token end end |
#run_open ⇒ Object
51 52 53 54 55 56 |
# File 'lib/circle/cli.rb', line 51 def run_open unless last_status puts 'No CI run found' end open(last_status.rels[:target].href) end |
#run_status ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/circle/cli.rb', line 38 def run_status if last_status && last_status.state == 'success' puts last_status.state exit(0) elsif last_status puts last_status.state else puts 'unknown' end exit(1) end |
#run_token(token = nil) ⇒ Object
58 59 60 61 62 63 64 |
# File 'lib/circle/cli.rb', line 58 def run_token(token=nil) if token repository.config['circleci.token'] = token else puts circle_token end end |