Class: Travis::CLI::Command
- Inherits:
-
Object
- Object
- Travis::CLI::Command
show all
- Extended by:
- Forwardable, Parser
- Defined in:
- lib/travis/cli/command.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Parser
new, on, on_initialize
Constructor Details
#initialize(options = {}) ⇒ Command
Returns a new instance of Command.
57
58
59
60
61
62
63
64
65
|
# File 'lib/travis/cli/command.rb', line 57
def initialize(options = {})
@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.
54
55
56
|
# File 'lib/travis/cli/command.rb', line 54
def arguments
@arguments
end
|
#config ⇒ Object
Returns the value of attribute config.
54
55
56
|
# File 'lib/travis/cli/command.rb', line 54
def config
@config
end
|
#force_interactive ⇒ Object
Returns the value of attribute force_interactive.
54
55
56
|
# File 'lib/travis/cli/command.rb', line 54
def force_interactive
@force_interactive
end
|
Returns the value of attribute formatter.
54
55
56
|
# File 'lib/travis/cli/command.rb', line 54
def formatter
@formatter
end
|
Returns the value of attribute input.
55
56
57
|
# File 'lib/travis/cli/command.rb', line 55
def input
@input
end
|
#output ⇒ Object
Returns the value of attribute output.
55
56
57
|
# File 'lib/travis/cli/command.rb', line 55
def output
@output
end
|
Class Method Details
.abstract ⇒ Object
46
47
48
|
# File 'lib/travis/cli/command.rb', line 46
def self.abstract
@@abstract << self
end
|
.abstract? ⇒ Boolean
42
43
44
|
# File 'lib/travis/cli/command.rb', line 42
def self.abstract?
@@abstract.include? self
end
|
.command_name ⇒ Object
37
38
39
|
# File 'lib/travis/cli/command.rb', line 37
def self.command_name
name[/[^:]*$/].downcase
end
|
.skip(name) ⇒ Object
50
51
52
|
# File 'lib/travis/cli/command.rb', line 50
def self.skip(name)
define_method(name) {}
end
|
Instance Method Details
#command_name ⇒ Object
109
110
111
|
# File 'lib/travis/cli/command.rb', line 109
def command_name
self.class.command_name
end
|
#debug(line) ⇒ Object
138
139
140
141
142
|
# File 'lib/travis/cli/command.rb', line 138
def debug(line)
write_to($stderr) do
say color("** #{line}", :debug)
end
end
|
#execute ⇒ Object
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/travis/cli/command.rb', line 98
def execute
check_arity(method(:run), *arguments)
load_config
setup
run(*arguments)
store_config
rescue StandardError => e
raise(e) if explode?
error e.message
end
|
#help ⇒ Object
129
130
131
132
|
# File 'lib/travis/cli/command.rb', line 129
def help
parser.banner = usage
parser.to_s
end
|
#parse(args) ⇒ Object
88
89
90
91
92
93
|
# File 'lib/travis/cli/command.rb', line 88
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
134
135
136
|
# File 'lib/travis/cli/command.rb', line 134
def say(data, format = nil, style = nil)
terminal.say format(data, format, style)
end
|
#setup ⇒ Object
95
96
|
# File 'lib/travis/cli/command.rb', line 95
def setup
end
|
#terminal ⇒ Object
67
68
69
|
# File 'lib/travis/cli/command.rb', line 67
def terminal
@terminal ||= HighLine.new(input, output)
end
|
#usage ⇒ Object
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
|
# File 'lib/travis/cli/command.rb', line 113
def usage
usage = "#$0 #{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
81
82
83
84
85
86
|
# File 'lib/travis/cli/command.rb', line 81
def write_to(io)
io_was, self.output = output, io
yield
ensure
self.output = io_was if io_was
end
|