shaft 0.8 → 0.8.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/bin/shaft +40 -23
  2. data/lib/shaft/version.rb +1 -1
  3. metadata +2 -2
data/bin/shaft CHANGED
@@ -12,6 +12,7 @@ class ShaftCLI < Thor
12
12
 
13
13
  map "-h" => :help
14
14
  map "-l" => :active
15
+ map :status => :active
15
16
 
16
17
  desc "active", "Lists active tunnels"
17
18
  method_options %w( short -s ) => :boolean
@@ -85,31 +86,17 @@ class ShaftCLI < Thor
85
86
  end
86
87
  end
87
88
 
88
- desc "stop [NAME]", "Stops a tunnel"
89
- method_options :name => :string
90
- def stop(name)
91
- active = get_active
92
- if active.has_key?(name)
93
- say "Stopping tunnel '#{name}' at pid #{active[name]}..."
94
- begin
95
- Process.kill "INT", active[name]
96
- rescue Errno::ESRCH
97
- say "Tunnel wasn't active (zombie shaft item)."
98
- end
99
-
100
- # verify killing
101
- tunnel = get_tunnel(name)
102
- if local_port_used?(tunnel['bind']['client-port'])
103
- error "Could not stop tunnel process!"
104
- else
105
- say "Stopped."
106
-
107
- # set as inactive
108
- active.delete(name)
109
- set_active(active)
89
+ desc "stop [NAME] [--all]", "Stops a tunnel"
90
+ method_option :name => :string, :required => false
91
+ option :all, :type => :boolean
92
+ def stop(name="")
93
+ if options[:all]
94
+ get_active.each_key do |tunnel|
95
+ _stop(tunnel)
110
96
  end
97
+ say "Done stopping all tunnels."
111
98
  else
112
- error "Tunnel '#{name}' does not seem to be active!"
99
+ _stop(name)
113
100
  end
114
101
  end
115
102
 
@@ -120,6 +107,36 @@ class ShaftCLI < Thor
120
107
  end
121
108
 
122
109
  private
110
+ def _stop(name)
111
+ if name.length > 0
112
+ active = get_active
113
+ if name && active.has_key?(name)
114
+ say "Stopping tunnel '#{name}' at pid #{active[name]}..."
115
+ begin
116
+ Process.kill "INT", active[name]
117
+ rescue Errno::ESRCH
118
+ say "Tunnel wasn't active (zombie shaft item)."
119
+ end
120
+
121
+ # verify killing
122
+ tunnel = get_tunnel(name)
123
+ if local_port_used?(tunnel['bind']['client-port'])
124
+ error "Could not stop tunnel process!"
125
+ else
126
+ say "Stopped."
127
+
128
+ # set as inactive
129
+ active.delete(name)
130
+ set_active(active)
131
+ end
132
+ else
133
+ error "Tunnel '#{name}' does not seem to be active!"
134
+ end
135
+ else
136
+ error "Missing tunnel name!"
137
+ end
138
+ end
139
+
123
140
  def get_config
124
141
  @config ||= read_yaml(SHAFT_CONFIG)
125
142
  end
@@ -1,3 +1,3 @@
1
1
  module Shaft
2
- VERSION = "0.8"
2
+ VERSION = "0.8.5"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shaft
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.8'
4
+ version: 0.8.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-29 00:00:00.000000000 Z
12
+ date: 2013-04-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: thor