qb 0.1.50 → 0.1.51

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3d9c34a19d57f54943675da647f3cd7b5bcaf7c4
4
- data.tar.gz: 46160ea3fde30678adf3a5e602d72dcef823e34b
3
+ metadata.gz: 8354a2e7a722ed65253867f9ba61d18f32548c7e
4
+ data.tar.gz: c3b3a05ac92ff16657beb5e53c01e5d29ad3a43d
5
5
  SHA512:
6
- metadata.gz: f3372997b5606c548da8350f1769eac58880379f3715c394f50c11796beaa664d0948670c7e6c6441f2ef9c8d7b284b5b019d1bbc4d28fe0f76b07a386c0c29d
7
- data.tar.gz: b815260aaeed6ac5ee541f3ca1bc9867a622d74494f5c1da7ba9a56bbd7cf7adb69ecaf7f250b7d552a517a5c5eb250f4212120d52460fdf2b4c0f4d8b2586c4
6
+ metadata.gz: 7f22505b21269bc2b63b14cbb9c9dfddf16d9fd4a046dc797d1609adda79598d9ff6778eb7486bfccbd44e8e80dce046aaf91fdbdaa56b9092663c3c6e4fd1e4
7
+ data.tar.gz: '048192659773f4e26e6de355ffa1b32c9f5af7507bf4245adcfa3a6566ab7f80fbb70c4b965759997966c0a12ae923e541f9ad349f4f7c2a6e7ecf8f709d5c1b'
data/exe/qb CHANGED
@@ -160,7 +160,7 @@ def main args
160
160
  #
161
161
  # in some cases (like projects) the dir can be figured out in other ways:
162
162
  #
163
- QB.get_default_dir role, cwd, options
163
+ role.default_dir cwd, options
164
164
 
165
165
  when 1
166
166
  # there is a single positional arg, which is used as dir
@@ -320,6 +320,10 @@ def main args
320
320
  template << "-#{ 'v' * qb_options['verbose'] }"
321
321
  end
322
322
 
323
+ if qb_options['ask_vault_pass'] || role.ask_vault_pass?
324
+ template << "--ask-vault-pass"
325
+ end
326
+
323
327
  template << "<%= playbook_path %>"
324
328
 
325
329
  cmd = Cmds.sub template.join(" "), [], {
data/lib/qb.rb CHANGED
@@ -36,83 +36,6 @@ module QB
36
36
  $stderr.puts dumpObj.pretty_inspect
37
37
  end
38
38
 
39
- def self.get_default_dir role, cwd, options
40
- debug "get_default_dir", role: role,
41
- meta: role.meta,
42
- cwd: cwd,
43
- options: options
44
-
45
- key = 'default_dir'
46
- value = role.meta[key]
47
- case value
48
- when nil
49
- # there is no get_dir info in meta/qb.yml, can't get the dir
50
- raise "unable to infer default directory: no '#{ key }' key in meta/qb.yml"
51
-
52
- when false
53
- # this method should not get called when the value is false (an entire
54
- # section is skipped in exe/qb when `default_dir = false`)
55
- raise "role does not use default directory (meta/qb.yml:default_dir = false)"
56
-
57
- when 'git_root'
58
- debug "returning the git root relative to cwd"
59
- NRSER.git_root cwd
60
-
61
- when 'cwd'
62
- debug "returning current working directory"
63
- cwd
64
-
65
- when Hash
66
- debug "qb meta option is a Hash"
67
-
68
- unless value.length == 1
69
- raise "#{ role.meta_path.to_s }:default_dir invalid: #{ value.inspect }"
70
- end
71
-
72
- hash_key, hash_value = value.first
73
-
74
- case hash_key
75
- when 'exe'
76
- exe_path = hash_value
77
-
78
- # supply the options to the exe so it can make work off those values
79
- # if it wants.
80
- exe_input_data = Hash[
81
- options.map {|option|
82
- [option.cli_option_name, option.value]
83
- }
84
- ]
85
-
86
- unless exe_path.start_with?('~') || exe_path.start_with?('/')
87
- exe_path = File.join(role.path, exe_path)
88
- debug 'exe path is relative, basing off role dir', exe_path: exe_path
89
- end
90
-
91
- debug "found 'exe' key, calling", exe_path: exe_path,
92
- exe_input_data: exe_input_data
93
-
94
- Cmds.chomp! exe_path do
95
- JSON.dump exe_input_data
96
- end
97
-
98
- when 'find_up'
99
- filename = hash_value
100
-
101
- unless filename.is_a? String
102
- raise "find_up filename must be string, found #{ filename.inspect }"
103
- end
104
-
105
- debug "found 'find_up', looking for file named #{ filename }"
106
-
107
- Util.find_up filename
108
-
109
- else
110
- raise "bad key: #{ hash_key } in #{ role.meta_path.to_s }:default_dir"
111
-
112
- end
113
- end
114
- end # get_default_dir
115
-
116
39
  def self.check_ansible_version
117
40
  out = Cmds.out! 'ansible --version'
118
41
  version_str = out[/ansible\ ([\d\.]+)/, 1]
@@ -23,10 +23,34 @@ module QB
23
23
  class MetadataError < Error
24
24
  end
25
25
 
26
+ # turn a name into a "command line" version by replacing underscores with
27
+ # dashes.
28
+ #
29
+ # @param [String] option_name
30
+ # the input option name.
31
+ #
32
+ # @return [String]
33
+ # the CLI-ized name.
34
+ #
35
+ # @example
36
+ # QB::Options.cli_ize_name "my_var" # => "my-var"
37
+ #
26
38
  def self.cli_ize_name option_name
27
39
  option_name.gsub '_', '-'
28
40
  end
29
41
 
42
+ # turn a name into a "ruby / ansible variable" version by replacing
43
+ # dashes with underscores.
44
+ #
45
+ # @param [String] option_name
46
+ # the input option name.
47
+ #
48
+ # @return [String]
49
+ # the ruby / ansible var-ized name.
50
+ #
51
+ # @example
52
+ # QB::Options.cli_ize_name "my-var" # => "my_var"
53
+ #
30
54
  def self.var_ize_name option_name
31
55
  option_name.gsub '-', '_'
32
56
  end
@@ -156,6 +180,25 @@ module QB
156
180
  end # each var
157
181
  end # add
158
182
 
183
+ # destructively removes options from `args` and populates hashes of
184
+ # role-specific options and general qb ones.
185
+ #
186
+ # @param [QB::Role] role
187
+ # the role to parse the options for.
188
+ #
189
+ # @param [Array<String>] args
190
+ # CLI args -- `ARGV` with the role arg shifted off.
191
+ #
192
+ # @return [Array<Hash<String, Option|Object>>]
193
+ # a two-element array:
194
+ #
195
+ # 1. the options for the role, hash of Option#cli_name to Option
196
+ # instances.
197
+ #
198
+ # 2. the general qb options, hash of String key to option values.
199
+ #
200
+ # @raise if bad options are found.
201
+ #
159
202
  def self.parse! role, args
160
203
  role_options = {}
161
204
 
@@ -246,6 +289,13 @@ module QB
246
289
  qb_options['run'] = false
247
290
  end
248
291
 
292
+ opts.on(
293
+ '--ASK-VAULT-PASS',
294
+ "ask for the vault password.",
295
+ ) do |value|
296
+ qb_options['ask_vault_pass'] = true
297
+ end
298
+
249
299
  add opts, role_options, role
250
300
 
251
301
  opts.on_tail("-h", "--help", "Show this message") do
@@ -481,6 +481,98 @@ module QB
481
481
  puts "\n" + format_examples + "\n"
482
482
  end
483
483
 
484
+ # should qb ask for an ansible vault password?
485
+ #
486
+ # @see http://docs.ansible.com/ansible/playbooks_vault.html
487
+ #
488
+ # @return [Boolean]
489
+ # `true` if qb should ask for a vault password.
490
+ #
491
+ def ask_vault_pass?
492
+ !!@meta['ask_vault_pass']
493
+ end
494
+
495
+ # gets the default `qb_dir` value, raising an error if the role doesn't
496
+ # define how to get one or there is a problem getting it.
497
+ #
498
+ #
499
+ def default_dir cwd, options
500
+ debug "get_default_dir", role: self,
501
+ meta: self.meta,
502
+ cwd: cwd,
503
+ options: options
504
+
505
+ key = 'default_dir'
506
+ value = self.meta[key]
507
+ case value
508
+ when nil
509
+ # there is no get_dir info in meta/qb.yml, can't get the dir
510
+ raise "unable to infer default directory: no '#{ key }' key in meta/qb.yml"
511
+
512
+ when false
513
+ # this method should not get called when the value is false (an entire
514
+ # section is skipped in exe/qb when `default_dir = false`)
515
+ raise "role does not use default directory (meta/qb.yml:default_dir = false)"
516
+
517
+ when 'git_root'
518
+ debug "returning the git root relative to cwd"
519
+ NRSER.git_root cwd
520
+
521
+ when 'cwd'
522
+ debug "returning current working directory"
523
+ cwd
524
+
525
+ when Hash
526
+ debug "qb meta option is a Hash"
527
+
528
+ unless value.length == 1
529
+ raise "#{ meta_path.to_s }:default_dir invalid: #{ value.inspect }"
530
+ end
531
+
532
+ hash_key, hash_value = value.first
533
+
534
+ case hash_key
535
+ when 'exe'
536
+ exe_path = hash_value
537
+
538
+ # supply the options to the exe so it can make work off those values
539
+ # if it wants.
540
+ exe_input_data = Hash[
541
+ options.map {|option|
542
+ [option.cli_option_name, option.value]
543
+ }
544
+ ]
545
+
546
+ unless exe_path.start_with?('~') || exe_path.start_with?('/')
547
+ exe_path = File.join(self.path, exe_path)
548
+ debug 'exe path is relative, basing off role dir', exe_path: exe_path
549
+ end
550
+
551
+ debug "found 'exe' key, calling", exe_path: exe_path,
552
+ exe_input_data: exe_input_data
553
+
554
+ Cmds.chomp! exe_path do
555
+ JSON.dump exe_input_data
556
+ end
557
+
558
+ when 'find_up'
559
+ filename = hash_value
560
+
561
+ unless filename.is_a? String
562
+ raise "find_up filename must be string, found #{ filename.inspect }"
563
+ end
564
+
565
+ debug "found 'find_up', looking for file named #{ filename }"
566
+
567
+ QB::Util.find_up filename
568
+
569
+ else
570
+ raise "bad key: #{ hash_key } in #{ self.meta_path.to_s }:default_dir"
571
+
572
+ end
573
+ end
574
+ end # default_dir
575
+
484
576
  private
485
577
 
486
578
  # get the value at the first found of the keys or the default.
@@ -1,7 +1,7 @@
1
1
  module QB
2
2
  GEM_NAME = 'qb'
3
3
 
4
- VERSION = "0.1.50"
4
+ VERSION = "0.1.51"
5
5
 
6
6
  def self.gemspec
7
7
  Gem.loaded_specs[GEM_NAME]
@@ -42,6 +42,9 @@ default_user: null
42
42
  # set to false to not save options in .qb-options.yml files
43
43
  save_options: true
44
44
 
45
+ # ask for an ansible vault password
46
+ ask_vault_pass: false
47
+
45
48
  options: []
46
49
  # - name: example
47
50
  # description: an example of a variable.
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.50
4
+ version: 0.1.51
5
5
  platform: ruby
6
6
  authors:
7
7
  - nrser
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-03-17 00:00:00.000000000 Z
11
+ date: 2017-03-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler