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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/cliswitch.rb +33 -13
  3. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dcde2ba58f9e0a5e140dad92e1d94ec7da65301656768f0f213af58fa6c32e6f
4
- data.tar.gz: 9411596874bf5b9befd7854ed32d2f8932daa4312d9c0ce02d6c4793f884b5a6
3
+ metadata.gz: 2ac2df2809fefe3c68dcb610044a686868a93e4d6f9c02d4261b79f4604dd71c
4
+ data.tar.gz: 20261ed4fbc24010f195ff49961726841e92d2858334114b344aeb2ee544f814
5
5
  SHA512:
6
- metadata.gz: 031b062e1cb874d370c004db99448eb901c1449af5a08513a899a9241e58adb2999859ddb3cf0ccf163374fdcab74d4659be879308418e0851ed0a5ab6a7383e
7
- data.tar.gz: 63020821b4e86cd23b0490d08203482aa43c78ed31b9137ed84d9269b661f8c645832de7aad37576da1ee090ef7735135ee9dff7248269ff6b53e482aea50d75
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-13>
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.1.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(options_config)
63
- @options_config = 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.start_with?('-') && search_in_options_config(next_arg)
107
- # do nothing
108
- else
109
- op.next_arg = next_arg
110
- arr.delete_at(_2+1)
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
- validate_mandatory_options()
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.1.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-13 00:00:00.000000000 Z
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.7
43
+ rubygems_version: 3.3.11
44
44
  signing_key:
45
45
  specification_version: 4
46
46
  summary: 'cliswitch: cli option parse'