Created
January 26, 2012 17:14
-
-
Save jorgenpt/1683864 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Jenkins::Model | |
class CLICommand | |
def self.short_description(short_description = nil) | |
@short_description = short_description if short_description | |
@short_description | |
end | |
def short_description | |
@@short_description | |
end | |
def parse(args) | |
@slop.parse(args) | |
end | |
def run | |
end | |
def usage | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'core_ext/exception' | |
module Jenkins | |
class Plugin | |
class Proxies | |
class CLICommand < Java.hudson.cli.CLICommand | |
# this module makes this class act as a proxy | |
include Jenkins::Plugin::Proxy | |
# when the glue layer needs to create a wrapper, it calls this constructor | |
# plugin refers to the Ruby plugin object, and the 'object' parameter | |
# refers to JM::CLICommand that it's wrapping. | |
def initialize(plugin, object) | |
super(plugin, object) | |
end | |
def getShortDescription | |
@object.short_description | |
end | |
# main(List<String> args, Locale locale, InputStream stdin, PrintStream stdout, PrintStream stderr) | |
def main(args, locale, stdin, stdout, stderr) | |
old_in, old_out, old_err = $stdin, $stdout, $stderr | |
ret = -1 | |
begin | |
$stdin, $stdout, $stderr = stdin, stdout, stderr | |
@object.parse(args) | |
ret = @object.run ? 0 : -1 | |
rescue InvalidOptionError, MissingOptionError | |
$stderr.puts $!.message | |
$stderr.puts @object.short_description | |
$stderr.puts @object.usage | |
rescue | |
$stderr.puts $!.full_message | |
ensure | |
$stdin, $stdout, $stderr = old_in, old_out, old_err | |
end | |
end | |
end | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class StreamEventsCommand | |
include Jenkins::Model::CLI::Command | |
args do | |
banner "stream-events [options]\n" | |
on :format=, 'JSON or XML' | |
on :v, :verbose, 'Enable verbose mode' | |
end | |
def run(opts) | |
puts "Woo!" if opts.verbose? | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment