Skip to content

Instantly share code, notes, and snippets.

@ohadlevy
Created April 25, 2012 07:08
Show Gist options
  • Select an option

  • Save ohadlevy/2487628 to your computer and use it in GitHub Desktop.

Select an option

Save ohadlevy/2487628 to your computer and use it in GitHub Desktop.
class HammerCommand < Clamp::Command
ALLOWED_CONTENT_TYPES = %w[ json yaml text ]
option ["-d", "--debug"], :flag, "Output more information"
option ["-u", "--user"], "USER", "Foreman user"
option ["-p", "--pass"], "PASSWORD", "Foreman password"
option ["-s", "--server"], "URL", "Foreman Server URL", :default => "http://localhost/"
option "--format", "FORMAT", "Output format", :default => "json"
option "--version", :flag, "show version" do
puts "hammer-1.0.0"
exit(0)
end
private
def format= s
raise ArgumentError, "must be one of: #{ALLOWED_CONTENT_TYPES.join(', ')}" unless ALLOWED_CONTENT_TYPES.include?(s)
@format = s
end
end
class HostListCommand < HammerCommand
ALLOWED_CONTENT_TYPES = %w[ json yaml text something_else ]
def execute
ForemanResource::print_response(ForemanResource::get_collection('hosts', {:foreman_url => server, :foreman_user => user, :foreman_pass => pass, :debug => debug?}), format)
end
end
def SomeOtherCommand < HammerCommand
def format= s
# do something really diffferent here
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment