easy_opt_parser 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +145 -8
- data/bin/test_arguments +30 -0
- data/easy_opt_parser.gemspec +4 -4
- data/lib/easy_opt_parser.rb +46 -15
- data/lib/easy_opt_parser/domain/command_option.rb +5 -0
- data/lib/easy_opt_parser/domain/flag_argument.rb +14 -0
- data/lib/easy_opt_parser/domain/optional_argument.rb +14 -0
- data/lib/easy_opt_parser/domain/required_argument.rb +14 -0
- data/lib/easy_opt_parser/version.rb +1 -1
- data/tests/test_easy_options_parser.rb +45 -11
- data/tests/test_helper.rb +54 -35
- metadata +14 -9
- data/lib/easy_opt_parser/domain/cli_option.rb +0 -5
- data/lib/easy_opt_parser/domain/no_required_option.rb +0 -14
- data/lib/easy_opt_parser/domain/required_option.rb +0 -14
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7eaa2265f68ad6db4a2272ec696fe187b05979ce
|
4
|
+
data.tar.gz: e9f3acf58a8765324cfee75d36e80877dcf5dc78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7263bb8733a3d654574a354e8a0acc8b32c817c6a05cd13b741dc5774f55734fbdf52f1102bc190c5ff768406c421132e9ed5fafa0d6c2460fc3a0090a53744
|
7
|
+
data.tar.gz: 3cba661d9ff484a32f9e9dde9453e351512aedf1dc8a9f6695f3d747084dbf5b0210f0b4510ee94575503d6f11b20bdad9a81bcd2fe5feb9b81646445fc5aa1c
|
data/README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
# EasyOptParser
|
1
|
+
# EasyOptParser (EOP)
|
2
2
|
|
3
|
-
|
3
|
+
Easy Opt Parser is a small simplification of the class `OptParser`.
|
4
4
|
|
5
|
-
|
5
|
+
The objective of this gem is to make easier the way to create command line options for your command. This gem is using the basic of OptParser and can be expanded over time.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
@@ -14,7 +14,7 @@ gem 'easy_opt_parser'
|
|
14
14
|
|
15
15
|
And then execute:
|
16
16
|
|
17
|
-
$ bundle
|
17
|
+
$ bundle install
|
18
18
|
|
19
19
|
Or install it yourself as:
|
20
20
|
|
@@ -22,17 +22,154 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
25
|
+
Let's see how it works!
|
26
|
+
|
27
|
+
Create a `dir` where you want and inside create two files:
|
28
|
+
|
29
|
+
`Gemfile` and `test.rb`
|
30
|
+
|
31
|
+
Inside `Gemfile`
|
32
|
+
|
33
|
+
```ruby
|
34
|
+
gem 'easy_opt_parser'
|
35
|
+
```
|
36
|
+
|
37
|
+
Then run
|
38
|
+
|
39
|
+
```bash
|
40
|
+
bundle install
|
41
|
+
```
|
42
|
+
|
43
|
+
Inside `test.rb` write this code
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
require 'easy_opt_parser'
|
47
|
+
require 'easy_opt_parser/domain/optional_argument'
|
48
|
+
require 'easy_opt_parser/domain/required_argument'
|
49
|
+
require 'easy_opt_parser/domain/flag_argument'
|
50
|
+
|
51
|
+
def arguments
|
52
|
+
[
|
53
|
+
EOP::RequiredArgument.new(name: 'required',
|
54
|
+
short_option: '-r',
|
55
|
+
long_option: '--required',
|
56
|
+
description: 'This is a required argument'),
|
57
|
+
|
58
|
+
EOP::OptionalArgument.new(name: 'optional',
|
59
|
+
short_option: '-o',
|
60
|
+
long_option: '--optional',
|
61
|
+
description: 'This is an optional argument'),
|
62
|
+
|
63
|
+
EOP::FlagArgument.new(name: 'flag',
|
64
|
+
short_option: '-f',
|
65
|
+
long_option: '--flag',
|
66
|
+
description: 'This is a flag argument'),
|
67
|
+
]
|
68
|
+
end
|
69
|
+
|
70
|
+
|
71
|
+
parser = EasyOptionParser.new('Test Arguments', arguments)
|
72
|
+
|
73
|
+
puts parser.options
|
74
|
+
```
|
75
|
+
|
76
|
+
This code shows that the only thing we need to do is to create an `Array` of `RequiredArgumen`, `OptionalArgumen` or `FlagArgument`.
|
77
|
+
|
78
|
+
`RequiredArgument`: In the help description will be added a `*` symbol to determinate that is required. Also the gem will check all required arguments to be present and with values, if not an exception will be raised.
|
79
|
+
|
80
|
+
`OptionalArgument`: Not necessary to be in command line, default value will be `nil`. If the argument is present but without value and error will be raised.
|
81
|
+
|
82
|
+
`FlagArgument`: Not necessary to be in command line, default value will be `false`. If the flag appears the value will be `true`
|
83
|
+
|
84
|
+
An extra argument is automatically added `-h` and `--help` to display the different arguments.
|
85
|
+
|
86
|
+
## Examples
|
87
|
+
|
88
|
+
Using the `Usage` example lets see the output the diffent outputs.
|
89
|
+
|
90
|
+
`help` argument
|
91
|
+
|
92
|
+
```bash
|
93
|
+
bundle exec ruby test.rb -h
|
94
|
+
```
|
95
|
+
|
96
|
+
Output
|
97
|
+
|
98
|
+
```bash
|
99
|
+
Test Arguments
|
100
|
+
-r, --required required This is a required argument *
|
101
|
+
-o, --optional optional This is an optional argument
|
102
|
+
-f, --flag This is a flag argument
|
103
|
+
-h, --help Displays Help
|
104
|
+
```
|
105
|
+
|
106
|
+
`required` argument
|
107
|
+
|
108
|
+
```bash
|
109
|
+
bundle exec ruby test.rb
|
110
|
+
```
|
111
|
+
|
112
|
+
Output
|
113
|
+
|
114
|
+
```bash
|
115
|
+
Missing Argument [required] (RuntimeError)
|
116
|
+
```
|
117
|
+
|
118
|
+
`required` is obviously a required argument, so the system will raise an error in this case
|
119
|
+
|
120
|
+
```bash
|
121
|
+
bundle exec ruby test.rb -r myValue
|
122
|
+
```
|
123
|
+
|
124
|
+
Output
|
125
|
+
|
126
|
+
```bash
|
127
|
+
{:required=>"myValue", :optional=>nil, :flag=>false}
|
128
|
+
```
|
129
|
+
|
130
|
+
`optional` argument
|
131
|
+
|
132
|
+
```bash
|
133
|
+
bundle exec ruby test.rb -r myValue -o myOptionalValue
|
134
|
+
```
|
135
|
+
|
136
|
+
Output
|
137
|
+
|
138
|
+
```bash
|
139
|
+
{:required=>"myValue", :optional=>"myOptionalValue", :flag=>false}
|
140
|
+
```
|
141
|
+
|
142
|
+
`flag` argument
|
143
|
+
|
144
|
+
```bash
|
145
|
+
bundle exec ruby test.rb -r myValue -f
|
146
|
+
```
|
147
|
+
|
148
|
+
Output
|
149
|
+
|
150
|
+
```bash
|
151
|
+
{:required=>"myValue", :optional=>nil, :flag=>true}
|
152
|
+
```
|
26
153
|
|
27
154
|
## Development
|
28
155
|
|
29
|
-
After checking out the
|
156
|
+
After checking out the repository run
|
157
|
+
|
158
|
+
```bash
|
159
|
+
bundle install
|
160
|
+
```
|
161
|
+
|
162
|
+
And then run the tests to check that everything is working as expected.
|
163
|
+
|
164
|
+
```bash
|
165
|
+
ruby tests/test_easy_options_parser.rb
|
166
|
+
```
|
30
167
|
|
31
|
-
|
168
|
+
Remember if you are contributing, create and run the tests before pull request.
|
32
169
|
|
33
170
|
## Contributing
|
34
171
|
|
35
|
-
Bug reports and pull requests are welcome on
|
172
|
+
Bug reports and pull requests are welcome on Gitlab at [https://gitlab.com/gonzalez.martin90/easy-option-parser](https://gitlab.com/gonzalez.martin90/easy-option-parser). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
36
173
|
|
37
174
|
## License
|
38
175
|
|
data/bin/test_arguments
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'easy_opt_parser'
|
4
|
+
require 'easy_opt_parser/domain/optional_argument'
|
5
|
+
require 'easy_opt_parser/domain/required_argument'
|
6
|
+
require 'easy_opt_parser/domain/flag_argument'
|
7
|
+
|
8
|
+
def arguments
|
9
|
+
[
|
10
|
+
EOP::RequiredArgument.new(name: 'required',
|
11
|
+
short_option: '-r',
|
12
|
+
long_option: '--required',
|
13
|
+
description: 'This is a required argument'),
|
14
|
+
|
15
|
+
EOP::OptionalArgument.new(name: 'optional',
|
16
|
+
short_option: '-o',
|
17
|
+
long_option: '--optional',
|
18
|
+
description: 'This is an optional argument'),
|
19
|
+
|
20
|
+
EOP::FlagArgument.new(name: 'flag',
|
21
|
+
short_option: '-f',
|
22
|
+
long_option: '--flag',
|
23
|
+
description: 'This is a flag argument'),
|
24
|
+
]
|
25
|
+
end
|
26
|
+
|
27
|
+
|
28
|
+
parser = EasyOptionParser.new('Test Arguments', arguments)
|
29
|
+
|
30
|
+
puts parser.options
|
data/easy_opt_parser.gemspec
CHANGED
@@ -9,8 +9,8 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ["Martin Gonzalez"]
|
10
10
|
spec.email = ["gonzalez.martin90@gmail.com"]
|
11
11
|
|
12
|
-
spec.summary = %q{
|
13
|
-
spec.description = %q{
|
12
|
+
spec.summary = %q{Easy Opt Parser is a small simplification of the class OptParser. }
|
13
|
+
spec.description = %q{The objective of this gem is to make easier the way to create command line options for your command. This gem is using the basic of OptParser and can be expanded over time.}
|
14
14
|
spec.homepage = "https://gitlab.com/gonzalez.martin90/easy-option-parser"
|
15
15
|
spec.license = "MIT"
|
16
16
|
|
@@ -26,8 +26,8 @@ Gem::Specification.new do |spec|
|
|
26
26
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
27
|
f.match(%r{^(test|spec|features)/})
|
28
28
|
end
|
29
|
-
spec.bindir = "
|
30
|
-
spec.executables
|
29
|
+
spec.bindir = "bin"
|
30
|
+
spec.executables << 'test_arguments'
|
31
31
|
spec.require_paths = ["lib"]
|
32
32
|
|
33
33
|
spec.add_development_dependency "bundler", "~> 1.16"
|
data/lib/easy_opt_parser.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'optparse'
|
2
|
+
require 'easy_opt_parser/domain/flag_argument'
|
2
3
|
|
3
4
|
class EasyOptionParser
|
4
5
|
attr_reader :options, :title
|
@@ -7,26 +8,36 @@ class EasyOptionParser
|
|
7
8
|
@options = {}
|
8
9
|
@title = title
|
9
10
|
assert_valid_arguments!(arguments, symbol: :name)
|
10
|
-
assert_valid_arguments!(arguments, symbol: :
|
11
|
-
assert_valid_arguments!(arguments, symbol: :
|
11
|
+
assert_valid_arguments!(arguments, symbol: :short_option)
|
12
|
+
assert_valid_arguments!(arguments, symbol: :long_option)
|
12
13
|
populate_with_default_values(arguments)
|
13
14
|
|
14
15
|
parser = OptionParser.new do |opts|
|
15
16
|
opts.banner = @title
|
16
|
-
arguments.
|
17
|
-
|
18
|
-
|
19
|
-
opts.on(argument.short, long, description) do |value|
|
20
|
-
options[argument.name.to_sym] = value
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
opts.on('-h', '--help', 'Displays Help') do
|
25
|
-
puts opts
|
26
|
-
exit
|
27
|
-
end
|
17
|
+
create_value_arguments(opts, arguments.reject {|arg| arg.is_a?(EOP::FlagArgument)})
|
18
|
+
create_flag_arguments(opts, arguments.select { |arg| arg.is_a?(EOP::FlagArgument) })
|
19
|
+
create_help_argument(opts)
|
28
20
|
end
|
29
21
|
parser.parse!
|
22
|
+
|
23
|
+
assert_required_arguments!(arguments)
|
24
|
+
end
|
25
|
+
|
26
|
+
def create_flag_arguments(opts, arguments)
|
27
|
+
arguments.each do |arg|
|
28
|
+
argument_with(opts, arg.name, arg.short_option, arg.long_option, arg.description)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def create_value_arguments(opts, arguments)
|
33
|
+
arguments.each do |arg|
|
34
|
+
long_option = create_long_option_from(arg)
|
35
|
+
argument_with(opts, arg.name, arg.short_option, long_option, arg.description)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def create_long_option_from(argument)
|
40
|
+
"#{argument.long_option} #{argument.name}"
|
30
41
|
end
|
31
42
|
|
32
43
|
def contains?(name)
|
@@ -36,9 +47,9 @@ class EasyOptionParser
|
|
36
47
|
private
|
37
48
|
|
38
49
|
def assert_valid_arguments!(arguments, symbol:)
|
50
|
+
raise 'Arguments must be an Array' unless arguments.is_a?(Array)
|
39
51
|
raise 'Arguments cannot be nil' if arguments.nil?
|
40
52
|
raise 'Arguments cannot be empty' if arguments.empty?
|
41
|
-
raise 'Arguments must be an Array' unless arguments.is_a?(Array)
|
42
53
|
argument_names = arguments.map(&symbol)
|
43
54
|
raise 'Duplicated value in options' if argument_names.detect{|a| argument_names.count(a) > 1}
|
44
55
|
end
|
@@ -48,4 +59,24 @@ class EasyOptionParser
|
|
48
59
|
@options[argument.name.to_sym] = argument.default_value
|
49
60
|
end
|
50
61
|
end
|
62
|
+
|
63
|
+
def argument_with(opts, name, short, long, description)
|
64
|
+
opts.on(short, long, description) do |value|
|
65
|
+
@options[name.to_sym] = value
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def create_help_argument(opts)
|
70
|
+
opts.on('-h', '--help', 'Displays Help') do
|
71
|
+
puts opts
|
72
|
+
exit
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def assert_required_arguments!(arguments)
|
77
|
+
required_arguments = arguments.select(&:required)
|
78
|
+
required_arguments.each do |arg|
|
79
|
+
raise "Missing Argument [#{arg.name}]" if @options[arg.name.to_sym].to_s.empty?
|
80
|
+
end
|
81
|
+
end
|
51
82
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'easy_opt_parser/domain/command_option'
|
2
|
+
|
3
|
+
module EOP
|
4
|
+
class FlagArgument < CommandOption
|
5
|
+
def initialize(name:, short_option:, long_option:, description:)
|
6
|
+
@name = name
|
7
|
+
@short_option = short_option
|
8
|
+
@long_option = long_option
|
9
|
+
@description = description
|
10
|
+
@default_value = false
|
11
|
+
@required = false
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'easy_opt_parser/domain/command_option'
|
2
|
+
|
3
|
+
module EOP
|
4
|
+
class OptionalArgument < CommandOption
|
5
|
+
def initialize(name:, short_option:, long_option:, description:, default_value: nil)
|
6
|
+
@name = name
|
7
|
+
@short_option = short_option
|
8
|
+
@long_option = long_option
|
9
|
+
@description = description
|
10
|
+
@default_value = default_value
|
11
|
+
@required = false
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'easy_opt_parser/domain/command_option'
|
2
|
+
|
3
|
+
module EOP
|
4
|
+
class RequiredArgument < CommandOption
|
5
|
+
def initialize(name:, short_option:, long_option:, description:, default_value: '')
|
6
|
+
@name = name
|
7
|
+
@short_option = short_option
|
8
|
+
@long_option = long_option
|
9
|
+
@description = "#{description} *"
|
10
|
+
@default_value = default_value
|
11
|
+
@required = true
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -3,8 +3,10 @@ require_relative './test_helper'
|
|
3
3
|
|
4
4
|
class TestEasyOptionParser < MiniTest::Test
|
5
5
|
def test_contains_a_title
|
6
|
+
# simulate the entry of arguments
|
7
|
+
ARGV.concat(%w(-p ./path))
|
6
8
|
title = 'My title'
|
7
|
-
options =
|
9
|
+
options = given_arguments
|
8
10
|
parser = EasyOptionParser.new(title, options)
|
9
11
|
|
10
12
|
assert_equal(parser.title, title)
|
@@ -28,39 +30,71 @@ class TestEasyOptionParser < MiniTest::Test
|
|
28
30
|
end
|
29
31
|
end
|
30
32
|
|
31
|
-
def
|
32
|
-
options =
|
33
|
+
def test_raise_error_when_require_arg_is_missing
|
34
|
+
options = given_arguments
|
35
|
+
assert_raises do
|
36
|
+
EasyOptionParser.new('title', options)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_optional_argument_can_be_nil
|
41
|
+
optional_arguments = given_an_optional_argument
|
42
|
+
parser = EasyOptionParser.new('Title', optional_arguments)
|
43
|
+
assert parser.options.include?(:optional)
|
44
|
+
assert parser.options[:optional].nil?
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_contains_an_argument
|
48
|
+
# simulate the entry of arguments
|
49
|
+
ARGV.concat(%w(-p ./path))
|
50
|
+
options = given_arguments
|
33
51
|
parser = EasyOptionParser.new('title', options)
|
34
52
|
|
35
53
|
assert parser.contains?('path')
|
36
54
|
end
|
37
55
|
|
38
|
-
def
|
39
|
-
|
56
|
+
def test_accept_flag_argument
|
57
|
+
# simulate the entry of arguments
|
58
|
+
ARGV << '-f'
|
59
|
+
options = given_a_flag_argument
|
60
|
+
parser = EasyOptionParser.new('title', options)
|
61
|
+
|
62
|
+
assert parser.options[:flag]
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_accept_missing_flag_argument
|
66
|
+
options = given_a_flag_argument
|
67
|
+
parser = EasyOptionParser.new('title', options)
|
68
|
+
|
69
|
+
assert !parser.options[:flag]
|
70
|
+
end
|
71
|
+
|
72
|
+
def test_raise_error_when_arguments_has_duplicated_name
|
73
|
+
options = given_duplicated_arguments_by_name
|
40
74
|
|
41
75
|
assert_raises do
|
42
76
|
EasyOptionParser.new('title', options)
|
43
77
|
end
|
44
78
|
end
|
45
79
|
|
46
|
-
def
|
47
|
-
options =
|
80
|
+
def test_raise_error_when_arguments_has_duplicated_short
|
81
|
+
options = given_duplicated_arguments_by_short
|
48
82
|
|
49
83
|
assert_raises do
|
50
84
|
EasyOptionParser.new('title', options)
|
51
85
|
end
|
52
86
|
end
|
53
87
|
|
54
|
-
def
|
55
|
-
options =
|
88
|
+
def test_raise_error_when_arguments_has_duplicated_long
|
89
|
+
options = given_duplicated_arguments_by_long
|
56
90
|
|
57
91
|
assert_raises do
|
58
92
|
EasyOptionParser.new('title', options)
|
59
93
|
end
|
60
94
|
end
|
61
95
|
|
62
|
-
def
|
96
|
+
def test_required_argument_contains_required_mark
|
63
97
|
required_option = given_a_required_option
|
64
|
-
|
98
|
+
assert required_option.description.include?('*')
|
65
99
|
end
|
66
100
|
end
|
data/tests/test_helper.rb
CHANGED
@@ -1,55 +1,74 @@
|
|
1
|
-
require 'easy_opt_parser/domain/
|
2
|
-
require 'easy_opt_parser/domain/
|
1
|
+
require 'easy_opt_parser/domain/optional_argument'
|
2
|
+
require 'easy_opt_parser/domain/required_argument'
|
3
|
+
require 'easy_opt_parser/domain/flag_argument'
|
3
4
|
require 'easy_opt_parser'
|
4
5
|
|
5
6
|
def given_a_required_option
|
6
|
-
EOP::
|
7
|
+
EOP::RequiredArgument.new(name: 'path', short_option: '-p', long_option: '--path', description: 'Some description here')
|
7
8
|
end
|
8
9
|
|
9
|
-
def
|
10
|
+
def given_arguments
|
10
11
|
[
|
11
|
-
EOP::
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
EOP::RequiredArgument.new(name: 'path',
|
13
|
+
short_option: '-p',
|
14
|
+
long_option: '--path',
|
15
|
+
description: 'Some description here')
|
15
16
|
]
|
16
17
|
end
|
17
18
|
|
18
|
-
def
|
19
|
+
def given_a_flag_argument
|
19
20
|
[
|
20
|
-
EOP::
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
EOP::RequiredOption.new(name: 'path',
|
25
|
-
short: '-o',
|
26
|
-
long: '--other',
|
27
|
-
description: 'Some other description here')
|
21
|
+
EOP::FlagArgument.new(name: 'flag',
|
22
|
+
short_option: '-f',
|
23
|
+
long_option: '--flag',
|
24
|
+
description: 'This is a flag argument')
|
28
25
|
]
|
29
26
|
end
|
30
27
|
|
31
|
-
def
|
28
|
+
def given_an_optional_argument
|
32
29
|
[
|
33
|
-
EOP::
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
EOP::RequiredOption.new(name: 'other_path',
|
38
|
-
short: '-p',
|
39
|
-
long: '--other',
|
40
|
-
description: 'Some other description here')
|
30
|
+
EOP::OptionalArgument.new(name: 'optional',
|
31
|
+
short_option: '-o',
|
32
|
+
long_option: '--opt',
|
33
|
+
description: 'Optional Value')
|
41
34
|
]
|
42
35
|
end
|
43
36
|
|
44
|
-
def
|
37
|
+
def given_duplicated_arguments_by_name
|
45
38
|
[
|
46
|
-
EOP::
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
EOP::
|
51
|
-
|
52
|
-
|
53
|
-
|
39
|
+
EOP::RequiredArgument.new(name: 'path',
|
40
|
+
short_option: '-p',
|
41
|
+
long_option: '--path',
|
42
|
+
description: 'Some description here'),
|
43
|
+
EOP::RequiredArgument.new(name: 'path',
|
44
|
+
short_option: '-o',
|
45
|
+
long_option: '--other',
|
46
|
+
description: 'Some other description here')
|
47
|
+
]
|
48
|
+
end
|
49
|
+
|
50
|
+
def given_duplicated_arguments_by_short
|
51
|
+
[
|
52
|
+
EOP::RequiredArgument.new(name: 'path',
|
53
|
+
short_option: '-p',
|
54
|
+
long_option: '--path',
|
55
|
+
description: 'Some description here'),
|
56
|
+
EOP::RequiredArgument.new(name: 'other_path',
|
57
|
+
short_option: '-p',
|
58
|
+
long_option: '--other',
|
59
|
+
description: 'Some other description here')
|
60
|
+
]
|
61
|
+
end
|
62
|
+
|
63
|
+
def given_duplicated_arguments_by_long
|
64
|
+
[
|
65
|
+
EOP::RequiredArgument.new(name: 'path',
|
66
|
+
short_option: '-p',
|
67
|
+
long_option: '--path',
|
68
|
+
description: 'Some description here'),
|
69
|
+
EOP::RequiredArgument.new(name: 'other_path',
|
70
|
+
short_option: '-o',
|
71
|
+
long_option: '--path',
|
72
|
+
description: 'Some other description here')
|
54
73
|
]
|
55
74
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: easy_opt_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Gonzalez
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-03-
|
11
|
+
date: 2018-03-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,10 +66,13 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
description:
|
69
|
+
description: The objective of this gem is to make easier the way to create command
|
70
|
+
line options for your command. This gem is using the basic of OptParser and can
|
71
|
+
be expanded over time.
|
70
72
|
email:
|
71
73
|
- gonzalez.martin90@gmail.com
|
72
|
-
executables:
|
74
|
+
executables:
|
75
|
+
- test_arguments
|
73
76
|
extensions: []
|
74
77
|
extra_rdoc_files: []
|
75
78
|
files:
|
@@ -80,11 +83,13 @@ files:
|
|
80
83
|
- LICENSE.txt
|
81
84
|
- README.md
|
82
85
|
- Rakefile
|
86
|
+
- bin/test_arguments
|
83
87
|
- easy_opt_parser.gemspec
|
84
88
|
- lib/easy_opt_parser.rb
|
85
|
-
- lib/easy_opt_parser/domain/
|
86
|
-
- lib/easy_opt_parser/domain/
|
87
|
-
- lib/easy_opt_parser/domain/
|
89
|
+
- lib/easy_opt_parser/domain/command_option.rb
|
90
|
+
- lib/easy_opt_parser/domain/flag_argument.rb
|
91
|
+
- lib/easy_opt_parser/domain/optional_argument.rb
|
92
|
+
- lib/easy_opt_parser/domain/required_argument.rb
|
88
93
|
- lib/easy_opt_parser/version.rb
|
89
94
|
- tests/test_easy_options_parser.rb
|
90
95
|
- tests/test_helper.rb
|
@@ -111,5 +116,5 @@ rubyforge_project:
|
|
111
116
|
rubygems_version: 2.6.14
|
112
117
|
signing_key:
|
113
118
|
specification_version: 4
|
114
|
-
summary:
|
119
|
+
summary: Easy Opt Parser is a small simplification of the class OptParser.
|
115
120
|
test_files: []
|
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'easy_opt_parser/domain/cli_option'
|
2
|
-
|
3
|
-
module EOP
|
4
|
-
class NoRequiredOption < CLIOption
|
5
|
-
def initialize(name:, short:, long:, description:, default_value: '')
|
6
|
-
@name = name
|
7
|
-
@short = short
|
8
|
-
@long = long
|
9
|
-
@description = description
|
10
|
-
@default_value = default_value
|
11
|
-
@required = false
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'easy_opt_parser/domain/cli_option'
|
2
|
-
|
3
|
-
module EOP
|
4
|
-
class RequiredOption < CLIOption
|
5
|
-
def initialize(name:, short:, long:, description:, default_value: '')
|
6
|
-
@name = name
|
7
|
-
@short = short
|
8
|
-
@long = long
|
9
|
-
@description = "#{description} *"
|
10
|
-
@default_value = default_value
|
11
|
-
@required = true
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|