hoodoo 2.1.1 → 2.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fcb6260d51d3dd934b17047fa2db6abe3b9dc25f7f95f81be5bd0af5035ff019
4
- data.tar.gz: 97f48231ab533c2aec1557679007d7ea95f5e10c0aeb262cc8a1c84d2bf611ae
3
+ metadata.gz: 27c91b7d6239a85430ddf6e2cb47e0461775375e6f4b1969c6bbbf9017a41243
4
+ data.tar.gz: 3808aceb6a8474d1c456d25b38aa5a280df7c6da547747f1a54cce3b57bbe1ab
5
5
  SHA512:
6
- metadata.gz: 30633c2155b09f06ac6d75c53aef460b4c04b426019a11eb9bb08040ece7586295b875ec8f3034c87e3e4a80945c1ebd0514444f2437bccef3049cbf5b616080
7
- data.tar.gz: f12b6ba55fd0ad9a8f7f66e1e6924a98cbbba2eed5999cf8b14a6810c15529bff0eaf5d2fe472b5d757e15bd5877baba9724e88caab2af846a2e6394b3ecd2ae
6
+ metadata.gz: 35bea308563fef3c91d9f5f015942b3a03a198a299a18f754079d8ed1319cfc7da10165deee81d356064bcf1f479e5d20958807b9a7f90a998a3d288291d25b0
7
+ data.tar.gz: 072047f7dc3c8deccb4a034de3bd793149909e99107455125313ae92f4ce85b059cf90b11ad3587af4b85a86c2199f235180f592b54bded4891ebc97a0802f4e
data/bin/hoodoo CHANGED
@@ -2,4 +2,4 @@
2
2
  $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
3
3
  require 'hoodoo/generator'
4
4
 
5
- exit Hoodoo::Generator.instance.run!(ARGV)
5
+ exit Hoodoo::Generator.instance.run!
@@ -11,6 +11,7 @@
11
11
  require 'singleton'
12
12
  require 'fileutils'
13
13
  require 'pathname'
14
+ require 'getoptlong'
14
15
 
15
16
  module Hoodoo
16
17
 
@@ -36,26 +37,58 @@ module Hoodoo
36
37
  #
37
38
  NAME_REGEX = /^[a-zA-Z01-9_-]{2,30}$/
38
39
 
39
- # Run the +hoodoo+ command implementation.
40
+ # Run the +hoodoo+ command implementation. Command line options are
41
+ # taken from the Ruby ARGV constant.
40
42
  #
41
- # +args+:: Array of command line arguments, excluding the +hoodoo+
42
- # command itself (so, just any extra arguments passed in).
43
- #
44
- def run!( args )
45
- return show_usage if args_empty?(args)
43
+ def run!
44
+ git = nil
45
+ path = nil
46
+
47
+ return show_usage() if ARGV.length < 1
48
+ name = ARGV.shift() if ARGV.first[ 0 ] != '-'
49
+
50
+ opts = GetoptLong.new(
51
+ [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
52
+ [ '--version', '-v', '-V', GetoptLong::NO_ARGUMENT ],
53
+ [ '--path', '-p', GetoptLong::REQUIRED_ARGUMENT ],
54
+ [ '--from', '-f', GetoptLong::REQUIRED_ARGUMENT ],
55
+ [ '--git', '-g', GetoptLong::REQUIRED_ARGUMENT ],
56
+ )
57
+
58
+ silence_stream( $stderr ) do
59
+ begin
60
+ opts.each do | opt, arg |
61
+ case opt
62
+ when '--help'
63
+ return show_usage()
64
+ when '--version'
65
+ return show_version()
66
+ when '--path'
67
+ path = arg
68
+ when '--from', '--git'
69
+ git = arg
70
+ end
71
+ end
72
+
73
+ rescue GetoptLong::InvalidOption, GetoptLong::MissingArgument => e
74
+ return usage_and_warning( e.message )
75
+
76
+ end
77
+ end
78
+
79
+ unless path.nil? || git.nil?
80
+ return usage_and_warning( 'Use the --path OR --from arguments, but not both' )
81
+ end
46
82
 
47
- name = args.first
83
+ git ||= 'git@github.com:LoyaltyNZ/service_shell.git'
48
84
 
49
- return show_usage if name == '-h' || name == '--help' || name.nil? || name.empty?
50
- return show_version if name == '-v' || name == '--version'
85
+ name = ARGV.shift() if name.nil?
86
+ return show_usage() if name.nil?
51
87
 
88
+ return usage_and_warning( "Unexpected extra arguments were given" ) if ARGV.count > 0
52
89
  return usage_and_warning( "SERVICE_NAME must match #{ NAME_REGEX.inspect }" ) if naughty_name?( name )
53
90
  return usage_and_warning( "'#{ name }' already exists" ) if File.exist?( "./#{ name }" )
54
91
 
55
- path = args[ 2 ] if args[ 1 ] == '--path'
56
- git = args[ 2 ] if args[ 1 ] == '--from'
57
- git ||= 'git@github.com:LoyaltyNZ/service_shell.git'
58
-
59
92
  return create_service( name, git, path )
60
93
  end
61
94
 
@@ -143,7 +176,7 @@ module Hoodoo
143
176
  puts
144
177
  puts "Creates a service shell at the PWD, customised with the given service name."
145
178
  puts
146
- puts " hoodoo <service-name> [--from <git-repository> | --path <full-pathname>]"
179
+ puts " hoodoo <service-name> [--from <git-repository> OR --path <full-pathname>]"
147
180
  puts
148
181
  puts "For example:"
149
182
  puts
@@ -151,7 +184,8 @@ module Hoodoo
151
184
  puts " hoodoo service_person --from git@github.com:YOURNAME/service_shell_fork.git"
152
185
  puts " hoodoo service_product --path /path/to/local/service/shell/container"
153
186
  puts
154
- puts "See also:"
187
+ puts "The '--from' option is aliased as '--git'. All options have single letter"
188
+ puts "equivalents. See also:"
155
189
  puts
156
190
  puts " hoodoo --help shows this help"
157
191
  puts " hoodoo --version shows the require-able gem version"
@@ -171,9 +205,27 @@ module Hoodoo
171
205
  end
172
206
 
173
207
  def usage_and_warning( warning )
174
- puts "WARNING: #{warning}"
175
208
  puts
176
- show_usage
209
+ puts "-" * 80
210
+ puts "WARNING: #{warning}"
211
+ puts "-" * 80
212
+
213
+ return show_usage()
214
+ end
215
+
216
+ def silence_stream( stream, &block )
217
+ begin
218
+ old_stream = stream.dup
219
+ stream.reopen( File::NULL )
220
+ stream.sync = true
221
+
222
+ yield
223
+
224
+ ensure
225
+ stream.reopen( old_stream )
226
+ old_stream.close
227
+
228
+ end
177
229
  end
178
230
  end
179
231
  end
@@ -12,11 +12,11 @@ module Hoodoo
12
12
  # The Hoodoo gem version. If this changes, be sure to re-run
13
13
  # <tt>bundle install</tt> or <tt>bundle update</tt>.
14
14
  #
15
- VERSION = '2.1.1'
15
+ VERSION = '2.1.2'
16
16
 
17
17
  # The Hoodoo gem date. If this changes, be sure to re-run
18
18
  # <tt>bundle install</tt> or <tt>bundle update</tt>.
19
19
  #
20
- DATE = '2017-11-03'
20
+ DATE = '2017-11-07'
21
21
 
22
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hoodoo
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.1
4
+ version: 2.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Loyalty New Zealand
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-03 00:00:00.000000000 Z
11
+ date: 2017-11-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dalli
@@ -526,7 +526,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
526
526
  version: '0'
527
527
  requirements: []
528
528
  rubyforge_project:
529
- rubygems_version: 2.7.0
529
+ rubygems_version: 2.7.1
530
530
  signing_key:
531
531
  specification_version: 4
532
532
  summary: Opinionated APIs