Class: Circle::CLI::App

Inherits:
Thor
  • Object
show all
Defined in:
lib/circle/cli/app.rb

Constant Summary collapse

CIRCLE_URL =
'https://circleci.com/account/api'
LOGIN_HELP =
"1. Press [enter], and you'll be taken CircleCI.\n2. Enter a name for your new token.\n3. Click 'Create new token'.\n4. Come back to your prompt and paste in your new token.\n5. Press enter to complete the process.\n"
NO_TOKEN_MESSAGE =
"CircleCI token hasn't been configured. Run the following command to login:\n\n  $ circle login\n"

Instance Method Summary collapse

Instance Method Details

#buildObject



90
91
92
93
94
95
# File 'lib/circle/cli/app.rb', line 90

def build
  validate_repo!
  project.build!
  say "A build has been triggered.\n\n", :green
  invoke :status, [], watch: true
end

#cancelObject



99
100
101
102
103
104
105
# File 'lib/circle/cli/app.rb', line 99

def cancel
  validate_repo!
  validate_latest!
  latest.cancel! unless latest.finished?
  invoke :status
  say "\nThe build has been cancelled.", :red unless latest.finished?
end

#loginObject



119
120
121
122
123
124
125
126
# File 'lib/circle/cli/app.rb', line 119

def 
  say , :yellow
  ask set_color("\nPress [enter] to open CircleCI", :blue)
  Launchy.open(CIRCLE_URL)
  value = ask set_color('Enter your token:', :blue)
  repo.circle_token = value
  say "\nYour token has been set to '#{value}'.", :green
end

#openObject



82
83
84
85
86
# File 'lib/circle/cli/app.rb', line 82

def open
  validate_repo!
  validate_latest!
  Launchy.open latest[:build_url]
end

#overviewObject



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/circle/cli/app.rb', line 60

def overview
  validate_repo!
  abort! 'No recent builds.' if project.recent_builds.empty?

  watcher = Watcher.new do
    display_builds(project.recent_builds)
  end

  watcher.to_preload do
    project.clear_cache!
    project.recent_builds
  end

  if options[:watch]
    watcher.poll(options[:poll])
  else
    watcher.display
  end
end

#statusObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/circle/cli/app.rb', line 32

def status
  validate_repo!
  validate_latest!

  watcher = Watcher.new do
    display_status
  end

  watcher.to_preload do
    project.clear_cache!
    project.latest.preload
  end

  if options[:watch]
    watcher.poll(options[:poll])
  else
    watcher.display
  end
end

#token(value = nil) ⇒ Object



108
109
110
111
112
113
114
115
116
# File 'lib/circle/cli/app.rb', line 108

def token(value = nil)
  if value
    repo.circle_token = value
  elsif value = repo.circle_token
    say value
  else
    say NO_TOKEN_MESSAGE, :yellow
  end
end

#watchObject



53
54
55
# File 'lib/circle/cli/app.rb', line 53

def watch
  invoke :status, [], watch: true
end