docopt-compgen 1.0.0 → 1.3.0

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: b3f524e54bf6f9520b41f0e64f2cd710d64a87241d7b0780fc2421655983eb1f
4
- data.tar.gz: 5204ce5211e06c02871b42e05f49371c2b6e3b4731dd6669ae39a7f026167e07
3
+ metadata.gz: 44bcf88d3208f5870a54bd566bddbdbf010a6be6a9d656c9875b36301714b519
4
+ data.tar.gz: af8eefcae73223d825ab8cb2ca2e8db2312912f4f4bac89bac047ddcd477b131
5
5
  SHA512:
6
- metadata.gz: 53ae0d920fb9d37eab1298fc07d1172d4c57ffa6e607a2243cb283e84f77bdf9eb7b87d3f33c3c86701e1646d7a3137ad338eb1c2c9fb11c7ea11dc366aae103
7
- data.tar.gz: c9935c4ca6acdb855a87d2bb663bf279c4cc6ec9df5d2c145f9479f212dbd3290d7a7b590ab8841b633532ec52acc96f1e8963712fcf5025fea81c985656b9b2
6
+ metadata.gz: 59c215aaaf9033dad335fd5965caa7320d6dd0e59d2cc3716d34e0c8c2da31315d9f40c359194da5f58987f4b8b42f4b88b15a7ccbf9423b0e02d07f73ccc4cb
7
+ data.tar.gz: 8a3d52b71f8e1ddf062d2097ae2d7ad9e4f360e7a7d239ba7e1ffe7b561891df490c1545b9c71bc20872cdafd51b04b859594a92ed378cb308d5c165404b6e5f
data/bin/docopt-compgen CHANGED
@@ -8,9 +8,11 @@ usage = <<~EOF
8
8
  #{File.basename($0)} [options] [<command>]
9
9
 
10
10
  Options:
11
+ --complete-short Complete short options (long options are always completed)
11
12
  --command-name NAME Command name
12
13
  If not specified then the slugified basename of <command> will be used
13
14
  --namespace NAME Prefix for generated bash functions [default: cmd]
15
+ -v, --version Show version
14
16
  -h, --help Show help
15
17
  EOF
16
18
 
@@ -21,8 +23,20 @@ rescue Docopt::Exit
21
23
  exit 2
22
24
  end
23
25
 
26
+ require_relative '../lib/docopt_compgen'
27
+
28
+ if opts['--version']
29
+ puts DocoptCompgen::VERSION
30
+ exit
31
+ end
32
+
24
33
  require 'colorize'
25
34
 
35
+ def extract_command_name(usage)
36
+ matches = /Usage:\s*(\S+)/.match(usage)
37
+ matches[1] if matches
38
+ end
39
+
26
40
  if $stdin.tty?
27
41
  command = opts['<command>']
28
42
  if command.nil?
@@ -32,33 +46,33 @@ if $stdin.tty?
32
46
  end
33
47
 
34
48
  begin
35
- help = `#{command} --help`
49
+ usage = `#{command} --help`
36
50
  rescue => e
37
51
  $stderr.puts e.to_s.red
38
52
  exit 1
39
53
  end
54
+
55
+ command_name = opts['--command-name']
40
56
  else
41
- if !opts['--command-name']
42
- $stderr.puts 'Error: --command-name is mandatory when passing help via stdin'.red
43
- puts usage
57
+ usage = $stdin.read
58
+ command_name = extract_command_name(usage)
59
+
60
+ if command_name.nil?
61
+ $stderr.puts 'Error: Unable to parse command name from usage output'.red
44
62
  exit 1
45
63
  end
46
-
47
- help = $stdin.read
48
64
  end
49
65
 
50
- if help.nil? || help.lines.first !~ /Usage:/
51
- $stderr.puts 'Unable to parse help output from "%s"'.red % command
66
+ if usage.nil? || usage.lines.first !~ /Usage:/
67
+ $stderr.puts 'Unable to parse usage output from "%s"'.red % command
52
68
  exit 1
53
69
  end
54
70
 
55
- require_relative '../lib/docopt-compgen'
56
-
57
- parser = DocoptCompgen::Parser.new(help)
71
+ parser = DocoptCompgen::Parser.new(usage, complete_short: opts['--complete-short'])
58
72
  generator = DocoptCompgen::Generator.new(
59
73
  command,
60
74
  parser.to_node,
61
- command_name: opts['--command-name'],
75
+ command_name: command_name,
62
76
  namespace: opts['--namespace'],
63
77
  )
64
78
 
File without changes
File without changes
@@ -1,7 +1,8 @@
1
1
  module DocoptCompgen
2
2
  class Parser
3
- def initialize(help)
3
+ def initialize(help, complete_short: false)
4
4
  @help = help
5
+ @complete_short = complete_short
5
6
  end
6
7
 
7
8
  def to_node
@@ -55,17 +56,15 @@ module DocoptCompgen
55
56
  end
56
57
  end
57
58
 
58
- # rubocop:disable Style/SoleNestedConditional
59
59
  if [Docopt::Option].include?(pattern.class)
60
- # if pattern.short
61
- # node.add_option(pattern.short)
62
- # end
60
+ if pattern.short && @complete_short
61
+ node.add_option(pattern.short)
62
+ end
63
63
 
64
64
  if pattern.long
65
65
  node.add_option(pattern.long)
66
66
  end
67
67
  end
68
- # rubocop:enable Style/SoleNestedConditional
69
68
 
70
69
  if [Docopt::Argument].include?(pattern.class)
71
70
  node.add_argument(pattern.name)
File without changes
@@ -1,3 +1,3 @@
1
1
  module DocoptCompgen
2
- VERSION = '1.0.0'
2
+ VERSION = '1.3.0'
3
3
  end
@@ -0,0 +1,11 @@
1
+ module DocoptCompgen
2
+ def self.root_dir
3
+ File.expand_path('..', __dir__)
4
+ end
5
+ end
6
+
7
+ require_relative 'docopt_compgen/version'
8
+ require_relative 'docopt_compgen/util'
9
+ require_relative 'docopt_compgen/node'
10
+ require_relative 'docopt_compgen/parser'
11
+ require_relative 'docopt_compgen/generator'
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.3.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-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -60,12 +60,12 @@ extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
62
  - bin/docopt-compgen
63
- - lib/docopt-compgen.rb
64
- - lib/docopt-compgen/generator.rb
65
- - lib/docopt-compgen/node.rb
66
- - lib/docopt-compgen/parser.rb
67
- - lib/docopt-compgen/util.rb
68
- - lib/docopt-compgen/version.rb
63
+ - lib/docopt_compgen.rb
64
+ - lib/docopt_compgen/generator.rb
65
+ - lib/docopt_compgen/node.rb
66
+ - lib/docopt_compgen/parser.rb
67
+ - lib/docopt_compgen/util.rb
68
+ - lib/docopt_compgen/version.rb
69
69
  homepage: https://github.com/crdx/docopt-compgen
70
70
  licenses:
71
71
  - MIT
@@ -78,7 +78,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
78
78
  requirements:
79
79
  - - ">="
80
80
  - !ruby/object:Gem::Version
81
- version: '0'
81
+ version: '3.0'
82
82
  required_rubygems_version: !ruby/object:Gem::Requirement
83
83
  requirements:
84
84
  - - ">="
@@ -1,11 +0,0 @@
1
- module DocoptCompgen
2
- def self.root_dir
3
- File.expand_path('../..', __FILE__)
4
- end
5
- end
6
-
7
- require_relative 'docopt-compgen/version'
8
- require_relative 'docopt-compgen/util'
9
- require_relative 'docopt-compgen/node'
10
- require_relative 'docopt-compgen/parser'
11
- require_relative 'docopt-compgen/generator'