bin/shaft in shaft-0.8 vs bin/shaft in shaft-0.8.5

- old
+ new

@@ -10,10 +10,11 @@ class ShaftCLI < Thor include Thor::Actions map "-h" => :help map "-l" => :active + map :status => :active desc "active", "Lists active tunnels" method_options %w( short -s ) => :boolean def active active = get_active @@ -83,44 +84,60 @@ error "Tunnel '#{name}' not found!" end end end - desc "stop [NAME]", "Stops a tunnel" - method_options :name => :string - def stop(name) - active = get_active - if active.has_key?(name) - say "Stopping tunnel '#{name}' at pid #{active[name]}..." - begin - Process.kill "INT", active[name] - rescue Errno::ESRCH - say "Tunnel wasn't active (zombie shaft item)." + desc "stop [NAME] [--all]", "Stops a tunnel" + method_option :name => :string, :required => false + option :all, :type => :boolean + def stop(name="") + if options[:all] + get_active.each_key do |tunnel| + _stop(tunnel) end - - # verify killing - tunnel = get_tunnel(name) - if local_port_used?(tunnel['bind']['client-port']) - error "Could not stop tunnel process!" - else - say "Stopped." - - # set as inactive - active.delete(name) - set_active(active) - end + say "Done stopping all tunnels." else - error "Tunnel '#{name}' does not seem to be active!" + _stop(name) end end desc "restart [NAME]", "Restarts a tunnel" method_options :name => :string def restart(name) stop(name) && start(name) end private + def _stop(name) + if name.length > 0 + active = get_active + if name && active.has_key?(name) + say "Stopping tunnel '#{name}' at pid #{active[name]}..." + begin + Process.kill "INT", active[name] + rescue Errno::ESRCH + say "Tunnel wasn't active (zombie shaft item)." + end + + # verify killing + tunnel = get_tunnel(name) + if local_port_used?(tunnel['bind']['client-port']) + error "Could not stop tunnel process!" + else + say "Stopped." + + # set as inactive + active.delete(name) + set_active(active) + end + else + error "Tunnel '#{name}' does not seem to be active!" + end + else + error "Missing tunnel name!" + end + end + def get_config @config ||= read_yaml(SHAFT_CONFIG) end def get_active