help_parser 1.2.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
  SHA1:
3
- metadata.gz: e7f21561ecf236af4fe5f3336b46b193ab4ec0bc
4
- data.tar.gz: a31ba014547991e9c0fcce10ecdcd1b42d266e2a
3
+ metadata.gz: 2403ec5690c6b29e5fa4fc82a4b2cabf7ce0d4d1
4
+ data.tar.gz: da462a01617bb2ae7dbda2f1f2c37fedd4023070
5
5
  SHA512:
6
- metadata.gz: 9e0fd4c89b843cc2abfe331c4f201ee293d7988884962c00cbad7755706367f25f5646318351e556dbadb71b7dc82db6ebede453d3d6a99912c186e942405110
7
- data.tar.gz: c6ce42094e74c6f2ee15b2b416ed997e66bac242c651856c23cb34238b5815fa8c2eaf971b986dbe2ed12c97bd07d11a92b886b19812cf85403dace867f20715
6
+ metadata.gz: fb9d8fab785ca44653e3229f200df278eea63752c0ebc6b8116d4575d27d84b60ad12c2814f6a0febc43e4bb4433457ff7ec976d822918073fcafc04eceb342e
7
+ data.tar.gz: f48f5d9767b607dbcc3f57ada3bdc2b62c3aad506cf5844da077c036e1ab5571e82a55090cd47aadac15e91ccdf8ec035c1b190cbab1dbdf1e9819726d7b02f2
@@ -5,7 +5,7 @@ rubygems :: https://rubygems.org/gems/help_parser
5
5
 
6
6
  == DESCRIPTION:
7
7
 
8
- _HelpParser_ - Parses your help text to define your command line options.
8
+ HelpParser - Parses your help text to define your command line options.
9
9
 
10
10
  == FEATURES/PROBLEMS:
11
11
 
@@ -40,7 +40,7 @@ _HelpParser_ - Parses your help text to define your command line options.
40
40
  exit 64 # Usage error exit code
41
41
  end
42
42
 
43
- See `examples/command_suite` for an example of how to build a command suite with _HelpParser_.
43
+ See `examples/command_suite` for an example of how to build a command suite with HelpParser.
44
44
 
45
45
  == INSTALL:
46
46
 
@@ -8,7 +8,7 @@ module HELP_PARSER
8
8
  case string
9
9
  when /^-?\d+$/
10
10
  return string.to_i
11
- when /^-?\d+\.\d+$/
11
+ when /^-?\d+\.\d+([eE][+-]?\d+)?$/
12
12
  return string.to_f
13
13
  when /,/
14
14
  return string.split(',').map{|s| to_value(s)}
@@ -1,3 +1,3 @@
1
1
  module HELP_PARSER
2
- VERSION = '1.2.0'
2
+ VERSION = '1.3.0'
3
3
  end
metadata CHANGED
@@ -1,76 +1,24 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: help_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
- - CarlosJHR64
7
+ - carlosjhr64
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-13 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rainbow
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '1.99'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 1.99.1
23
- type: :development
24
- prerelease: false
25
- version_requirements: !ruby/object:Gem::Requirement
26
- requirements:
27
- - - "~>"
28
- - !ruby/object:Gem::Version
29
- version: '1.99'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 1.99.1
33
- - !ruby/object:Gem::Dependency
34
- name: test-unit
35
- requirement: !ruby/object:Gem::Requirement
36
- requirements:
37
- - - "~>"
38
- - !ruby/object:Gem::Version
39
- version: '2.5'
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- version: 2.5.5
43
- type: :development
44
- prerelease: false
45
- version_requirements: !ruby/object:Gem::Requirement
46
- requirements:
47
- - - "~>"
48
- - !ruby/object:Gem::Version
49
- version: '2.5'
50
- - - ">="
51
- - !ruby/object:Gem::Version
52
- version: 2.5.5
11
+ date: 2015-12-23 00:00:00.000000000 Z
12
+ dependencies: []
53
13
  description: |
54
- _HelpParser_ - Parses your help text to define your command line options.
14
+ HelpParser - Parses your help text to define your command line options.
55
15
  email: carlosjhr64@gmail.com
56
16
  executables: []
57
17
  extensions: []
58
18
  extra_rdoc_files:
59
19
  - README.rdoc
60
20
  files:
61
- - History.txt
62
21
  - README.rdoc
63
- - TODO.txt
64
- - examples/command_suite
65
- - examples/implementation_error_duplicate_key
66
- - examples/implementation_error_redefinition
67
- - examples/implementation_error_terminal
68
- - examples/simple
69
- - features/edge.feature
70
- - features/simple.feature
71
- - features/step_definitions/help_parser_steps.rb
72
- - features/suite.feature
73
- - help_parser.gemspec
74
22
  - lib/help_parser.rb
75
23
  - lib/help_parser/errors.rb
76
24
  - lib/help_parser/functions.rb
@@ -81,7 +29,6 @@ files:
81
29
  - lib/help_parser/usage_exception.rb
82
30
  - lib/help_parser/version.rb
83
31
  - lib/help_parser/version_exception.rb
84
- - test/help_parser.rb
85
32
  homepage: https://github.com/carlosjhr64/help_parser
86
33
  licenses:
87
34
  - MIT
@@ -104,8 +51,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
104
51
  version: '0'
105
52
  requirements: []
106
53
  rubyforge_project:
107
- rubygems_version: 2.2.0
54
+ rubygems_version: 2.4.5.1
108
55
  signing_key:
109
56
  specification_version: 4
110
- summary: _HelpParser_ - Parses your help text to define your command line options.
57
+ summary: HelpParser - Parses your help text to define your command line options.
111
58
  test_files: []
@@ -1,5 +0,0 @@
1
- === 0.0.0 / 2013-12-04
2
- === 1.0.2 / 2013-12-13 12:22:05 -0800
3
- 773a9196081c53bd8c90252bdfae7db7 pkg/help_parser-1.0.2.gem
4
- === 1.1.0 / 2013-12-17
5
- 95995f3c2f47fff986c9d6c8158ee169 pkg/help_parser-1.1.0.gem
data/TODO.txt DELETED
@@ -1,3 +0,0 @@
1
- == File List
2
-
3
-
@@ -1,130 +0,0 @@
1
- #!/usr/bin/env ruby
2
- require 'json'
3
- require 'rainbow'
4
-
5
- ############################################################
6
- # Here I show how one might structure a command suite
7
- # using HelpParser. The output is for cucumber testing.
8
- ############################################################
9
-
10
- VERSION = '10.02.3'
11
- NAME = File.basename($PROGRAM_NAME) # command_suite
12
- GLOBAL_HELP = <<GLOBAL_HELP
13
- This is a test script for HelpParser.
14
-
15
- Usage:
16
-
17
- #{NAME} [global options] command [command options] [arguments...]
18
-
19
- Global Options:
20
-
21
- -h --help Show this help and exit
22
- -v --version Show the version and exit
23
- -q --quiet Be quiet
24
- -V --verbose Say more about whats going on
25
-
26
- --string=STRING A String value
27
- --float=FLOAT A Float value
28
- --integer=INTEGER An Integer value
29
- --array=val1,val2... An Array of values
30
-
31
- Commands:
32
-
33
- first The first command
34
- second The second command
35
-
36
- This script is being runned by Ruby #{RUBY_VERSION}.
37
- GLOBAL_HELP
38
-
39
- FIRST_HELP = <<FIRST
40
- #{NAME}-first is the first command of the test script for HelpParser.
41
- Usage: #{NAME} [global options] first [options]
42
- Options:
43
- -h --help Show this help and exit
44
- --string=STRING A String value
45
- --float=FLOAT A Float value
46
- --integer=INTEGER An Integer value
47
- --array=val1,val2... An Array of values
48
- FIRST
49
-
50
- SECOND_HELP = <<SECOND
51
- #{NAME}-second is the second command of the test script for HelpParser.
52
- Usage: #{NAME} [global options] second [options]
53
- Options:
54
- -h --help Show this help and exit
55
- --string=STRING A String value
56
- --float=FLOAT A Float value
57
- --integer=INTEGER An Integer value
58
- --array=val1,val2... An Array of values
59
- SECOND
60
-
61
- begin
62
- $LOAD_PATH << File.expand_path(File.dirname(__FILE__) + '/../lib')
63
- require 'help_parser'
64
- include HELP_PARSER
65
-
66
- GLOBAL_OPTIONS = HelpParser.new(VERSION, GLOBAL_HELP)
67
-
68
- STRING = GLOBAL_OPTIONS[:string, 'string1', 'string2']
69
- FLOAT = GLOBAL_OPTIONS[:float, 1.0, 2.0]
70
- INTEGER = GLOBAL_OPTIONS[:integer, 1, 2]
71
- ARRAY = GLOBAL_OPTIONS[:array, [], [1,'two',3.0]]
72
-
73
- GLOBAL_OPTIONS.usage_error "Need command." if ARGV.empty?
74
- COMMAND = ARGV.shift
75
- # I see suites this way:
76
- # system("command #{ARGV.join(' ')}")
77
- # but...
78
- case COMMAND
79
- when 'first'
80
- # Just going to reuse VERSION, although
81
- # the comand could have it's own version number.
82
- OPTIONS = HelpParser.new(VERSION, FIRST_HELP)
83
- # CONST = OPTIONS[key, missing_key, missing_value]
84
- CSTRING = OPTIONS[:string, 'string1', 'string2']
85
- CFLOAT = OPTIONS[:float, 1.0, 2.0]
86
- CINTEGER = OPTIONS[:integer, 1, 2]
87
- CARRAY = OPTIONS[:array, [], [1,'two',3.0]]
88
- when 'second'
89
- OPTIONS = HelpParser.new(VERSION, SECOND_HELP)
90
- CSTRING = OPTIONS[:string, 'string1', 'string2']
91
- CFLOAT = OPTIONS[:float, 1.0, 2.0]
92
- CINTEGER = OPTIONS[:integer, 1, 2]
93
- CARRAY = OPTIONS[:array, [], [1,'two',3.0]]
94
- else
95
- GLOBAL_OPTIONS.usage_error "Unrecognized command #{COMMAND}."
96
- end
97
-
98
- OUTPUT = {
99
- :exception => '',
100
- :message=> '',
101
- :command => COMMAND,
102
- :options => OPTIONS,
103
- :global_options => GLOBAL_OPTIONS,
104
- # Constants from Global
105
- :string => STRING,
106
- :float => FLOAT,
107
- :integer => INTEGER,
108
- :array => ARRAY,
109
- # Constants from Command
110
- :cstring => CSTRING,
111
- :cfloat => CFLOAT,
112
- :cinteger => CINTEGER,
113
- :carray => CARRAY,
114
- }
115
-
116
- rescue Exception
117
- STDERR.puts $!.message.chomp.color(:blue)
118
- STDERR.puts $!.backtrace.join("\n").color(:red)
119
- OUTPUT = {
120
- :exception => $!.class.to_s,
121
- :message=> $!.message,
122
- # These below might be undefined:
123
- :command => (COMMAND||=''),
124
- :global_options => (GLOBAL_OPTIONS||={}),
125
- :command_options => (OPTIONS||={}),
126
- :options => ($!.respond_to?(:obj))? $!.obj : {},
127
- }
128
- end
129
-
130
- puts JSON.pretty_generate OUTPUT
@@ -1,30 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # This is used by cucumber for testing.
3
- # It has a bad help text.
4
- require 'json'
5
- require 'rainbow'
6
- $LOAD_PATH << File.expand_path(File.dirname(__FILE__) + '/../lib')
7
- require 'help_parser'
8
- include HELP_PARSER
9
- HELP = <<HELP
10
- Usage:
11
- simple [options] arguments...
12
- Options:
13
- -z --zebra
14
- -a --zebra
15
- HELP
16
- output = {
17
- :exception => '',
18
- :message => '',
19
- }
20
- begin
21
- OPTIONS = HelpParser.new('1.2.3', HELP)
22
- rescue Exception
23
- STDERR.puts $!.obj.help.chomp.color(:blue)
24
- STDERR.puts $!.message.chomp.color(:red)
25
- output = {
26
- :exception => $!.class.to_s,
27
- :message => $!.message,
28
- }
29
- end
30
- puts JSON.pretty_generate output
@@ -1,29 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # This is used by cucumber for testing.
3
- # It has a bad help text.
4
- require 'json'
5
- require 'rainbow'
6
- $LOAD_PATH << File.expand_path(File.dirname(__FILE__) + '/../lib')
7
- require 'help_parser'
8
- include HELP_PARSER
9
- HELP = <<HELP
10
- Usage:
11
- simple [options] arguments...
12
- Options:
13
- -z --help
14
- HELP
15
- output = {
16
- :exception => '',
17
- :message => '',
18
- }
19
- begin
20
- OPTIONS = HelpParser.new('1.2.3', HELP)
21
- rescue Exception
22
- STDERR.puts $!.obj.help.chop.color(:blue)
23
- STDERR.puts $!.message.chomp.color(:red)
24
- output = {
25
- :exception => $!.class.to_s,
26
- :message => $!.message,
27
- }
28
- end
29
- puts JSON.pretty_generate output
@@ -1,30 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # This is used by cucumber for testing.
3
- # It has a bad help text.
4
- require 'json'
5
- require 'rainbow'
6
- $LOAD_PATH << File.expand_path(File.dirname(__FILE__) + '/../lib')
7
- require 'help_parser'
8
- include HELP_PARSER
9
- HELP = <<HELP
10
- Usage:
11
- simple [options] arguments...
12
- Options:
13
- -a --aaa
14
- -b --a
15
- HELP
16
- output = {
17
- :exception => '',
18
- :message => '',
19
- }
20
- begin
21
- OPTIONS = HelpParser.new('1.2.3', HELP)
22
- rescue Exception
23
- STDERR.puts $!.obj.help.chomp.color(:blue)
24
- STDERR.puts $!.message.chomp.color(:red)
25
- output = {
26
- :exception => $!.class.to_s,
27
- :message => $!.message,
28
- }
29
- end
30
- puts JSON.pretty_generate output
@@ -1,29 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # This is used by cucumber for testing.
3
- require 'json'
4
- require 'rainbow'
5
- $LOAD_PATH << File.expand_path(File.dirname(__FILE__) + '/../lib')
6
- require 'help_parser'
7
- include HELP_PARSER
8
- HELP = <<HELP
9
- Usage:
10
- simple [options] arguments...
11
- Options:
12
- -h --help Help already in dictionary
13
- Missing version in dictionary
14
- --nocomment
15
- -s --long=VALUE Full template
16
- --V Single characters can have long format
17
- -k Short option does not need a long option
18
- HELP
19
- begin
20
- OPTIONS = HelpParser.new('1.2.3', HELP)
21
- data = { :exception => '', :message => '', :options => OPTIONS }
22
- puts JSON.pretty_generate data
23
- rescue Exception
24
- STDERR.puts $!.message.chomp.color(:blue)
25
- STDERR.puts $!.backtrace.join("\n").color(:red)
26
- data = { :exception => $!.class, :message => $!.message, :options => $!.obj }
27
- data[:options] = ($!.respond_to?(:obj))? $!.obj : {}
28
- puts JSON.pretty_generate data
29
- end
@@ -1,30 +0,0 @@
1
- @edge
2
- Feature: Edge cases
3
-
4
- Scenario: Redefinition of dictionary
5
- For example, --help already maps to -h,
6
- so if help text says different
7
- we should get an ImplementationError.
8
- * Given command "./examples/implementation_error_redefinition"
9
- * Given option ""
10
- * When we run command
11
- * Then exception is "HELP_PARSER::ImplementationError"
12
- * Then message matches "redefinition"
13
-
14
- Scenario: Terminal
15
- For example, -h defines the "user wants help" state.
16
- If the help text tries to create another terminal state for -h,
17
- we should get an ImplementationError.
18
- * Given command "./examples/implementation_error_terminal"
19
- * Given option ""
20
- * When we run command
21
- * Then exception is "HELP_PARSER::ImplementationError"
22
- * Then message matches "terminal"
23
-
24
- Scenario: Redifinition in help text
25
- For example, it the help text says --zebra is -z and -a.
26
- * Given command "./examples/implementation_error_duplicate_key"
27
- * Given option ""
28
- * When we run command
29
- * Then exception is "HELP_PARSER::ImplementationError"
30
- * Then message matches "redefinition"
@@ -1,125 +0,0 @@
1
- @simple
2
- Feature: Testing examples/simple
3
-
4
- Background:
5
- * Given command "./examples/simple"
6
-
7
- Scenario: Version, short option: -v
8
- * Given option "-v"
9
- * When we run command
10
- * Then exception is "HELP_PARSER::VersionException"
11
- * Then message is "1.2.3"
12
- * Then options[v] is "true"
13
- * Then options[version] is "true"
14
-
15
- Scenario: Version, long option: --version
16
- * Given option "--version"
17
- * When we run command
18
- * Then exception is "HELP_PARSER::VersionException"
19
- * Then message is "1.2.3"
20
- * Then options[v] is "true"
21
- * Then options[version] is "true"
22
-
23
- Scenario: Help, short option: -h
24
- * Given option "-h"
25
- * When we run command
26
- * Then exception is "HELP_PARSER::HelpException"
27
- * Then message matches "^Usage:"
28
- * Then options[h] is "true"
29
- * Then options[help] is "true"
30
-
31
- Scenario: Help, long option: --help
32
- * Given option "--help"
33
- * When we run command
34
- * Then exception is "HELP_PARSER::HelpException"
35
- * Then message matches "^Usage:"
36
- * Then options[h] is "true"
37
- * Then options[help] is "true"
38
-
39
- Scenario: Duplicate with long option: -h --help
40
- * Given option "-h --help"
41
- * When we run command
42
- * Then exception is "HELP_PARSER::UsageError"
43
- * Then message matches "^duplicate"
44
-
45
- Scenario: Duplicate with short option: --help -h
46
- * Given option "-h --help"
47
- * When we run command
48
- * Then exception is "HELP_PARSER::UsageError"
49
- * Then message matches "^duplicate"
50
-
51
- Scenario: No options: ""
52
- * Given option ""
53
- * When we run command
54
- * Then exception is ""
55
- * Then message is ""
56
- * Then options.empty?
57
-
58
- Scenario: No comment: --nocomment
59
- We don't need to comment a command line option in the help.
60
- * Given option "--nocomment"
61
- * When we run command
62
- * Then exception is ""
63
- * Then message is ""
64
- * Then options[nocomment] is "true"
65
- * Then options.length is 1
66
-
67
- Scenario: Long option values, String: --long=aStringValue
68
- * Given option "--long=aStringValue"
69
- * When we run command
70
- * Then options[long] is "aStringValue"
71
-
72
- Scenario: Long option values, Integer: --long=42
73
- * Given option "--long=42"
74
- * When we run command
75
- * Then options[long] is "42"
76
- * Then options[long] kind of Integer
77
-
78
- Scenario: Long option values, default true: --long
79
- * Given option "--long"
80
- * When we run command
81
- * Then options[long] is "true"
82
-
83
- Scenario: Long option values, negated: --no-long
84
- * Given option "--no-long"
85
- * When we run command
86
- * Then options[long] is "false"
87
-
88
- Scenario: Long option values, Array: long=1,2,3
89
- * Given option "--long=1,2,3"
90
- * When we run command
91
- * Then options[long] kind of Array
92
-
93
- Scenario: Three non synonim-ed keys: -k, -V, --nocomment
94
- * Given options "--nocomment -k -V"
95
- * When we run command
96
- * Then options.length is 3
97
- * Then options[k] is "true"
98
- * Then options[V] is "true"
99
- * Then options[nocomment] is "true"
100
-
101
- Scenario: One synonim-ed key: -s
102
- * Given options "-s"
103
- * When we run command
104
- * Then options.length is 2
105
- * Then options[s] is "true"
106
- * Then options[long] is "true"
107
-
108
- Scenario: One synonim-ed key: --long=abc
109
- * Given options "--long=abc"
110
- * When we run command
111
- * Then options.length is 2
112
- * Then options[s] is "abc"
113
- * Then options[long] is "abc"
114
-
115
- Scenario: Attempting to set a negation: --no-long=NotAllowed
116
- * Given options "--no-long=NotAllowed"
117
- * When we run command
118
- * Then exception is "HELP_PARSER::UsageError"
119
- * Then message matches "no-long=NotAllowed"
120
-
121
- Scenario: User passed undefined option: --cacahuates
122
- * Given option "--cacahuates"
123
- * When we run command
124
- * Then exception is "HELP_PARSER::UsageError"
125
- * Then message matches "not.*valid.*cacahuates"
@@ -1,80 +0,0 @@
1
- require 'json'
2
- require 'open3'
3
-
4
- Given /Given command "([^"]*)"/ do |command|
5
- @command = command
6
- end
7
-
8
- Given /Given option(s?) "([^"]*)"/ do |p, options|
9
- @options = options
10
- end
11
-
12
- When /When we run command/ do
13
- @stdout, @stderr, @status = Open3.capture3("#{@command} #{@options}")
14
- begin
15
- @json = JSON.parse @stdout
16
- rescue StandardError
17
- @json = {}
18
- end
19
- end
20
-
21
- Then /Then exit status is "(\d+)"/ do |status|
22
- unless @status.exit_status == status.to_i
23
- raise "Got #{@status.exit_status} instead of #{status}"
24
- end
25
- end
26
-
27
- Then /Then (\w+) is "([^"]*)"/ do |key, expected|
28
- value = @json[key].to_s
29
- unless value == expected
30
- raise "Got '#{value}' instead of '#{expected}'"
31
- end
32
- end
33
-
34
- Then /Then (\w+) matches "([^"]*)"/ do |key, expected|
35
- value = @json[key]
36
- unless value =~ /#{expected}/
37
- raise "'#{expected}' did not match:\n#{value}"
38
- end
39
- end
40
-
41
- Then /Then options\[(\w+)\] is "([^*]*)"/ do |key,expected|
42
- options = @json['options']
43
- value = (options)? options[key].to_s : ''
44
- unless expected == value
45
- raise "Got '#{value}' instead of '#{expected}'"
46
- end
47
- end
48
-
49
- Then /Then options\[(\w+)\] kind of (\w+)/ do |key, type|
50
- options = @json['options']
51
- value = options[key]
52
- case type
53
- when 'Integer'
54
- raise "Not an integer" unless value.kind_of?(Integer)
55
- when 'Array'
56
- raise "Not an array" unless value.kind_of?(Array)
57
- else
58
- raise "Unrecognized type #{type}"
59
- end
60
- end
61
-
62
- Then /Then options.empty\?/ do
63
- options = @json['options']
64
- raise "options not empty!" unless options.empty?
65
- end
66
-
67
- Then /Then options.length is (\d+)/ do |expected|
68
- expected = expected.to_i
69
- options = @json['options']
70
- actual = options.length
71
- raise "Length was #{actual}, not #{expected}." unless actual == expected
72
- end
73
-
74
- =begin
75
- Then // do ||
76
- unless ==
77
- raise "Got '#{@json['']}' instead of '#{}'"
78
- end
79
- end
80
- =end
@@ -1,131 +0,0 @@
1
- @suite
2
- Feature: Testing examples/command_suite
3
-
4
- Background:
5
- * Given command "./examples/command_suite"
6
-
7
- Scenario: Version: -v
8
- * Given option "-v"
9
- * When we run command
10
- * Then message is "10.02.3"
11
- * Then exception is "HELP_PARSER::VersionException"
12
- * Then options[v] is "true"
13
- * Then options[version] is "true"
14
- * Then command is ""
15
-
16
- Scenario: Help: --help
17
- * Given option "--help"
18
- * When we run command
19
- * Then message matches "^This is a test script"
20
- * Then exception is "HELP_PARSER::HelpException"
21
- * Then options[h] is "true"
22
- * Then options[help] is "true"
23
- * Then command is ""
24
-
25
- Scenario: First Version: first --version
26
- * Given option "first --version"
27
- * When we run command
28
- * Then message is "10.02.3"
29
- * Then exception is "HELP_PARSER::VersionException"
30
- * Then options[v] is "true"
31
- * Then options[version] is "true"
32
- * Then command is "first"
33
-
34
- Scenario: First Help: first -h
35
- * Given option "first --h"
36
- * When we run command
37
- * Then message matches "^command_suite-first"
38
- * Then exception is "HELP_PARSER::HelpException"
39
- * Then options[h] is "true"
40
- * Then options[help] is "true"
41
- * Then command is "first"
42
-
43
- Scenario: Second Version: second --version
44
- * Given option "second --version"
45
- * When we run command
46
- * Then message is "10.02.3"
47
- * Then exception is "HELP_PARSER::VersionException"
48
- * Then options[v] is "true"
49
- * Then options[version] is "true"
50
- * Then command is "second"
51
-
52
- Scenario: Second Help: second -h
53
- * Given option "second --h"
54
- * When we run command
55
- * Then message matches "^command_suite-second"
56
- * Then exception is "HELP_PARSER::HelpException"
57
- * Then options[h] is "true"
58
- * Then options[help] is "true"
59
- * Then command is "second"
60
-
61
- Scenario: ""
62
- * Given option ""
63
- * When we run command
64
- * Then message is "Need command."
65
- * Then exception is "HELP_PARSER::UsageError"
66
-
67
- Scenario: "first"
68
- * Given option "first"
69
- * When we run command
70
- #
71
- * Then string is "string1"
72
- * Then float is "1.0"
73
- * Then integer is "1"
74
- #
75
- * Then cstring is "string1"
76
- * Then cfloat is "1.0"
77
- * Then cinteger is "1"
78
- #
79
- * Then command is "first"
80
-
81
- Scenario: "first --string --float --integer"
82
- * Given options "first --string --float --integer"
83
- * When we run command
84
- #
85
- * Then string is "string1"
86
- * Then float is "1.0"
87
- * Then integer is "1"
88
- #
89
- * Then cstring is "string2"
90
- * Then cfloat is "2.0"
91
- * Then cinteger is "2"
92
- #
93
- * Then command is "first"
94
-
95
- Scenario: "--string --float --integer second --string=string3 --float=3.0 --integer=3"
96
- * Given options "--string --float --integer second --string=string3 --float=3.0 --integer=3"
97
- * When we run command
98
- #
99
- * Then string is "string2"
100
- * Then float is "2.0"
101
- * Then integer is "2"
102
- #
103
- * Then cstring is "string3"
104
- * Then cfloat is "3.0"
105
- * Then cinteger is "3"
106
- #
107
- * Then command is "second"
108
-
109
- Scenario: "--string=1 second"
110
- * Given options "--string=1 second"
111
- * When we run command
112
- * Then exception is "HELP_PARSER::UsageError"
113
- * Then message matches "^type error.*String"
114
-
115
- Scenario: "second --integer=string"
116
- * Given options "second --integer=string"
117
- * When we run command
118
- * Then exception is "HELP_PARSER::UsageError"
119
- * Then message matches "^type error.*Fixnum"
120
-
121
- Scenario: "first --float=1"
122
- * Given options "first --float=1"
123
- * When we run command
124
- * Then exception is "HELP_PARSER::UsageError"
125
- * Then message matches "^type error.*Float"
126
-
127
- Scenario: "--array=seven first"
128
- * Given options "--array=seven first"
129
- * When we run command
130
- * Then exception is "HELP_PARSER::UsageError"
131
- * Then message matches "^type error.*Array"
@@ -1,56 +0,0 @@
1
- Gem::Specification.new do |s|
2
-
3
- s.name = 'help_parser'
4
- s.version = '1.2.0'
5
-
6
- s.homepage = 'https://github.com/carlosjhr64/help_parser'
7
-
8
- s.author = 'CarlosJHR64'
9
- s.email = 'carlosjhr64@gmail.com'
10
-
11
- s.date = '2014-01-13'
12
- s.licenses = ['MIT']
13
-
14
- s.description = <<DESCRIPTION
15
- _HelpParser_ - Parses your help text to define your command line options.
16
- DESCRIPTION
17
-
18
- s.summary = <<SUMMARY
19
- _HelpParser_ - Parses your help text to define your command line options.
20
- SUMMARY
21
-
22
- s.extra_rdoc_files = ['README.rdoc']
23
- s.rdoc_options = ["--main", "README.rdoc"]
24
-
25
- s.require_paths = ["lib"]
26
- s.files = %w(
27
- History.txt
28
- README.rdoc
29
- TODO.txt
30
- examples/command_suite
31
- examples/implementation_error_duplicate_key
32
- examples/implementation_error_redefinition
33
- examples/implementation_error_terminal
34
- examples/simple
35
- features/edge.feature
36
- features/simple.feature
37
- features/step_definitions/help_parser_steps.rb
38
- features/suite.feature
39
- help_parser.gemspec
40
- lib/help_parser.rb
41
- lib/help_parser/errors.rb
42
- lib/help_parser/functions.rb
43
- lib/help_parser/help_exception.rb
44
- lib/help_parser/help_parser.rb
45
- lib/help_parser/implementation_error.rb
46
- lib/help_parser/usage_error.rb
47
- lib/help_parser/usage_exception.rb
48
- lib/help_parser/version.rb
49
- lib/help_parser/version_exception.rb
50
- test/help_parser.rb
51
- )
52
-
53
- s.add_development_dependency 'rainbow', '~> 1.99', '>= 1.99.1'
54
- s.add_development_dependency 'test-unit', '~> 2.5', '>= 2.5.5'
55
-
56
- end
@@ -1,250 +0,0 @@
1
- require 'test/unit'
2
- require 'help_parser'
3
-
4
- class Test_HELP_PARSER_HelpParser < Test::Unit::TestCase
5
- include HELP_PARSER
6
-
7
- class Mock
8
- include HELP_PARSER::Errors
9
- def version
10
- 'version'
11
- end
12
- def help
13
- 'help'
14
- end
15
- end
16
-
17
- MOCK = Mock.new
18
-
19
- def test_001_usage_error_new
20
- assert_raises(UsageError){ raise UsageError, ['message', self] }
21
- obj = message = nil
22
- begin
23
- raise UsageError, ['message', self]
24
- rescue Exception
25
- message = $!.message
26
- obj = $!.obj if $!.respond_to?(:obj)
27
- end
28
- assert(message = 'message')
29
- refute(obj.nil?)
30
- assert(obj == self)
31
- end
32
-
33
- def test_002_implementation_error_new
34
- assert_raises(ImplementationError){ raise ImplementationError, ['message', self] }
35
- obj = nil
36
- begin
37
- raise ImplementationError, ['message', self]
38
- rescue Exception
39
- message = $!.message
40
- obj = $!.obj if $!.respond_to?(:obj)
41
- end
42
- assert(message = 'message')
43
- refute(obj.nil?)
44
- assert(obj == self)
45
- end
46
-
47
- def test_003_usage_exception_new
48
- assert_raises(UsageException){ raise UsageException, ['message', self] }
49
- obj = nil
50
- begin
51
- raise UsageException, ['message', self]
52
- rescue Exception
53
- message = $!.message
54
- obj = $!.obj if $!.respond_to?(:obj)
55
- end
56
- assert(message = 'message')
57
- refute(obj.nil?)
58
- assert(obj == self)
59
- end
60
-
61
- def test_004_help_exception_new
62
- assert_raises(HelpException){ raise HelpException, MOCK }
63
- obj = nil
64
- begin
65
- raise HelpException, MOCK
66
- rescue Exception
67
- message = $!.message
68
- obj = $!.obj if $!.respond_to?(:obj)
69
- end
70
- assert(message = 'help')
71
- refute(obj.nil?)
72
- assert(obj == MOCK)
73
- end
74
-
75
- def test_005_version_exception_new
76
- assert_raises(VersionException){ raise VersionException, MOCK }
77
- obj = nil
78
- begin
79
- raise VersionException, MOCK
80
- rescue Exception
81
- message = $!.message
82
- obj = $!.obj if $!.respond_to?(:obj)
83
- end
84
- assert(message = 'version')
85
- refute(obj.nil?)
86
- assert(obj == MOCK)
87
- end
88
-
89
- def test_006_usage_exceptions
90
- message = error = 'none'
91
- begin
92
- raise VersionException, MOCK
93
- rescue StandardError
94
- error = 'standard'
95
- rescue Exception
96
- error = 'exception'
97
- message = $!.message
98
- end
99
- assert_equal(error, 'exception')
100
- assert_equal(message, 'version')
101
-
102
- error = 'none'
103
- begin
104
- raise HelpException, MOCK
105
- rescue StandardError
106
- error = 'standard'
107
- rescue Exception
108
- error = 'exception'
109
- message = $!.message
110
- end
111
- assert_equal(error, 'exception')
112
- assert_equal(message, 'help')
113
- end
114
-
115
- def test_007_usage_errors
116
- message = error = 'none'
117
- begin
118
- raise UsageError, ['error', MOCK]
119
- rescue StandardError
120
- message = $!.message
121
- error = 'standard'
122
- rescue Exception
123
- error = 'exception'
124
- message = 'wrong'
125
- end
126
- assert_equal(error, 'standard')
127
- assert_equal(message, 'error')
128
-
129
- error = 'none'
130
- begin
131
- raise ImplementationError, ['error', MOCK]
132
- rescue StandardError
133
- message = $!.message
134
- error = 'standard'
135
- rescue Exception
136
- error = 'exception'
137
- message = 'wrong'
138
- end
139
- assert_equal(error, 'standard')
140
- assert_equal(message, 'error')
141
- end
142
-
143
- def test_008_to_value
144
- [['1', Integer], ['1.0', Float], ['One', String], ['1,2.0,Three', Array]].each do |string, type|
145
- value = HelpParser.to_value(string)
146
- assert( value.kind_of?(type) )
147
- end
148
- end
149
-
150
- def test_009_str2sym
151
- assert_equal(HelpParser.str2sym('abcd'), :abcd)
152
- assert_equal(HelpParser.str2sym('ab-cd'), :ab_cd)
153
- assert_equal(HelpParser.str2sym('ab_cd'), :ab_cd)
154
- end
155
-
156
- def test_010_raise_error
157
- assert_raises(UsageError){ MOCK.usage_error('usage error') }
158
- assert_raises(ImplementationError){ MOCK.implementation_error('implementation error') }
159
-
160
- obj = error = message = 'none'
161
- begin
162
- MOCK.usage_error('usage error')
163
- rescue Exception
164
- error = $!.class
165
- message = $!.message
166
- obj = $!.obj if $!.respond_to?(:obj)
167
- end
168
- assert_equal(error, UsageError)
169
- assert_equal(message, 'usage error')
170
- assert_equal(obj, MOCK)
171
-
172
- obj = error = message = 'none'
173
- begin
174
- MOCK.implementation_error('implementation error')
175
- rescue Exception
176
- error = $!.class
177
- message = $!.message
178
- obj = $!.obj if $!.respond_to?(:obj)
179
- end
180
- assert_equal(error, ImplementationError)
181
- assert_equal(message, 'implementation error')
182
- assert_equal(obj, MOCK)
183
- end
184
-
185
- def test_011_parse
186
- argv = [
187
- '-a', '-bcd', '--e', '--fgh',
188
- '--i=z', '--jklm=y', '--nop=1', '--q=2.0', '--r=1,2.0,Three',
189
- '--no-st'
190
- ]
191
-
192
- options = {}
193
- parsed = HelpParser.parse(argv, MOCK){|key, value| options[key]=value}
194
-
195
- assert_equal options['a'], true
196
- assert_equal options['b'], true
197
- assert_equal options['c'], true
198
- assert_equal options['d'], true
199
- assert_equal options['e'], true
200
- assert_equal options['fgh'], true
201
-
202
- assert_equal options['i'], 'z'
203
- assert_equal options['jklm'], 'y'
204
- assert_equal options['nop'], 1
205
- assert_equal options['q'], 2.0
206
- assert_equal options['r'], [1,2.0,'Three']
207
-
208
- assert_equal options['st'], false
209
-
210
- refute options.has_key?('bcd')
211
- refute options.has_key?('f')
212
- refute options.has_key?('g')
213
- refute options.has_key?('h')
214
- refute options.has_key?('no-st')
215
- refute options.has_key?('no_st')
216
-
217
- assert_raises(UsageError){ HelpParser.parse(['--no-key=true'], MOCK){ } }
218
- assert_nothing_raised(UsageError){ HelpParser.parse(['--no-key'], MOCK){ } }
219
- end
220
-
221
- # HelpParser#new, HelpParser#[], and HelpParser#defaults
222
- # are mostly tested via cucumber.
223
- # I'm just going to do some quick tests.
224
-
225
- def test_012_new
226
- argv = [
227
- '-a', '-bcd', '--e', '--fgh',
228
- '--i=z', '--jklm=y', '--nop=1', '--q=2.0', '--r=1,2.0,Three',
229
- ]
230
- help = "-a\n-b\n-c\n-d\n-e\n--fgh\n-i\n--jklm\n--nop\n--q\n--r"
231
- assert_nothing_raised{ HelpParser.new(argv, '0.1.0', help) }
232
- assert_nothing_raised{ HelpParser.new('0.0.0', argv, help) }
233
- assert_nothing_raised{ HelpParser.new('0.1.0', help, argv) }
234
- end
235
-
236
- def test_013_defaults
237
- options = HelpParser.new('0', '--var', [''])
238
- options.defaults!(:var, 'A', 'B')
239
- assert_equal( options[:var], 'A' )
240
-
241
- options = HelpParser.new('0', '--var', ['--var'])
242
- options.defaults!(:var, 'A', 'B')
243
- assert_equal( options[:var], 'B' )
244
-
245
- options = HelpParser.new('0', '--var', ['--var=C'])
246
- options.defaults!(:var, 'A', 'B')
247
- assert_equal( options[:var], 'C' )
248
- end
249
-
250
- end