vmc-ng/lib/vmc/cli.rb in vmc-0.4.0.beta.36 vs vmc-ng/lib/vmc/cli.rb in vmc-0.4.0.beta.37

- old
+ new

@@ -38,34 +38,34 @@ option :verbose, :alias => "-V", :type => :boolean, :desc => "Print extra information" option(:force, :alias => "-f", :type => :boolean, :desc => "Skip interaction when possible") { - option(:script) + input[:script] } option(:quiet, :alias => "-q", :type => :boolean, :desc => "Simplify output format") { - option(:script) + input[:script] } option(:script, :type => :boolean, :desc => "Shortcut for --quiet and --force") { !$stdout.tty? } option(:color, :type => :boolean, :default => true, :desc => "Use colorful output") { - !option(:quiet) + !input[:quiet] } option :trace, :alias => "-t", :type => :boolean, :desc => "Show API requests and responses" def default_action - if option(:version) + if input[:version] line "vmc #{VERSION}" else super end end @@ -88,15 +88,15 @@ unless client.current_space fail "Please select a space with 'vmc target -i'." end end - def execute(cmd, argv) - if option(:help) + def run(name) + if input[:help] invoke :help, :command => cmd.name.to_s else - cmd.context.new.precondition if cmd.context <= CLI + precondition super end rescue Interrupt exit_status 130 rescue Mothership::Error @@ -151,23 +151,23 @@ end end end def quiet? - option(:quiet) + input[:quiet] end def force? - option(:force) + input[:force] end def color_enabled? - option(:color) + input[:color] end def verbose? - option(:verbose) + input[:verbose] end def err(msg, status = 1) if quiet? $stderr.puts(msg) @@ -242,12 +242,12 @@ else {} end end - def target_info - info = targets_info[client_target] + def target_info(target = client_target) + info = targets_info[target] if info.is_a? String { :token => info } else info || {} @@ -260,19 +260,19 @@ File.open(File.expand_path(VMC::TOKENS_FILE), "w") do |io| YAML.dump(ts, io) end end - def save_target_info(info) + def save_target_info(info, target = client_target) ts = targets_info - ts[client_target] = info + ts[target] = info save_targets(ts) end - def remove_target_info + def remove_target_info(target = client_target) ts = targets_info - ts.delete client_target + ts.delete target save_targets(ts) end def no_v2 fail "Not implemented for v2." if v2? @@ -285,37 +285,37 @@ def invalidate_client @@client = nil client end - def client + def client(target = client_target) return @@client if defined?(@@client) && @@client - info = target_info + info = target_info(target) @@client = case info[:version] when 2 - CFoundry::V2::Client.new(client_target, info[:token]) + CFoundry::V2::Client.new(target, info[:token]) when 1 - CFoundry::V1::Client.new(client_target, info[:token]) + CFoundry::V1::Client.new(target, info[:token]) else - CFoundry::Client.new(client_target, info[:token]) + CFoundry::Client.new(target, info[:token]) end - @@client.proxy = option(:proxy) - @@client.trace = option(:trace) + @@client.proxy = input[:proxy] + @@client.trace = input[:trace] unless info.key? :version info[:version] = case @@client when CFoundry::V2::Client 2 else 1 end - save_target_info(info) + save_target_info(info, target) end if org = info[:organization] @@client.current_organization = @@client.organization(org) end