On Friday, November 25, 2011 06:34:43 PM mzatko(a)redhat.com
wrote:
From: Maros Zatko <mzatko(a)redhat.com>
---
lib/aeolus_cli/command/config_parser.rb | 208
+++++++++++++++++-------------- 1 files changed, 114
insertions(+), 94
deletions(-)
diff --git a/lib/aeolus_cli/command/config_parser.rb
b/lib/aeolus_cli/command/config_parser.rb index 05e0ed4..f0a1748
100644
--- a/lib/aeolus_cli/command/config_parser.rb
+++ b/lib/aeolus_cli/command/config_parser.rb
@@ -25,7 +25,6 @@ module Aeolus
@args = argv
# Default options
@options = {}
- parse
end
def process
@@ -35,6 +34,7 @@ module Aeolus
# Eventually get the config file from user dir if it exists.
# File.expand_path("~")
if COMMANDS.include?(@command)
+ parse(@command)
self.send((a)command.to_sym)
else
@args << "-h"
@@ -44,7 +44,9 @@ module Aeolus
end
private
- def parse
+ def parse(subcommand = nil)
+ subcommand = subcommand.to_sym if subcommand
+
@optparse ||= OptionParser.new do|opts|
opts.banner = "Usage: aeolus-cli [#{COMMANDS.join('|')}]
[general options] [command options]"
@@ -70,114 +72,132 @@ module Aeolus
exit(0)
end
- opts.separator ""
- opts.separator "List options:"
- opts.on('-i', '--images', 'Retrieve a list of images')
do
- @options[:subcommand] = :images
- end
- opts.on('-b', '--builds ID', 'Retrieve the builds of an
image')
do |id| - @options[:subcommand] = :builds
- @options[:id] = id
- end
- opts.on('-t', '--targetimages ID', 'Retrieve the target
images
from a build') do |id| - @options[:subcommand] =
:targetimages
- @options[:id] = id
- end
- opts.on('-P', '--providerimages ID', 'Retrieve the
provider
images from a target image') do |id| -
@options[:subcommand] =
:providerimages
- @options[:id] = id
- end
- opts.on('-g', '--targets', 'Retrieve the values available
for
the --target parameter') do - @options[:subcommand] =
:targets
- end
- opts.on('-p', '--providers', 'Retrieve the values
available for
the --provider parameter') do - @options[:subcommand] =
:providers
- end
- opts.on('-a', '--accounts', 'Retrieve the values available
for
the --account parameter') do - @options[:subcommand] =
:accounts
+ if !subcommand || subcommand == :list
+ opts.separator ""
+ opts.separator "List options:"
+ opts.on('-i', '--images', 'Retrieve a list of
images') do
+ @options[:subcommand] = :images
+ end
+ opts.on('-b', '--builds ID', 'Retrieve the builds of an
image') do |id| + @options[:subcommand] = :builds
+ @options[:id] = id
+ end
+ opts.on('-t', '--targetimages ID', 'Retrieve the target
images
from a build') do |id| + @options[:subcommand] =
:targetimages
+ @options[:id] = id
+ end
+ opts.on('-P', '--providerimages ID', 'Retrieve the
provider
images from a target image') do |id| +
@options[:subcommand]
= :providerimages
+ @options[:id] = id
+ end
+ opts.on('-g', '--targets', 'Retrieve the values
available for
the --target parameter') do + @options[:subcommand] =
:targets
+ end
+ opts.on('-p', '--providers', 'Retrieve the values
available
for the --provider parameter') do +
@options[:subcommand] =
:providers
+ end
+ opts.on('-a', '--accounts', 'Retrieve the values
available for
the --account parameter') do + @options[:subcommand]
=
:accounts
+ end
end
- opts.separator ""
- opts.separator "Build options:"
- opts.on('-e', '--template FILE', 'path to file that
contains
template xml') do |file| - @options[:template] = file
- end
- opts.on('-z', '--no-validation', 'Do not validation the
template
against the TDL XML Schema') do |description| -
@options[:validation] = false
+ if !subcommand || subcommand == :build
+ opts.separator ""
+ opts.separator "Build options:"
+ opts.on('-e', '--template FILE', 'path to file that
contains
template xml') do |file| + @options[:template] = file
+ end
+ opts.on('-z', '--no-validation', 'Do not validation the
template against the TDL XML Schema') do |description| +
@options[:validation] = false
+ end
end
- opts.separator ""
- opts.separator "Push options:"
- opts.on('-B', '--build ID', 'push all target images for a
build,
to same providers as previously') do |id| - @options[:build]
=
id
- end
- opts.on('-t', '--targetimages ID', 'Retrieve the target
images
from a build') do |id| - @options[:targetimage] = id
- end
- opts.on('-A', '--account NAME', 'name of specific
provider
account to use for push') do |name| - @options[:account] =
name
+ if !subcommand || subcommand == :push
+ opts.separator ""
+ opts.separator "Push options:"
+ opts.on('-B', '--build ID', 'push all target images for
a
build, to same providers as previously') do |id| +
@options[:build] = id
+ end
+ opts.on('-t', '--targetimages ID', 'Retrieve the target
images
from a build') do |id| + @options[:targetimage] =
id
+ end
+ opts.on('-A', '--account NAME', 'name of specific
provider
account to use for push') do |name| + @options[:account]
=
name
+ end
end
- opts.separator ""
- opts.separator "Delete options:"
- opts.on('-I', '--image ID', 'delete build image and
associated
objects') do |id| - @options[:subcommand] = :image
- @options[:image] = id
- end
- opts.on('-B', '--build ID', 'delete build and associated
objects') do |id| - @options[:subcommand] = :build
- @options[:build] = id
- end
- opts.on('-m', '--targetimage ID', 'delete target image and
its
provider images') do |id| - @options[:subcommand] =
:target_image
- @options[:targetimage] = id
- end
- opts.on('-D', '--providerimage ID', 'delete provider
image')
do
|id| - @options[:subcommand] = :provider_image
- @options[:providerimage] = id
+ if !subcommand || subcommand == :delete
+ opts.separator ""
+ opts.separator "Delete options:"
+ opts.on('-I', '--image ID', 'delete build image and
associated
objects') do |id| + @options[:subcommand] = :image
+ @options[:image] = id
+ end
+ opts.on('-B', '--build ID', 'delete build and
associated
objects') do |id| + @options[:subcommand] = :build
+ @options[:build] = id
+ end
+ opts.on('-m', '--targetimage ID', 'delete target image
and
its
provider images') do |id| + @options[:subcommand] =
:target_image
+ @options[:targetimage] = id
+ end
+ opts.on('-D', '--providerimage ID', 'delete provider
image')
do |id| + @options[:subcommand] = :provider_image
+ @options[:providerimage] = id
+ end
end
opts.separator ""
opts.separator "URL with credentials to Conductor are set in
~/.aeolus-cli" opts.separator "Conductor URL should point to
https://<host_where_conductor_runs>/conductor/api"
- opts.separator ""
- opts.separator "List Examples:"
- opts.separator "aeolus-cli list --images #
list available images" - opts.separator "aeolus-cli list --builds
$image_id # list the builds of an image" -
opts.separator "aeolus-cli list --targetimages $build_id # list the
target images from a build" - opts.separator "aeolus-cli list
--providerimages $target_id # list the provider images from a
target
image" - opts.separator "aeolus-cli list --targets
# list the values available for the --target parameter" -
opts.separator "aeolus-cli list --providers # list the
values available for the --provider parameter" -
opts.separator
"aeolus-cli list --accounts # list the values
available
for the --account parameter" + if !subcommand ||
subcommand ==
:list
+ opts.separator ""
+ opts.separator "List Examples:"
+ opts.separator "aeolus-cli list --images #
list available images" + opts.separator "aeolus-cli list
--builds $image_id # list the builds of an image" +
opts.separator "aeolus-cli list --targetimages $build_id # list the
target images from a build" + opts.separator "aeolus-cli list
--providerimages $target_id # list the provider images from a
target
image" + opts.separator "aeolus-cli list
--targets
# list the values available for the --target parameter" +
opts.separator "aeolus-cli list --providers # list the
values available for the --provider parameter" +
opts.separator
"aeolus-cli list --accounts # list the values
available
for the --account parameter" + end
- opts.separator ""
- opts.separator "Build examples:"
- opts.separator "aeolus-cli build --target ec2 --template
my.tmpl
# build a new image for ec2 from based on the given
template" -
opts.separator "aeolus-cli build --target ec2,rhevm
--template
my.tmpl # build a new image for ec2 and for rhevm based on the
given
template" - #opts.separator "aeolus-cli build
--image
$image_id
# (NOT IMPLEMENTED) rebuild the image template and
targets
from latest build" - #opts.separator %q{aeolus-cli
build --
target
ec2,rackspace \ # rebuild the image with a new template and
set of
targets - # --image $image_i \
- # --template my.tmpl}
+ if !subcommand || subcommand == :build
+ opts.separator ""
+ opts.separator "Build examples:"
+ opts.separator "aeolus-cli build --target ec2 --template
my.tmpl # build a new image for ec2 from based on the given
template" + opts.separator "aeolus-cli build --target
ec2,rhevm
--template my.tmpl # build a new image for ec2 and for rhevm
based on the
given template" + #opts.separator "aeolus-cli
build --image
$image_id # (NOT IMPLEMENTED) rebuild the image
template
and targets from latest build" + #opts.separator
%q{aeolus-cli
build --target ec2,rackspace \ # rebuild the image with a
new
template and set of targets + # --image $image_i \
+ # --template my.tmpl}
+ end
- opts.separator ""
- opts.separator "Push examples:"
- opts.separator "aeolus-cli push --account
ec2-account,ec2-account2 --targetimage $target_image_id #
Push target
images to each of the specified account" -
opts.separator
"aeolus-cli push --account ec2-account,rhevm-account --build
$build_id
# Push target images attached to a particular build to each
of
the specified accounts" - opts.separator
"aeolus-cli push
--account ec2-account,rhevm-account --image $image_id
# Push
target images attached to a particular image to each of the
specified
accounts" + if !subcommand || subcommand == :push
+ opts.separator ""
+ opts.separator "Push examples:"
+ opts.separator "aeolus-cli push --account
ec2-account,ec2-account2 --targetimage $target_image_id #
Push target
images to each of the specified account" +
opts.separator
"aeolus-cli push --account ec2-account,rhevm-account --build
$build_id
# Push target images attached to a particular build to each
of
the specified accounts" + opts.separator
"aeolus-cli push
--account ec2-account,rhevm-account --image $image_id
# Push
target images attached to a particular image to each of the
specified
accounts" + end
- opts.separator ""
- opts.separator "Import examples:"
- opts.separator "aeolus-cli import --provider ec2-us-east-1
--target ec2 --id $ami_id # import an AMI from the specified
provider" -
opts.separator "aeolus-cli import --provider
ec2-us-east-1 --
target
ec2 --id $ami_id --description '<image><name>My
Image</name></image>' #
import an AMI from the specified provider" -
opts.separator
"aeolus-cli import --provider ec2-us-east-1 --target ec2 --id
$ami_id
--description <path_to_xml_file> # import an AMI from the
specified
provider" + if !subcommand || subcommand == :import
+ opts.separator ""
+ opts.separator "Import examples:"
+ opts.separator "aeolus-cli import --provider ec2-us-east-1
--target ec2 --id $ami_id # import an AMI from the specified
provider" +
opts.separator "aeolus-cli import --provider
ec2-us-east-1
--target ec2 --id $ami_id --description '<image><name>My
Image</name></image>' # import an AMI from the specified
provider" +
opts.separator "aeolus-cli import --provider ec2-us-east-1
--
target
ec2 --id $ami_id --description <path_to_xml_file> # import an
AMI
from the
specified provider" + end
- opts.separator ""
- opts.separator "Delete examples: (DELETE CURRENTLY NOT
IMPLEMENTED) " - opts.separator "aeolus-cli delete --image
$image_id # deletes a image and all associated builds" -
opts.separator "aeolus-cli delete --build $build_id #
deletes a build and all associated targetimages" -
opts.separator
"aeolus-cli delete --targetimage $target_image # deletes a
target
image and all associated provider images" -
opts.separator
"aeolus-cli delete --providerimage $provider_image # deletes a
provider
image" + if !subcommand || subcommand == :delete
+ opts.separator ""
+ opts.separator "Delete examples: (DELETE CURRENTLY
NOT
IMPLEMENTED) " + opts.separator "aeolus-cli
delete --
image
$image_id # deletes a image and all associated
builds" +
opts.separator "aeolus-cli delete --build $build_id #
deletes a build and all associated targetimages" +
opts.separator "aeolus-cli delete --targetimage $target_image
#
deletes a target image and all associated provider images" +
opts.separator "aeolus-cli delete --providerimage $provider_image
#
deletes a provider image" + end
end
begin
I coworked on this with mzatko...
I will change tests to work with mzatko's work.
--
Petr Blaho