consoler 1.0.1 → 1.2.1
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 +5 -5
- data/.github/workflows/tests.yml +34 -0
- data/.rubocop.yml +45 -0
- data/.yardopts +2 -0
- data/README.md +264 -11
- data/consoler.gemspec +4 -3
- data/lib/consoler/application.rb +112 -27
- data/lib/consoler/arguments.rb +0 -1
- data/lib/consoler/command.rb +0 -1
- data/lib/consoler/matcher.rb +157 -63
- data/lib/consoler/option.rb +113 -27
- data/lib/consoler/options.rb +40 -17
- data/lib/consoler/version.rb +1 -2
- metadata +21 -20
- data/.travis.yml +0 -11
data/lib/consoler/options.rb
CHANGED
@@ -3,7 +3,6 @@
|
|
3
3
|
require_relative 'option'
|
4
4
|
|
5
5
|
module Consoler
|
6
|
-
|
7
6
|
# List of options
|
8
7
|
#
|
9
8
|
# @attr_reader [String] description Description of the options
|
@@ -13,13 +12,15 @@ module Consoler
|
|
13
12
|
# Create a list of option based on a string definition
|
14
13
|
#
|
15
14
|
# @param options_def [String] A string definition of the desired options
|
15
|
+
# @raise [RuntimeError] if you try to use a duplicate name
|
16
16
|
def initialize(options_def)
|
17
17
|
@options = []
|
18
18
|
@description = nil
|
19
19
|
|
20
20
|
return if options_def.nil?
|
21
21
|
|
22
|
-
|
22
|
+
# strip the description
|
23
|
+
if (match = /(^|\s+)-- (?<description>.*)$/.match(options_def))
|
23
24
|
@description = match[:description]
|
24
25
|
options_def = options_def[0...-match[0].size]
|
25
26
|
end
|
@@ -29,28 +30,50 @@ module Consoler
|
|
29
30
|
|
30
31
|
option_names = []
|
31
32
|
|
32
|
-
while option_def = options.shift
|
33
|
+
while (option_def = options.shift)
|
33
34
|
Consoler::Option.create option_def, tracker do |option|
|
34
35
|
raise "Duplicate option name: #{option.name}" if option_names.include? option.name
|
35
36
|
|
36
|
-
@options.push option
|
37
37
|
option_names.push option.name
|
38
|
+
|
39
|
+
option.aliases.each do |alias_|
|
40
|
+
raise "Duplicate alias name: #{alias_.name}" if option_names.include? alias_.name
|
41
|
+
|
42
|
+
option_names.push alias_.name
|
43
|
+
end
|
44
|
+
|
45
|
+
@options.push option
|
38
46
|
end
|
39
47
|
end
|
40
48
|
end
|
41
49
|
|
42
|
-
# Get a
|
50
|
+
# Get a option by its name
|
51
|
+
#
|
52
|
+
# May be matched by one of its aliases
|
43
53
|
#
|
44
54
|
# @param name [String] Name of the option
|
45
55
|
# @return [Consoler::Option, nil]
|
46
56
|
def get(name)
|
47
|
-
|
48
|
-
|
49
|
-
|
57
|
+
option, = get_with_alias name
|
58
|
+
option
|
59
|
+
end
|
60
|
+
|
61
|
+
# Get a option by its name, with matched alias
|
62
|
+
#
|
63
|
+
# @param name [String] Name of the option
|
64
|
+
# @return [[(Consoler::Option, nil), (Consoler::Option, nil)]]
|
65
|
+
def get_with_alias(name)
|
66
|
+
each do |option, _|
|
67
|
+
if option.name == name
|
68
|
+
return option, option
|
69
|
+
end
|
70
|
+
|
71
|
+
option.aliases.each do |alias_|
|
72
|
+
return option, alias_ if alias_.name == name
|
50
73
|
end
|
51
74
|
end
|
52
75
|
|
53
|
-
|
76
|
+
[nil, nil]
|
54
77
|
end
|
55
78
|
|
56
79
|
# Loop through all options
|
@@ -72,6 +95,9 @@ module Consoler
|
|
72
95
|
@options.size
|
73
96
|
end
|
74
97
|
|
98
|
+
# Get the definition for these options
|
99
|
+
#
|
100
|
+
# @return [String] Options definition
|
75
101
|
def to_definition
|
76
102
|
definition = ''
|
77
103
|
optional = nil
|
@@ -79,18 +105,17 @@ module Consoler
|
|
79
105
|
each do |option, i|
|
80
106
|
definition += ' '
|
81
107
|
|
82
|
-
if optional.nil?
|
108
|
+
if optional.nil? && option.is_optional
|
83
109
|
definition += '['
|
84
110
|
optional = option.is_optional
|
85
111
|
end
|
86
112
|
|
87
113
|
definition += option.to_definition
|
88
114
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
end
|
115
|
+
# only close when the next option is not optional, or another optional group
|
116
|
+
if option.is_optional && (@options[i + 1].nil? || optional != @options[i + 1].is_optional)
|
117
|
+
definition += ']'
|
118
|
+
optional = nil
|
94
119
|
end
|
95
120
|
end
|
96
121
|
|
@@ -98,8 +123,6 @@ module Consoler
|
|
98
123
|
end
|
99
124
|
end
|
100
125
|
|
101
|
-
private
|
102
|
-
|
103
126
|
# Optionals tracker
|
104
127
|
#
|
105
128
|
# @attr [Boolean] is_tracking Is inside optional options
|
data/lib/consoler/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: consoler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-12-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,70 +16,70 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2.0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: minitest
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 5.11.3
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 5.11.3
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 12.3.0
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 12.3.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: simplecov
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 0.
|
61
|
+
version: 0.16.1
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 0.
|
68
|
+
version: 0.16.1
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: yard
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version: 0.
|
75
|
+
version: 0.9.12
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
|
-
version: 0.
|
82
|
+
version: 0.9.12
|
83
83
|
description: Sinatra-like application builder for the console
|
84
84
|
email: me@justim.net
|
85
85
|
executables: []
|
@@ -87,8 +87,10 @@ extensions: []
|
|
87
87
|
extra_rdoc_files: []
|
88
88
|
files:
|
89
89
|
- ".editorconfig"
|
90
|
+
- ".github/workflows/tests.yml"
|
90
91
|
- ".gitignore"
|
91
|
-
- ".
|
92
|
+
- ".rubocop.yml"
|
93
|
+
- ".yardopts"
|
92
94
|
- Gemfile
|
93
95
|
- LICENSE.txt
|
94
96
|
- README.md
|
@@ -115,15 +117,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
115
117
|
requirements:
|
116
118
|
- - ">="
|
117
119
|
- !ruby/object:Gem::Version
|
118
|
-
version: '
|
120
|
+
version: '2.4'
|
119
121
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
122
|
requirements:
|
121
123
|
- - ">="
|
122
124
|
- !ruby/object:Gem::Version
|
123
125
|
version: '0'
|
124
126
|
requirements: []
|
125
|
-
|
126
|
-
rubygems_version: 2.6.11
|
127
|
+
rubygems_version: 3.1.2
|
127
128
|
signing_key:
|
128
129
|
specification_version: 4
|
129
130
|
summary: Consoler
|