Class: Tweetwine::CLI::Command
- Inherits:
-
Object
- Object
- Tweetwine::CLI::Command
show all
- Defined in:
- lib/tweetwine/cli.rb
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(args) ⇒ Command
Returns a new instance of Command.
191
192
193
194
|
# File 'lib/tweetwine/cli.rb', line 191
def initialize(args)
parsing_succeeded = parse(args)
self.class.abort_with_usage unless parsing_succeeded
end
|
Class Method Details
.abort_with_usage ⇒ Object
.about(description = nil) ⇒ Object
153
154
155
156
|
# File 'lib/tweetwine/cli.rb', line 153
def about(description = nil)
return @about unless description
@about = description.chomp
end
|
.inherited(child) ⇒ Object
145
146
147
148
149
150
151
|
# File 'lib/tweetwine/cli.rb', line 145
def inherited(child)
child.instance_eval do
@about, @name, @usage = nil
end
end
|
.name ⇒ Object
163
164
165
|
# File 'lib/tweetwine/cli.rb', line 163
def name
@name
end
|
.register(*names) ⇒ Object
158
159
160
161
|
# File 'lib/tweetwine/cli.rb', line 158
def register(*names)
@name = names.first
CLI.register_command(self, names)
end
|
.show_usage(about_cmd = self) ⇒ Object
173
174
175
176
177
178
179
180
181
182
183
|
# File 'lib/tweetwine/cli.rb', line 173
def show_usage(about_cmd = self)
about = about_cmd.about
name = about_cmd.name
usage = about_cmd.usage
result = <<-END
#{about}
Usage: #{CLI::EXEC_NAME} #{name} #{usage}
END
CLI.ui.info result.strip!
end
|
.usage(description = nil) ⇒ Object
Usage description for the command, use if overriding #parse.
168
169
170
171
|
# File 'lib/tweetwine/cli.rb', line 168
def usage(description = nil)
return @usage unless description
@usage = description
end
|
Instance Method Details
#parse(args) ⇒ Object
Default behavior, which succeeds always; override for real argument parsing if the command needs arguments.
198
199
200
|
# File 'lib/tweetwine/cli.rb', line 198
def parse(args)
true
end
|