From: Martyn Taylor mtaylor@redhat.com
--- .../aeolus-image/lib/config_parser.rb | 9 ++++++++- .../image_factory/aeolus-image/lib/list_command.rb | 5 +++++ .../aeolus-image/spec/config_parser_spec.rb | 14 +++++++++++++- .../aeolus-image/spec/list_command_spec.rb | 17 +++++++++++++++++ 4 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 services/image_factory/aeolus-image/spec/list_command_spec.rb
diff --git a/services/image_factory/aeolus-image/lib/config_parser.rb b/services/image_factory/aeolus-image/lib/config_parser.rb index 3ee8b1e..b59a723 100644 --- a/services/image_factory/aeolus-image/lib/config_parser.rb +++ b/services/image_factory/aeolus-image/lib/config_parser.rb @@ -171,7 +171,14 @@ module Aeolus # For the list example above, that object would call a method 'images' based on the item # @options[:subcommand] being :images, so internally that class may do something like: # self.send(@options[:subcommand]) - "Not implemented" + if @options[:subcommand].nil? + # TODO: Pull out Print Usage into seporate method, and print + puts "Could not find subcommand for list, run `./aeolus-image --help` for usage instructions" + exit(0) + else + list_command = ListCommand.new(@options) + list_command.send(@options[:subcommand]) + end end
def build diff --git a/services/image_factory/aeolus-image/lib/list_command.rb b/services/image_factory/aeolus-image/lib/list_command.rb index 35f6927..9939f74 100644 --- a/services/image_factory/aeolus-image/lib/list_command.rb +++ b/services/image_factory/aeolus-image/lib/list_command.rb @@ -4,6 +4,11 @@ module Aeolus def initialize(opts={}, logger=nil) super(opts, logger) end + + def images + doc = Nokogiri::XML iwhd['/images'].get + doc.xpath("/objects/object/key").collect { |node| "uuid: " + node.text } + end end end end diff --git a/services/image_factory/aeolus-image/spec/config_parser_spec.rb b/services/image_factory/aeolus-image/spec/config_parser_spec.rb index e923345..7473add 100644 --- a/services/image_factory/aeolus-image/spec/config_parser_spec.rb +++ b/services/image_factory/aeolus-image/spec/config_parser_spec.rb @@ -4,11 +4,23 @@ module Aeolus module Image describe ConfigParser do it "should parse the specified command" do - config_parser = ConfigParser.new(%w(list)) + config_parser = ConfigParser.new(%w(list --images)) config_parser.process config_parser.command.should == 'list' end
+ it "should exit gracefully when a required subcommand is not provided" do + begin + silence_stream(STDOUT) do + config_parser = ConfigParser.new(%w(list)) + config_parser.process + config_parser.should_receive(:exit).with(0) + end + rescue SystemExit => e + e.status.should == 0 + end + end + it "should notify the user of an invalid command" do config_parser = ConfigParser.new(%w(sparkle)) config_parser.should_receive(:exit).with(0) diff --git a/services/image_factory/aeolus-image/spec/list_command_spec.rb b/services/image_factory/aeolus-image/spec/list_command_spec.rb new file mode 100644 index 0000000..1f47b47 --- /dev/null +++ b/services/image_factory/aeolus-image/spec/list_command_spec.rb @@ -0,0 +1,17 @@ +require 'spec_helper' + +module Aeolus + module Image + describe ListCommand do + it "should return a list of images" do + regexp = Regexp.new('[uuid:\s][\w]{8}[-][\w]{4}[-][\w]{4}[-][\w]{4}[-][\w]{12}') + listc = ListCommand.new(:subcommand => 'images') + images = listc.images + images.each do |image| + regexp.match(image.to_s).should_not == nil + end + end + + end + end +end \ No newline at end of file
aeolus-devel@lists.fedorahosted.org