cl 1.1.2 → 1.1.3

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
- SHA1:
3
- metadata.gz: 7f18a2158926e842dab20361ade1b319373bddcc
4
- data.tar.gz: 159816ab441d0c8b602dc8144eb9667cf5dbd300
2
+ SHA256:
3
+ metadata.gz: 023c11a89274f2bdacc6ce33042df713e9fdf4cf4a65570e1d27499f733f993c
4
+ data.tar.gz: f6446a52bfc1f52d4733249690fc8e8a67b18b110a2e283a2756a829be11e26b
5
5
  SHA512:
6
- metadata.gz: be2b676ee1a44cbc57de36fcdef553aa03c6de6491e96bc85b25291b9801ac7e0de6cb851cc5f9c0995fa7b5166b53bd674b7c46991b4d8b1156c584c7022a24
7
- data.tar.gz: 850aefcf9d3a5e16cbef6b259b1d8085e9ebe1b75c40a7a85278ce5c961edbbcdec3c2e62e4f758986864269597a1afb321c1fa697e0f1b707d3cc17bf9d2f34
6
+ metadata.gz: 80508a712619113a2a6d7b95c73e45c5584f14432f5dc93a6196e18f1a82eafd17607f0ec0e74c094a5c1ba1d0bc2b4911c1b46aaec2ca9d87979320e40ad6bd
7
+ data.tar.gz: f5e53adf26746f03386e1270945935b0f58012f62c36fa04dbaa1179fb1fb4e0250fcb305adab85cdafa5757ada6af27fe2ace1133881574ce550800861ac8d9
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- cl (1.1.1)
4
+ cl (1.1.2)
5
5
  regstry (~> 1.0.3)
6
6
 
7
7
  GEM
@@ -17,7 +17,7 @@ class Cl
17
17
  extend Dsl
18
18
 
19
19
  class << self
20
- include Merge, Underscore
20
+ include Merge, Suggest, Underscore
21
21
 
22
22
  inherited = ->(const) do
23
23
  const.register [registry_key, underscore(const.name.split('::').last)].compact.join(':') if const.name
@@ -35,6 +35,10 @@ class Cl
35
35
  opts = merge(ctx.config[registry_key], opts) if ctx.config[registry_key]
36
36
  [args, opts || {}]
37
37
  end
38
+
39
+ def suggestions(opt)
40
+ suggest(opts.map(&:name), opt.sub(/^--/, ''))
41
+ end
38
42
  end
39
43
 
40
44
  opt '--help', 'Get help on this command'
@@ -4,6 +4,7 @@ class Cl
4
4
  class Error < StandardError
5
5
  MSGS = {
6
6
  unknown_cmd: 'Unknown command: %s',
7
+ unknown_option: 'Unknown option: %s',
7
8
  missing_args: 'Missing arguments (given: %s, required: %s)',
8
9
  too_many_args: 'Too many arguments (given: %s, allowed: %s)',
9
10
  wrong_type: 'Wrong argument type (given: %s, expected: %s)',
@@ -38,6 +39,20 @@ class Cl
38
39
  end
39
40
  end
40
41
 
42
+ class UnknownOption < Error
43
+ attr_reader :cmd, :opt
44
+
45
+ def initialize(cmd, str)
46
+ @cmd = cmd
47
+ @opt = str.sub('invalid option: ', '')
48
+ super(:unknown_option, opt)
49
+ end
50
+
51
+ def suggestions
52
+ cmd.suggestions(opt)
53
+ end
54
+ end
55
+
41
56
  class RequiredOpts < OptionError
42
57
  def initialize(opts)
43
58
  msg = opts.size == 1 ? :required_opt : :required_opts
@@ -21,6 +21,8 @@ class Cl
21
21
 
22
22
  def run
23
23
  cmd.help? ? help.run : cmd.run
24
+ rescue OptionParser::InvalidOption => e
25
+ raise UnknownOption.new(const, e.message)
24
26
  end
25
27
 
26
28
  def cmd
@@ -1,3 +1,3 @@
1
1
  class Cl
2
- VERSION = '1.1.2'
2
+ VERSION = '1.1.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.2
4
+ version: 1.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sven Fuchs
@@ -170,8 +170,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
170
170
  - !ruby/object:Gem::Version
171
171
  version: '0'
172
172
  requirements: []
173
- rubyforge_project:
174
- rubygems_version: 2.6.13
173
+ rubygems_version: 3.0.3
175
174
  signing_key:
176
175
  specification_version: 4
177
176
  summary: Object-oriented OptionParser based CLI support