help_parser 6.0.0 → 6.1.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: 32640b3a82d8e685727ed7ff3e3aedbe8e9ca33c6f0593614605eac9d2d9f7e4
4
- data.tar.gz: e30652f83532f4640d4e3759bea0fb3528b80a16dcf69029b2ac387442adb41b
3
+ metadata.gz: e50119d56d6b94ac58234ccfc24d3c5ddaf68a6f399753af89fc3fad2f210b3e
4
+ data.tar.gz: 591810bdc390d16c1ed6b4fc2332f6bc1b98a683c218cd446fa7726d820ff22e
5
5
  SHA512:
6
- metadata.gz: 346ae0d84f82e9c274088f0855aedf234ead157bf4a52351702e3f6a3d5267bf80eda759df59e8abb01cb873168e3c3f3d3e898c2a9790fa8e4cb095a3077b0f
7
- data.tar.gz: c19868f202f8247664b2e5006b915752609f22f7e98771edc108996dc456b858a353fbfa67079aa158704764feab96eb6902515e2b09fb0d6d7048950e0bfa86
6
+ metadata.gz: b64e50f235e4f53e2f85a0508212b38b4fb80f7616150864a68cf04f39bb3c9d88dad4a3b1764ee3a7410978d01f20ae15739610a79c92a25190bad00bd24526
7
+ data.tar.gz: 9ccf098df4a3226b39a85519251f172097ecb9854cd05adf95bc61d54a4fad9718703c6c2ed9a92abf61f1862fbe10738937b41473c34fa0eb75db34aca78b7e
data/README.md CHANGED
@@ -42,7 +42,7 @@ I prefer easy.
42
42
  Blah blah blah
43
43
  HELP
44
44
 
45
- VERSION = "6.0.0"
45
+ VERSION = "6.1.0"
46
46
 
47
47
  # Macros:
48
48
  HelpParser.string(name) # for options.name : String
@@ -63,6 +63,11 @@ I prefer easy.
63
63
  Well, what do you think?
64
64
  PERFECT!
65
65
 
66
+ ## New for 6.1.0:
67
+
68
+ Running your `awesome` command with the `--help` flag will also check your help text for errors,
69
+ on top of giving the help text. Otherwise, the parser no longer checks for help text errors.
70
+
66
71
  ## INSTALL:
67
72
 
68
73
  $ sudo gem install help_parser
@@ -1,4 +1,12 @@
1
1
  module HelpParser
2
+ @@validate = false
3
+ def self.validate!
4
+ @@validate = true
5
+ end
6
+ def self.validate?
7
+ @@validate
8
+ end
9
+
2
10
  USAGE = 'usage'
3
11
  TYPES = 'types'
4
12
  EXCLUSIVE = 'exclusive'
@@ -63,7 +71,7 @@ module HelpParser
63
71
  EXTRANEOUS_SPACES = 'Extraneous spaces in help.'
64
72
 
65
73
  # lambda utilities
66
- MSG = lambda{|msg,*keys| "#{msg}: #{keys.join(' ')}"}
74
+ MSG = lambda{|msg,*keys| "\033[0;31m#{msg}: #{keys.join(' ')}\033[0m"}
67
75
  F2K = lambda{|f| f[1]=='-' ? f[2..((f.index('=')||0)-1)] : f[1]}
68
76
  RESERVED = lambda{|k| [USAGE,TYPES,EXCLUSIVE].include?(k)} # reserved
69
77
  end
@@ -1,17 +1,23 @@
1
1
  module HelpParser
2
2
  class Options
3
- def initialize( version, help, argv)
3
+ def initialize(version, help, argv)
4
4
  @hash = HelpParser.parsea(argv)
5
5
  if version && (@hash.has_key?('v') || @hash.has_key?('version'))
6
6
  # -v or --version
7
7
  raise VersionException, version
8
8
  end
9
9
  if help
10
- if @hash.has_key?('h') || @hash.has_key?('help')
11
- # -h or --help
10
+ # -h or --help
11
+ if @hash.has_key?('h') || _=@hash.has_key?('help')
12
+ begin
13
+ # validates help
14
+ HelpParser.parseh(help, true)
15
+ rescue HelpError
16
+ $stderr.puts $!
17
+ end if _
12
18
  raise HelpException, help
13
19
  end
14
- specs = HelpParser.parseh(help)
20
+ specs = HelpParser.parseh(help, HelpParser.validate?)
15
21
  Completion.new(@hash, specs)
16
22
  if xs=specs[EXCLUSIVE]
17
23
  xs.each{|x| raise HelpParser::UsageError, MSG[EXCLUSIVE_KEYS,*x] if @hash.keys.count{|k|x.include?(k)}>1}
@@ -1,5 +1,5 @@
1
1
  module HelpParser
2
- def self.parseh(help)
2
+ def self.parseh(help, validate=true)
3
3
  specs,name = NoDupHash.new,''
4
4
  help.each_line do |line|
5
5
  line.chomp!
@@ -12,27 +12,25 @@ module HelpParser
12
12
  break if line[0]=='#'
13
13
  next if line[0]!=' '
14
14
  spec = (index=line.rindex("\t"))? line[0,index].strip : line.strip
15
- raise HelpError, EXTRANEOUS_SPACES if spec == ''
15
+ raise HelpError, EXTRANEOUS_SPACES if validate and spec==''
16
16
  case name
17
17
  when USAGE
18
18
  specs[name].push HelpParser.parseu spec
19
19
  when TYPES
20
- raise HelpError, MSG[UNRECOGNIZED_TYPE,spec] unless spec=~TYPE_DEF
20
+ raise HelpError, MSG[UNRECOGNIZED_TYPE,spec] if validate and not spec=~TYPE_DEF
21
21
  specs[name].push spec.split(CSV)
22
22
  when EXCLUSIVE
23
- raise HelpError, MSG[UNRECOGNIZED_X,spec] unless spec=~X_DEF
23
+ raise HelpError, MSG[UNRECOGNIZED_X,spec] if validate and not spec=~X_DEF
24
24
  specs[name].push spec.split(CSV)
25
25
  else
26
- case spec
27
- when SHORT, LONG, SHORT_LONG, SHORT_LONG_DEFAULT
28
- specs[name].push spec.split(CSV)
29
- else
26
+ if validate and not [SHORT, LONG, SHORT_LONG, SHORT_LONG_DEFAULT].any?{|_|_=~spec}
30
27
  raise HelpError, MSG[UNRECOGNIZED_OPTION,spec]
31
28
  end
29
+ specs[name].push spec.split(CSV)
32
30
  end
33
31
  end
34
32
  end
35
- HelpParser.validate_usage_specs(specs)
33
+ HelpParser.validate_usage_specs(specs) if validate
36
34
  return specs
37
35
  end
38
36
  end
@@ -33,12 +33,11 @@ module HelpParser
33
33
  unless specs[EXCLUSIVE].nil?
34
34
  seen = {}
35
35
  specs[EXCLUSIVE].each do |xs|
36
- k = xs.sort.join
36
+ k = xs.sort.join(',').to_sym
37
37
  raise HelpError, MSG[DUP_X,*xs] if seen[k]
38
38
  seen[k] = true
39
39
  xs.each do |x|
40
40
  raise HelpError, MSG[UNSEEN_FLAG, x] unless flags.include?(x)
41
- k<<x
42
41
  end
43
42
  end
44
43
  end
data/lib/help_parser.rb CHANGED
@@ -11,7 +11,7 @@ require_relative './help_parser/options'
11
11
  require_relative './help_parser/macros'
12
12
 
13
13
  module HelpParser
14
- VERSION = '6.0.0'
14
+ VERSION = '6.1.0'
15
15
 
16
16
  def self.[](
17
17
  version = nil,
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: help_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 6.0.0
4
+ version: 6.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - carlosjhr64
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-23 00:00:00.000000000 Z
11
+ date: 2018-02-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  Welcome to the best Help Parser of all!