docker-env 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/bin/docker-env +33 -7
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2236ba069cbf37b173d7c7bc7c9bc35edec96c61
4
- data.tar.gz: e704b52d70738ee3fbb6aa81c77088a2a453f60d
3
+ metadata.gz: 2f33b10f7bf7f70865735af1a5c528de04a581ff
4
+ data.tar.gz: 024670f80640a4a0dd8a46fb2e259cc406f8f60f
5
5
  SHA512:
6
- metadata.gz: e01e16356664b5ffbcb3ffc5a032b71ec3e5af17e43b81719c018971b7de7f1033da8e9a606d7ed0a927a662b1b073f30ff93608d7842219ae9ba2445adf3f3e
7
- data.tar.gz: 8af770816efb333a0b3366375414bb0d81f2836ec9c833a12754a8c2c19ad62ddac66fc15d5c6f1df05372c41d2a0e41b25576b7b99d19443a6349f49812f038
6
+ metadata.gz: f34ea507fef861db30f108dc7b9e6ad605db38334eb99e58a1ff92c3402034812a6c35cf27d09759578bee8145205973e9a0d1025f4fb57d04a020593e0eae48
7
+ data.tar.gz: b86aff6d07962278789af3eac68a2c7522dd18688884a7cf620391ca402924bed3e7faf71b7388dd8c18c9edb399543d0663cdd8fab641f0e95a77f51a1e9bcb
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.2.0
@@ -18,24 +18,50 @@ arguments :strict
18
18
  wrap_help_text :verbatim
19
19
 
20
20
  switch [:v, :verbose], desc: 'be more verbose'
21
+ switch [:k, :kill], desc: 'quit docker if it is running'
22
+ switch [:r, :restart], desc: 'stop and start docker around command'
21
23
 
22
24
  def current(options)
23
25
  f = File.readlink(SYMLINK)
24
26
  options[:verbose] ? f : f.split('.').last
25
27
  end
26
28
 
27
- def running?
28
- return unless `ps ax` =~ %r[/[D]ocker.app]
29
+ def tell_docker(what, options)
30
+ cmd = %[osascript -e 'tell application "Docker" to #{what}']
31
+ $stderr.puts cmd if options[:verbose]
32
+ system(cmd)
33
+ end
34
+
35
+ def check_running
36
+ `ps ax` =~ %r[/[D]ocker.app]
37
+ end
38
+
39
+ def running?(options)
40
+ active = check_running
41
+ tell_docker('quit', options) if active && (options[:kill] || options[:restart])
42
+
43
+ # wait for docker to quit
44
+ while check_running do
45
+ $stderr.putc '.' if options[:verbose]
46
+ sleep 1
47
+ end
48
+ $stderr.puts ''
49
+
50
+ return active unless check_running
29
51
 
30
52
  $stderr.puts 'Please quit Docker.app before using this script!'
31
53
  exit 1
32
54
  end
33
55
 
56
+ post do |global_options, _command, _options, _args|
57
+ tell_docker('activate', global_options) if global_options[:restart]
58
+ end
59
+
34
60
  desc 'setup by moving Docker.qcow2 to "image_name" and linking back'
35
61
  arg 'image_name'
36
62
  command :init do |c|
37
63
  c.action do |global_options, _options, args|
38
- running?
64
+ running?(global_options)
39
65
  if File.symlink?(SYMLINK)
40
66
  $stderr.puts "Already setup. Current is: #{current(global_options)}"
41
67
  exit 1
@@ -73,8 +99,8 @@ Removes current link so that the next time docker starts, it will create a
73
99
  create the symlink
74
100
  EOF
75
101
  command :new do |c|
76
- c.action do |_global_options, _options, _args|
77
- running?
102
+ c.action do |global_options, _options, _args|
103
+ running?(global_options)
78
104
  if File.exist?(SYMLINK) || !File.symlink?(SYMLINK)
79
105
  $stderr.puts "Please use '--force' to force delete current image!"
80
106
  exit 1
@@ -109,8 +135,8 @@ end
109
135
  desc 'Link to "image"'
110
136
  arg 'image'
111
137
  command :use do |c|
112
- c.action do |_global_options, _options, args|
113
- running?
138
+ c.action do |global_options, _options, args|
139
+ running?(global_options)
114
140
  file = "#{SYMLINK}.#{args[0]}"
115
141
  File.exist?(file) or raise "Image #{file} does not exist"
116
142
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docker-env
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rick Frankel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-26 00:00:00.000000000 Z
11
+ date: 2016-12-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake