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 =
<<-EOMSG
1. Press [enter], and you'll be taken CircleCI.
2. Enter a name for your new token.
3. Click 'Create new token'.
4. Come back to your prompt and paste in your new token.
5. Press enter to complete the process.
EOMSG
NO_TOKEN_MESSAGE =
<<-EOMSG
CircleCI token hasn't been configured. Run the following command to login:

  $ circle login
EOMSG

Instance Method Summary collapse

Instance Method Details

#buildObject



71
72
73
74
75
76
# File 'lib/circle/cli/app.rb', line 71

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

#cancelObject



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

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



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

def 
  say LOGIN_HELP, :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



63
64
65
66
67
# File 'lib/circle/cli/app.rb', line 63

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

#overviewObject



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/circle/cli/app.rb', line 49

def overview
  validate_repo!
  abort! 'No recent builds.' if project.recent_builds.empty?
  show_overview = -> { display_builds(project.recent_builds) }

  if options[:watch]
    watching(-> { project.recent_builds  }, &show_overview)
  else
    show_overview
  end
end

#statusObject



29
30
31
32
33
# File 'lib/circle/cli/app.rb', line 29

def status
  validate_repo!
  validate_latest!
  display_status
end

#token(value = nil) ⇒ Object



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

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



38
39
40
41
42
43
44
# File 'lib/circle/cli/app.rb', line 38

def watch
  validate_repo!
  validate_latest!
  watching -> { project.latest.preload } do
    display_status
  end
end