qb 0.1.47 → 0.1.48

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
  SHA1:
3
- metadata.gz: 63ae54569cf29beff79d801d32e28d243c959d3c
4
- data.tar.gz: c9d99ed1389b6b5fc370ac81b10fcca184e175cd
3
+ metadata.gz: 0eb9c603416537655809bf3a2147a55cd35e1833
4
+ data.tar.gz: f6c6ae61026428b672ee0dd61a01dddfddd492bc
5
5
  SHA512:
6
- metadata.gz: 366267848f33fecb1a8a8aa39119870db2d78dc91f009933f790b98bb13abbd0fd1e9a50b2b23d8478115ab4893553fd53b931d38b1d33eb5258a668552e297b
7
- data.tar.gz: d6a819e756d023cb6c0f6da18b1b5603419e650c856da23da124b86185afc41bd09ee375690153b81282f7b57b6982f9ca820646e27ea3be13253c4da7c4e193
6
+ metadata.gz: 65c50309bd1d3501a14228cced913d84351d8192df54b13f777d9e99c50fbabefd757d384c6bfdecfbe8b9725f60fc48b0d85a44660af08851a459cdd60a9b24
7
+ data.tar.gz: c719eb898d4fc602559396028dcd7fb6b98534b96645d718ccad76d40cbcd388dc11ddff24669ac385778c8db164f53b15be3f2f71a828c679eb1b5d54927cff
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --markup markdown
data/lib/qb.rb CHANGED
@@ -43,24 +43,40 @@ module QB
43
43
  options: options
44
44
 
45
45
  key = 'default_dir'
46
- case role.meta[key]
47
- when nil, false
46
+ value = role.meta[key]
47
+ case value
48
+ when nil
48
49
  # there is no get_dir info in meta/qb.yml, can't get the dir
49
50
  raise "unable to infer default directory: no '#{ key }' key in meta/qb.yml"
50
-
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
+
51
57
  when 'git_root'
52
58
  debug "returning the git root relative to cwd"
53
59
  NRSER.git_root cwd
54
60
 
55
61
  when 'cwd'
56
- debug "returing current working directory"
62
+ debug "returning current working directory"
57
63
  cwd
58
64
 
59
65
  when Hash
60
66
  debug "qb meta option is a Hash"
61
67
 
62
- if role.meta[key].key? 'exe'
63
- exe_path = role.meta[key]['exe']
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.
64
80
  exe_input_data = Hash[
65
81
  options.map {|option|
66
82
  [option.cli_option_name, option.value]
@@ -78,8 +94,21 @@ module QB
78
94
  Cmds.chomp! exe_path do
79
95
  JSON.dump exe_input_data
80
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
+
81
109
  else
82
- raise "not sure to process '#{ key }' in metea/qb.yml"
110
+ raise "bad key: #{ hash_key } in #{ role.meta_path.to_s }:default_dir"
111
+
83
112
  end
84
113
  end
85
114
  end # get_default_dir
data/lib/qb/options.rb CHANGED
@@ -250,6 +250,9 @@ module QB
250
250
 
251
251
  opts.on_tail("-h", "--help", "Show this message") do
252
252
  puts opts
253
+
254
+ role.puts_examples
255
+
253
256
  exit
254
257
  end
255
258
  end
data/lib/qb/role.rb CHANGED
@@ -3,9 +3,20 @@ require 'cmds'
3
3
  require 'parseconfig'
4
4
 
5
5
  module QB
6
+ # contains info on a QB role.
7
+ #
8
+ #
6
9
  class Role
10
+ # attrs
11
+ # =====
12
+
7
13
  attr_accessor :path, :name, :rel_path
8
14
 
15
+ # @!attribute [r] meta_path
16
+ # @return [String, nil] the path qb metadata was load from. `nil` if it's
17
+ # never been loaded or doesn't exist.
18
+ attr_accessor :meta_path
19
+
9
20
  # errors
10
21
  # ======
11
22
 
@@ -273,6 +284,9 @@ module QB
273
284
  end
274
285
 
275
286
  @name = path.to_s.split(File::SEPARATOR).last
287
+
288
+ # gets filled in when {#meta_load}
289
+ @meta_path = nil
276
290
  end
277
291
 
278
292
  def to_s
@@ -300,13 +314,18 @@ module QB
300
314
  #
301
315
  # if `cache` is true caches it as `@meta`
302
316
  #
303
- def load_meta cache = true
317
+ def load_meta cache = true
304
318
  meta = if (@path + 'meta' + 'qb').exist?
305
- YAML.load(Cmds.out!((@path + 'meta' + 'qb').realpath.to_s)) || {}
319
+ @meta_path = @path + 'meta' + 'qb'
320
+ YAML.load(Cmds.out!(@meta_path.realpath.to_s)) || {}
321
+
306
322
  elsif (@path + 'meta' + 'qb.yml').exist?
307
- YAML.load((@path + 'meta' + 'qb.yml').read) || {}
323
+ @meta_path = @path + 'meta' + 'qb.yml'
324
+ YAML.load(@meta_path.read) || {}
325
+
308
326
  else
309
327
  {}
328
+
310
329
  end
311
330
 
312
331
  if cache
@@ -422,6 +441,46 @@ module QB
422
441
  lines.join("\n")
423
442
  end
424
443
 
444
+ def examples
445
+ @meta['examples']
446
+ end
447
+
448
+ # format the `meta.examples` hash into a string suitable for cli
449
+ # output.
450
+ #
451
+ # @return [String]
452
+ # the CLI-formatted examples.
453
+ #
454
+ def format_examples
455
+ examples.
456
+ map {|title, body|
457
+ [
458
+ "#{ title }:",
459
+ body.lines.map {|l|
460
+ # only indent non-empty lines
461
+ # makes compacting newline sequences easier (see below)
462
+ if l.match(/^\s*$/)
463
+ l
464
+ else
465
+ ' ' + l
466
+ end
467
+ },
468
+ ''
469
+ ]
470
+ }.
471
+ flatten.
472
+ join("\n").
473
+ # compact newline sequences
474
+ gsub(/\n\n+/, "\n\n")
475
+ end
476
+
477
+ # examples text
478
+ def puts_examples
479
+ return unless examples
480
+
481
+ puts "\n" + format_examples + "\n"
482
+ end
483
+
425
484
  private
426
485
 
427
486
  # get the value at the first found of the keys or the default.
data/lib/qb/util.rb CHANGED
@@ -50,5 +50,33 @@ module QB
50
50
  # shouldn't ever happen
51
51
  raise "resolution failed: #{ segments.inspect }"
52
52
  end
53
+
54
+ # find `filename` in `from` or closest parent directory.
55
+ #
56
+ # @param [String] filename
57
+ # name of file to search for.
58
+ #
59
+ # @param [Pathname] from (Pathname.pwd)
60
+ # directory to start from.
61
+ #
62
+ # @return [Pathname]
63
+ # Pathname of found file.
64
+ #
65
+ # @raise
66
+ # if file is not found in `from` or any of it's parent directories.
67
+ #
68
+ def self.find_up filename, from = Pathname.pwd
69
+ path = from + filename
70
+
71
+ return from if path.exist?
72
+
73
+ parent = from.parent
74
+
75
+ if from == parent
76
+ raise "not found in current or any parent directories: #{ filename }"
77
+ end
78
+
79
+ return find_up filename, parent
80
+ end # .find_up
53
81
  end # Util
54
82
  end # QB
data/lib/qb/version.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  module QB
2
2
  GEM_NAME = 'qb'
3
3
 
4
- VERSION = "0.1.47"
4
+ VERSION = "0.1.48"
5
5
 
6
6
  def self.gemspec
7
7
  Gem.loaded_specs[GEM_NAME]
data/qb.gemspec CHANGED
@@ -91,6 +91,7 @@ Gem::Specification.new do |spec|
91
91
  spec.add_development_dependency "bundler", "~> 1.10"
92
92
  spec.add_development_dependency "rake", "~> 10.0"
93
93
  spec.add_development_dependency "rspec"
94
+ spec.add_development_dependency "yard"
94
95
 
95
96
  spec.add_dependency "cmds",'~> 0.0', ">= 0.0.9"
96
97
  spec.add_dependency "nrser-extras", '~> 0.0', ">= 0.0.3"
@@ -14,6 +14,10 @@ end
14
14
  puts JSON.pretty_generate({
15
15
  save_options: false,
16
16
 
17
+ default_dir: {
18
+ find_up: '.gitignore',
19
+ },
20
+
17
21
  vars: [
18
22
  {
19
23
  name: "name",
@@ -38,6 +38,13 @@ default_user: null
38
38
  # set to false to not save options in .qb-options.yml files
39
39
  save_options: false
40
40
 
41
+ examples:
42
+ create a new role backed by a GitHub repo: >
43
+
44
+ qb install --create --name=nrser.blah
45
+
46
+ (`name` needs to have the namespace attached if one is desired)
47
+
41
48
  options:
42
49
  # - name: example
43
50
  # description: an example of a variable.
@@ -46,7 +53,9 @@ options:
46
53
  # short: e
47
54
 
48
55
  - name: name
49
- description: name of role to install.
56
+ description: >
57
+ name of role to install.
58
+ include namespace if desired (nrser.blah vs blah).
50
59
  required: true
51
60
  type: string
52
61
  short: n
@@ -64,7 +73,7 @@ options:
64
73
  short: v
65
74
 
66
75
  - name: path
67
- description: path to isntall roles at.
76
+ description: path to install roles at.
68
77
  required: false
69
78
  type: string
70
79
  short: p
@@ -30,6 +30,10 @@ var_prefix: null
30
30
  # - invoke an execuable, passing a JSON serialization of the options
31
31
  # mapping their CLI names to values. path can be relative to role
32
32
  # directory.
33
+ # - {find_up: FILENAME}
34
+ # - starting at the current direcotry and climbing up to parent
35
+ # directories, use the first one that contains FILENAME. error
36
+ # if none is found.
33
37
  default_dir: null
34
38
 
35
39
  # default user to become for play
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.47
4
+ version: 0.1.48
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-06 00:00:00.000000000 Z
11
+ date: 2017-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: yard
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: cmds
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -140,6 +154,7 @@ executables:
140
154
  extensions: []
141
155
  extra_rdoc_files: []
142
156
  files:
157
+ - ".yardopts"
143
158
  - LICENSE.txt
144
159
  - README.md
145
160
  - ansible.cfg