docopt-compgen 1.0.0 → 1.1.0

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
  SHA256:
3
- metadata.gz: b3f524e54bf6f9520b41f0e64f2cd710d64a87241d7b0780fc2421655983eb1f
4
- data.tar.gz: 5204ce5211e06c02871b42e05f49371c2b6e3b4731dd6669ae39a7f026167e07
3
+ metadata.gz: 7c87d112789dd4ea1b0830ab3c5d004bf4e56fd42565de0c058cc3245ad9c58d
4
+ data.tar.gz: 1145fcc4bab68d7414deab14eceae576cc2902d8b35155219c47990171907d21
5
5
  SHA512:
6
- metadata.gz: 53ae0d920fb9d37eab1298fc07d1172d4c57ffa6e607a2243cb283e84f77bdf9eb7b87d3f33c3c86701e1646d7a3137ad338eb1c2c9fb11c7ea11dc366aae103
7
- data.tar.gz: c9935c4ca6acdb855a87d2bb663bf279c4cc6ec9df5d2c145f9479f212dbd3290d7a7b590ab8841b633532ec52acc96f1e8963712fcf5025fea81c985656b9b2
6
+ metadata.gz: 52cfc2f51e175ad014c4c575eb5da8cdaab2e1e2e8ad7473c0a6827d2c5775f68d9ae9a6782034c505d87abb4d5ba9a7f27c204fc52e660d651458360c06be43
7
+ data.tar.gz: eba600aa23409e5a9ee18c72991c32f1e5ed5a82805afc3f5943c9fd2fde3549f21cdc915904b62915677be006ae27f4a5fad90ff64cec5d9b4e474dbb676539
data/bin/docopt-compgen CHANGED
@@ -23,6 +23,11 @@ end
23
23
 
24
24
  require 'colorize'
25
25
 
26
+ def extract_command_name(usage)
27
+ matches = /Usage:\s*(\S+)/.match(usage)
28
+ matches[1] if matches
29
+ end
30
+
26
31
  if $stdin.tty?
27
32
  command = opts['<command>']
28
33
  if command.nil?
@@ -32,33 +37,35 @@ if $stdin.tty?
32
37
  end
33
38
 
34
39
  begin
35
- help = `#{command} --help`
40
+ usage = `#{command} --help`
36
41
  rescue => e
37
42
  $stderr.puts e.to_s.red
38
43
  exit 1
39
44
  end
45
+
46
+ command_name = opts['--command-name']
40
47
  else
41
- if !opts['--command-name']
42
- $stderr.puts 'Error: --command-name is mandatory when passing help via stdin'.red
43
- puts usage
48
+ usage = $stdin.read
49
+ command_name = extract_command_name(usage)
50
+
51
+ if command_name.nil?
52
+ $stderr.puts 'Error: Unable to parse command name from usage output'.red
44
53
  exit 1
45
54
  end
46
-
47
- help = $stdin.read
48
55
  end
49
56
 
50
- if help.nil? || help.lines.first !~ /Usage:/
51
- $stderr.puts 'Unable to parse help output from "%s"'.red % command
57
+ if usage.nil? || usage.lines.first !~ /Usage:/
58
+ $stderr.puts 'Unable to parse usage output from "%s"'.red % command
52
59
  exit 1
53
60
  end
54
61
 
55
62
  require_relative '../lib/docopt-compgen'
56
63
 
57
- parser = DocoptCompgen::Parser.new(help)
64
+ parser = DocoptCompgen::Parser.new(usage)
58
65
  generator = DocoptCompgen::Generator.new(
59
66
  command,
60
67
  parser.to_node,
61
- command_name: opts['--command-name'],
68
+ command_name: command_name,
62
69
  namespace: opts['--namespace'],
63
70
  )
64
71
 
@@ -1,3 +1,3 @@
1
1
  module DocoptCompgen
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docopt-compgen
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - crdx
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-05 00:00:00.000000000 Z
11
+ date: 2021-10-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize