cli/lib/commands/rbld_rm.rb in rbld-1.3.7 vs cli/lib/commands/rbld_rm.rb in rbld-1.3.8

- old
+ new

@@ -1,14 +1,37 @@ module Rebuild::CLI class RbldRmCommand < Command def initialize - @usage = "[OPTIONS] [ENVIRONMENT[:TAG]]" - @description = "Remove local environment" + @usage = "[OPTIONS] [ENVIRONMENT[:TAG]]... -- COMMANDS" + @description = "Remove one or more local environments" + @options = [ + ["-f, --force", "force remove modified environments"] + ] end + def parse_opts(parameters) + replace_argv( parameters ) do + opts = GetoptLong.new([ '--force', '-f', GetoptLong::NO_ARGUMENT ]) + runopts = {} + opts.each do |opt, arg| + case opt + when '--force' + runopts[:force] = true + end + end + return runopts, ARGV + end + end + def run(parameters) - env = Environment.new( parameters[0] ) - rbld_log.info("Going to remove #{env}") - engine_api.remove!( env ) + runopts, parameters = parse_opts( parameters ) + raise EnvironmentNameEmpty unless parameters.any? + parameters.each do |parameter| + env = Environment.new( parameter ) + rbld_log.info("Going to checkout #{env} before removal") + engine_api.checkout!( env ) if runopts[:force] + rbld_log.info("Going to remove #{env}") + engine_api.remove!( env ) + end end end end