qb 0.1.67 → 0.1.68

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: 3bfcdf4a94119b5ca496cb1f0723bcaaa8dc1a0e
4
- data.tar.gz: a91cb4f150803e5eb65a072c1d14a290777e1442
3
+ metadata.gz: d5cea6b175ce538d419a13ff2f8e93f9b60c312b
4
+ data.tar.gz: 4c9c82929111f60a0a53e21d28143baa9f979288
5
5
  SHA512:
6
- metadata.gz: c5a5f2f6900672fec6f8b780942da85d64932beb267bb6493accb0be594ccbeb32abc7863d6de1f3b6f1222b78c3a952d3d5e84eb240c8f18e99ddd1debf37a9
7
- data.tar.gz: aeb9f9693ddc76268ce3b13ed9a7c0e73d4ba59f108a94f07cfd02bb816b389a3a8c8f84a8d8f3e95890c06c93907dbdd9ac36b4c6cc3df69279767529fb0835
6
+ metadata.gz: 39bc6172c05b614b998ffc28fa3894267c617e587137080c57609aa4a89f6258681b0f08962b246a2c5d43474c078cd18588a368e44eef0ebd355b0e37f01a5d
7
+ data.tar.gz: cec0fb8aa6771e21661bb50b4f146ef27b4544ebfbd0b844dc29dd59eee0eb260b11f224c25b185671640427f476d60209b43e8740d7ea521d819b5063e8c729
data/exe/qb CHANGED
@@ -410,16 +410,22 @@ def main args
410
410
  end
411
411
 
412
412
  with_clean_env do
413
- # boot up stdio services so that ansible modules can stream to our
413
+ # boot up stdio out services so that ansible modules can stream to our
414
414
  # stdout and stderr to print stuff (including debug lines) in real-time
415
- stdio_services = {'out' => $stdout, 'err' => $stderr}.map do |name, dest|
416
- QB::Util::STDIO::Service.new(name, dest).tap {|s| s.open! }
417
- end
415
+ stdio_out_services = {'out' => $stdout, 'err' => $stderr}.
416
+ map {|name, dest|
417
+ QB::Util::STDIO::OutService.new(name, dest).tap { |s| s.open! }
418
+ }
419
+
420
+ # and an in service so that modules can prompt for user input
421
+ user_in_service = QB::Util::STDIO::InService.new('in', $stdin).
422
+ tap { |s| s.open! }
418
423
 
419
424
  status = cmd.stream
420
425
 
421
426
  # close the stdio services
422
- stdio_services.each {|s| s.close! }
427
+ stdio_out_services.each {|s| s.close! }
428
+ user_in_service.close!
423
429
 
424
430
  if status != 0
425
431
  puts "ERROR ansible-playbook failed."
@@ -12,6 +12,18 @@ module QB
12
12
  @@arg_types[name.to_sym] = type
13
13
  end
14
14
 
15
+ def debug *args
16
+ if @qb_stdio_err
17
+ header = "<QB::AnsibleModule #{ self.class.name }>"
18
+
19
+ if args[0].is_a? String
20
+ header += " " + args.shift
21
+ end
22
+
23
+ QB.debug header, *args
24
+ end
25
+ end
26
+
15
27
  def initialize
16
28
  @changed = false
17
29
  @input_file = ARGV[0]
@@ -19,17 +31,27 @@ module QB
19
31
  @args = JSON.load @input
20
32
  @facts = {}
21
33
 
34
+ @qb_stdio_out = nil
35
+ @qb_stdio_err = nil
36
+ @qb_stdio_in = nil
37
+
22
38
  # if QB_STDIO_ env vars are set send stdout and stderr
23
39
  # to those sockets to print in the parent process
24
40
 
25
41
  if ENV['QB_STDIO_OUT']
26
- $stdout = UNIXSocket.new ENV['QB_STDIO_OUT']
42
+ @qb_stdio_out = $stdout = UNIXSocket.new ENV['QB_STDIO_OUT']
27
43
  end
28
44
 
29
45
  if ENV['QB_STDIO_ERR']
30
- $stderr = UNIXSocket.new ENV['QB_STDIO_ERR']
46
+ @qb_stdio_err = $stderr = UNIXSocket.new ENV['QB_STDIO_ERR']
31
47
  end
32
48
 
49
+ if ENV['QB_STDIO_IN']
50
+ @qb_stdio_in = UNIXSocket.new ENV['QB_STDIO_IN']
51
+ end
52
+
53
+ debug "HERE!"
54
+
33
55
  @@arg_types.each {|key, type|
34
56
  var_name = "@#{ key.to_s }"
35
57
 
data/lib/qb/role.rb CHANGED
@@ -194,14 +194,21 @@ module QB
194
194
  return namespaceless_prefix_matches
195
195
  end
196
196
 
197
- # see if we word match any relative paths
197
+ # see if we prefix match any display paths
198
+ path_prefix_matches = available.select {|role|
199
+ role.display_path.start_with? input
200
+ }
201
+ return path_prefix_matches unless path_prefix_matches.empty?
202
+
203
+ # see if we word match any display` paths
198
204
  name_word_matches = available.select {|role|
199
205
  QB::Util.words_start_with? role.display_path.to_s, input
200
206
  }
201
207
  return name_word_matches unless name_word_matches.empty?
202
208
 
209
+ # nada
203
210
  []
204
- end
211
+ end # .matches
205
212
 
206
213
  # find exactly one matching role for the input string or raise.
207
214
  def self.require input
data/lib/qb/util.rb CHANGED
@@ -14,8 +14,16 @@ module QB
14
14
  # QB.debug "does #{ input } match #{ full_string }?"
15
15
 
16
16
  input_words = words input
17
+
18
+ # short-circuit if there are no input words ('./' for example)
19
+ return false if input_words.empty?
20
+
17
21
  full_string_words = words full_string
18
22
 
23
+ QB.debug "HERE",
24
+ input_words: input_words,
25
+ full_string_words: full_string_words
26
+
19
27
  full_string_words.each_with_index {|word, start_index|
20
28
  # compute the end index in full_string_words
21
29
  end_index = start_index + input_words.length - 1
data/lib/qb/util/stdio.rb CHANGED
@@ -16,9 +16,8 @@ module QB::Util::STDIO
16
16
  # their output to it, which is in turn printed to the console `qb` is running
17
17
  # in.
18
18
  class Service
19
- def initialize name, dest
19
+ def initialize name
20
20
  @name = name
21
- @dest = dest
22
21
  @thread = nil
23
22
  @server = nil
24
23
  @socket = nil
@@ -54,9 +53,7 @@ module QB::Util::STDIO
54
53
  @server = UNIXServer.new @path.to_s
55
54
  @socket = @server.accept
56
55
 
57
- while (line = @socket.gets) do
58
- @dest.puts line
59
- end
56
+ work_in_thread
60
57
  end
61
58
 
62
59
  # set the env key so children can find the socket path
@@ -73,14 +70,46 @@ module QB::Util::STDIO
73
70
  #
74
71
  debug "closing..."
75
72
 
76
- @thread.kill unless @thread.nil?
77
73
  @socket.close unless @socket.nil?
78
74
  @socket = nil
79
75
  @server.close unless @server.nil?
80
76
  @server = nil
81
77
  FileUtils.rm(@path) if @path.exist?
78
+ @thread.kill unless @thread.nil?
82
79
 
83
80
  debug "closed."
84
81
  end
85
82
  end # Service
83
+
84
+ # QB STDIO Service to proxy output from modules back to the main user
85
+ # process.
86
+ class OutService < Service
87
+ def initialize name, dest
88
+ super name
89
+ @dest = dest
90
+ end
91
+
92
+ def work_in_thread
93
+ while (line = @socket.gets) do
94
+ @dest.puts line
95
+ end
96
+ end
97
+ end # OutService
98
+
99
+ # QB STDIO Service to proxy interactive user input from the main process
100
+ # to modules.
101
+ class InService < Service
102
+ def initialize name, src
103
+ super name
104
+ @src = src
105
+ end
106
+
107
+ def work_in_thread
108
+ while (line = @src.gets) do
109
+ @socket.puts line
110
+ end
111
+
112
+ close!
113
+ end
114
+ end # InService
86
115
  end # QB::Util::STDIO
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.67"
4
+ VERSION = "0.1.68"
5
5
 
6
6
  def self.gemspec
7
7
  Gem.loaded_specs[GEM_NAME]
data/library/path_facts CHANGED
@@ -87,6 +87,27 @@ class PathFacts < QB::AnsibleModule
87
87
  end
88
88
  }
89
89
 
90
+ git.is_clean = Cmds.chomp!('git status --porcelain 2>/dev/null').empty?
91
+
92
+ rev_parse = Cmds.capture 'git rev-parse HEAD'
93
+
94
+ if rev_parse.ok?
95
+ git.head = rev_parse.out.chomp
96
+ git.head_short = git.head[0...7]
97
+ else
98
+ git.head = git.head_short = nil
99
+ end
100
+
101
+ branch = Cmds.capture 'git branch --no-color 2> /dev/null'
102
+
103
+ git.branch = if branch.ok?
104
+ if line = branch.out.lines.find {|line| line.start_with? '*'}
105
+ if m = line.match(/\*\s+(\S+)/)
106
+ m[0]
107
+ end
108
+ end
109
+ end
110
+
90
111
  git.origin = begin
91
112
  Cmds.chomp! "git remote get-url origin"
92
113
  rescue
@@ -184,9 +205,11 @@ class PathFacts < QB::AnsibleModule
184
205
  # To stay consistent with Gem
185
206
  npm.name = npm.package_json['name']
186
207
 
187
- npm.version = QB::Package::Version.from_npm_version(
188
- npm.package_json['version']
189
- )
208
+ if npm.package_json['version']
209
+ npm.version = QB::Package::Version.from_npm_version(
210
+ npm.package_json['version']
211
+ )
212
+ end
190
213
  end
191
214
 
192
215
  # Run the module.
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.67
4
+ version: 0.1.68
5
5
  platform: ruby
6
6
  authors:
7
7
  - nrser
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-07-06 00:00:00.000000000 Z
11
+ date: 2017-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler