cliswitch 0.1.0 → 0.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 +4 -4
- data/lib/cliswitch.rb +33 -13
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ac2df2809fefe3c68dcb610044a686868a93e4d6f9c02d4261b79f4604dd71c
|
4
|
+
data.tar.gz: 20261ed4fbc24010f195ff49961726841e92d2858334114b344aeb2ee544f814
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3cda1f5ba6ca766162c52c53f4482aa0883bc25564415447b8d9bb106b23fd9742cb7b46f298baf1fbf106c1b5f580d2fd32bc5d3d32408e9c83a5d6e514df2
|
7
|
+
data.tar.gz: 8b2e63bfa865c2b4bdf012a2f6deeb2956d3f91e30eee77b39167f1751bc2081127e7372d58cb9e526f62f0f61609646b06c8116e36c05a7b7bc6527fd075871
|
data/lib/cliswitch.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
# File : cliswitch.rb
|
3
3
|
# Authors : ccmywish <ccmywish@qq.com>
|
4
4
|
# Created on : <2022-04-13>
|
5
|
-
# Last modified : <2022-04-
|
5
|
+
# Last modified : <2022-04-14>
|
6
6
|
#
|
7
7
|
# cliswitch:
|
8
8
|
#
|
@@ -12,7 +12,7 @@
|
|
12
12
|
|
13
13
|
class CliSwitch
|
14
14
|
|
15
|
-
VERSION = "0.
|
15
|
+
VERSION = "0.3.0"
|
16
16
|
|
17
17
|
class Option
|
18
18
|
attr_accessor :name,
|
@@ -53,14 +53,14 @@ class CliSwitch
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
-
|
56
|
+
# instance attribute
|
57
57
|
attr_accessor :args
|
58
58
|
attr_accessor :options
|
59
59
|
attr_accessor :options_config
|
60
60
|
|
61
61
|
|
62
|
-
def initialize
|
63
|
-
@options_config =
|
62
|
+
def initialize
|
63
|
+
@options_config = self.class.class_options_config
|
64
64
|
end
|
65
65
|
|
66
66
|
|
@@ -103,11 +103,13 @@ class CliSwitch
|
|
103
103
|
arr.delete_at(_2+1)
|
104
104
|
when 'optional'
|
105
105
|
next_arg = arr[_2 + 1]
|
106
|
-
if next_arg.
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
106
|
+
if !next_arg.nil?
|
107
|
+
if next_arg.start_with?('-') && search_in_options_config(next_arg)
|
108
|
+
# do nothing
|
109
|
+
else
|
110
|
+
op.next_arg = next_arg
|
111
|
+
arr.delete_at(_2+1)
|
112
|
+
end
|
111
113
|
end
|
112
114
|
when 'noarg'
|
113
115
|
# do nothing
|
@@ -125,7 +127,8 @@ class CliSwitch
|
|
125
127
|
end
|
126
128
|
|
127
129
|
|
128
|
-
|
130
|
+
# Not validate by default, because it's not necessary
|
131
|
+
# validate_mandatory_options()
|
129
132
|
|
130
133
|
# Debug
|
131
134
|
# puts "=> args:"
|
@@ -133,10 +136,27 @@ class CliSwitch
|
|
133
136
|
# puts "=> options:"
|
134
137
|
# p @options
|
135
138
|
#
|
139
|
+
return @args, @options
|
136
140
|
|
137
141
|
end
|
138
142
|
|
139
143
|
|
144
|
+
#
|
145
|
+
# MyClass < CliSwitch
|
146
|
+
# option ...
|
147
|
+
# end
|
148
|
+
#
|
149
|
+
def self.option(...)
|
150
|
+
# A class instance variable for every subclass
|
151
|
+
@class_options_config ||= []
|
152
|
+
@class_options_config << Option.new(...)
|
153
|
+
end
|
154
|
+
|
155
|
+
def self.class_options_config
|
156
|
+
@class_options_config
|
157
|
+
end
|
158
|
+
|
159
|
+
|
140
160
|
private
|
141
161
|
|
142
162
|
|
@@ -169,9 +189,9 @@ class CliSwitch
|
|
169
189
|
end
|
170
190
|
end
|
171
191
|
|
172
|
-
end
|
192
|
+
end #end each loop
|
173
193
|
|
174
|
-
end
|
194
|
+
end # end def validate_mandatory_options
|
175
195
|
|
176
196
|
|
177
197
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cliswitch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ccmywish
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-04-
|
11
|
+
date: 2022-04-14 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: 'cliswitch: cli option parse.
|
14
14
|
|
@@ -40,7 +40,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '0'
|
42
42
|
requirements: []
|
43
|
-
rubygems_version: 3.3.
|
43
|
+
rubygems_version: 3.3.11
|
44
44
|
signing_key:
|
45
45
|
specification_version: 4
|
46
46
|
summary: 'cliswitch: cli option parse'
|