Class: Travis::CLI::Command
Constant Summary
Tools::Assets::BASE
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
asset, asset_path
Methods included from Parser
new, on, on_initialize
Constructor Details
#initialize(options = {}) ⇒ Command
Returns a new instance of Command.
69
70
71
72
73
74
75
76
77
78
|
# File 'lib/travis/cli/command.rb', line 69
def initialize(options = {})
@on_signal = []
@formatter = Travis::Tools::Formatter.new
self.output = $stdout
self.input = $stdin
options.each do |key, value|
public_send("#{key}=", value) if respond_to? "#{key}="
end
@arguments ||= []
end
|
Instance Attribute Details
#arguments ⇒ Object
Returns the value of attribute arguments.
66
67
68
|
# File 'lib/travis/cli/command.rb', line 66
def arguments
@arguments
end
|
#config ⇒ Object
Returns the value of attribute config.
66
67
68
|
# File 'lib/travis/cli/command.rb', line 66
def config
@config
end
|
#force_interactive ⇒ Object
Returns the value of attribute force_interactive.
66
67
68
|
# File 'lib/travis/cli/command.rb', line 66
def force_interactive
@force_interactive
end
|
Returns the value of attribute formatter.
66
67
68
|
# File 'lib/travis/cli/command.rb', line 66
def formatter
@formatter
end
|
Returns the value of attribute input.
67
68
69
|
# File 'lib/travis/cli/command.rb', line 67
def input
@input
end
|
#output ⇒ Object
Returns the value of attribute output.
67
68
69
|
# File 'lib/travis/cli/command.rb', line 67
def output
@output
end
|
Class Method Details
.abstract ⇒ Object
53
54
55
|
# File 'lib/travis/cli/command.rb', line 53
def self.abstract
@@abstract << self
end
|
.abstract? ⇒ Boolean
49
50
51
|
# File 'lib/travis/cli/command.rb', line 49
def self.abstract?
@@abstract.include? self
end
|
.command_name ⇒ Object
44
45
46
|
# File 'lib/travis/cli/command.rb', line 44
def self.command_name
name[/[^:]*$/].downcase
end
|
.description(description = nil) ⇒ Object
61
62
63
64
|
# File 'lib/travis/cli/command.rb', line 61
def self.description(description = nil)
@description = description if description
@description ||= ""
end
|
.skip(name) ⇒ Object
57
58
59
|
# File 'lib/travis/cli/command.rb', line 57
def self.skip(name)
define_method(name) {}
end
|
Instance Method Details
#check_completion ⇒ Object
136
137
138
139
140
141
142
143
144
|
# File 'lib/travis/cli/command.rb', line 136
def check_completion
return if skip_completion_check? or config['checked_completion'] or !interactive?
write_to($stderr) do
next if Tools::Completion.completion_installed?
next unless agree('Shell completion not installed. Would you like to like to install it now? ') { |q| q.default = "y" }
Tools::Completion.install_completion
end
config['checked_completion'] = true
end
|
#check_ruby ⇒ Object
146
147
148
149
|
# File 'lib/travis/cli/command.rb', line 146
def check_ruby
return if RUBY_VERSION > '1.9.2' or skip_version_check?
warn "Your Ruby version is outdated, please consider upgrading, as we will drop support for #{RUBY_VERSION} soon!"
end
|
#check_version ⇒ Object
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
# File 'lib/travis/cli/command.rb', line 119
def check_version
last_check.clear if last_check['version'] != Travis::VERSION
return if skip_version_check?
return if Time.now.to_i - last_check['at'].to_i < 3600
Timeout.timeout 1.0 do
response = Faraday.get('https://rubygems.org/api/v1/gems/travis.json', {}, 'If-None-Match' => last_check['etag'].to_s)
last_check['etag'] = response.['etag']
last_check['version'] = JSON.parse(response.body)['version'] if response.status == 200
end
last_check['at'] = Time.now.to_i
error "Outdated CLI version, run `gem install travis` or use --skip-version-check." if Travis::VERSION < last_check['version']
rescue Timeout::Error, Faraday::Error::ClientError
end
|
#command_name ⇒ Object
168
169
170
|
# File 'lib/travis/cli/command.rb', line 168
def command_name
self.class.command_name
end
|
#debug(line) ⇒ Object
197
198
199
200
201
|
# File 'lib/travis/cli/command.rb', line 197
def debug(line)
write_to($stderr) do
say color("** #{line}", :debug)
end
end
|
#execute ⇒ Object
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
|
# File 'lib/travis/cli/command.rb', line 151
def execute
setup_trap
check_ruby
check_arity(method(:run), *arguments)
load_config
check_version
check_completion
setup
run(*arguments)
store_config
rescue StandardError => e
raise(e) if explode?
message = e.message
message += " - need to run `travis login` again?" if Travis::Client::Error === e and message == 'access denied'
error message
end
|
#help(info = "") ⇒ Object
188
189
190
191
|
# File 'lib/travis/cli/command.rb', line 188
def help(info = "")
parser.banner = usage
self.class.description.sub(/./) { |c| c.upcase } + ".\n" + info + parser.to_s
end
|
#info(line) ⇒ Object
203
204
205
206
207
|
# File 'lib/travis/cli/command.rb', line 203
def info(line)
write_to($stderr) do
say color(line, :info)
end
end
|
#last_check ⇒ Object
111
112
113
114
115
116
117
|
# File 'lib/travis/cli/command.rb', line 111
def last_check
config['last_check'] ||= {
'at' => config.delete('last_version_check'),
'etag' => config.delete('etag')
}
end
|
#on_signal(&block) ⇒ Object
209
210
211
|
# File 'lib/travis/cli/command.rb', line 209
def on_signal(&block)
@on_signal << block
end
|
#parse(args) ⇒ Object
101
102
103
104
105
106
|
# File 'lib/travis/cli/command.rb', line 101
def parse(args)
rest = parser.parse(args)
arguments.concat(rest)
rescue OptionParser::ParseError => e
error e.message
end
|
#say(data, format = nil, style = nil) ⇒ Object
193
194
195
|
# File 'lib/travis/cli/command.rb', line 193
def say(data, format = nil, style = nil)
terminal.say format(data, format, style)
end
|
#setup ⇒ Object
108
109
|
# File 'lib/travis/cli/command.rb', line 108
def setup
end
|
#terminal ⇒ Object
80
81
82
|
# File 'lib/travis/cli/command.rb', line 80
def terminal
@terminal ||= HighLine.new(input, output)
end
|
#usage ⇒ Object
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
|
# File 'lib/travis/cli/command.rb', line 172
def usage
usage = "travis #{command_name}"
method = method(:run)
if method.respond_to? :parameters
method.parameters.each do |type, name|
name = "[#{name}]" if type == :opt
name = "[#{name}..]" if type == :rest
usage << " #{name}"
end
elsif method.arity != 0
usage << " ..."
end
usage << " [options]"
"Usage: " << color(usage, :command)
end
|
#write_to(io) ⇒ Object
94
95
96
97
98
99
|
# File 'lib/travis/cli/command.rb', line 94
def write_to(io)
io_was, self.output = output, io
yield
ensure
self.output = io_was if io_was
end
|