clasp-ruby 0.12.2 → 0.13.2

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
- SHA1:
3
- metadata.gz: 5e5001a6187f428a3cdfe4bc6b01774d0cfd5b94
4
- data.tar.gz: efcc8d280ccbf5733a12a7979bc8725f1dd02fd9
2
+ SHA256:
3
+ metadata.gz: 888f30cc9dbb790874262a1b63c79673fba947440f3c3d1d3d28f162c74326d4
4
+ data.tar.gz: 3c26abb10e9dc9194cd7bd25e0e6dcf8c84450f899ceb0d5ae6c2dcfe8b23242
5
5
  SHA512:
6
- metadata.gz: f032b789fd1b19a34192ff7c1cc0b0324e9c8058ac04f07c10231b31083900c4046c7bd90cd3c3d167024f19baf93cb3064e91ba5ee7c275066667f5ba559301
7
- data.tar.gz: 5fc26186f36d65c126320129149d040adfa67422c56e2116230e45d403adc1ea17866f96a45eaa38ae4b19eb5101f35e743bf6c70a553def5e22d6a7c4b927ac
6
+ metadata.gz: ab50428df60b73aae5963afef09b3bf68a9f6bd189bd8d3e09ce52e9b4e91cf51923a9211be14c6f4d7452ebac234f98293a9ce0589a4ec20ec8e6e55149f1e3
7
+ data.tar.gz: df63ce0472c547f49008fe732138993bfb1c932791c23eed131dc0ad2e837073cbd1e50b55d8e2b442b7086064176b38f96c762b5c503722c213f4f3cf4924d3
@@ -197,6 +197,33 @@ class Option
197
197
  end
198
198
  end
199
199
 
200
+ # A class that represents an explicit alias for a flag or an option
201
+ class Alias
202
+
203
+ def initialize(name, aliases)
204
+
205
+ @name = name
206
+ @aliases = (aliases || []).select { |a| a and not a.empty? }
207
+ @extras = nil
208
+ @help = nil
209
+ end
210
+
211
+ # The alias' name string
212
+ attr_reader :name
213
+ # The alias' aliases array
214
+ attr_reader :aliases
215
+ # The flag's help string
216
+ attr_reader :help
217
+ # The flag's extras
218
+ attr_reader :extras
219
+
220
+ # String form of the option
221
+ def to_s
222
+
223
+ "{#{name}; aliases=#{aliases.join(', ')}}"
224
+ end
225
+ end
226
+
200
227
  # ######################################################################## #
201
228
  # functions
202
229
 
@@ -336,6 +363,25 @@ def CLASP.Option(name, options = {})
336
363
  CLASP::Option.new(name, aliases, help, values_range, default_value, required, require_message, extras)
337
364
  end
338
365
 
366
+ def CLASP.Alias(name, *args)
367
+
368
+ options = args.pop if args[-1].is_a?(::Hash)
369
+ options ||= {}
370
+
371
+ if options[:alias]
372
+
373
+ aliases = [ options[:alias] ]
374
+ elsif options[:aliases]
375
+
376
+ aliases = options[:aliases]
377
+ else
378
+
379
+ aliases = args
380
+ end
381
+
382
+ CLASP::Alias.new name, aliases
383
+ end
384
+
339
385
  # ######################################################################## #
340
386
  # module
341
387
 
@@ -126,7 +126,7 @@ def self.show_usage aliases, options={}
126
126
  raise ArgumentError, "aliases may not be nil" if aliases.nil?
127
127
  raise TypeError, "aliases must be an array or must respond to each, reject and select" unless ::Array === aliases || (aliases.respond_to?(:each) && aliases.respond_to?(:reject) && aliases.respond_to?(:select))
128
128
 
129
- aliases.each { |a| raise TypeError, "each element in aliases must be a Flag or an Option" unless a.is_a?(::CLASP::Flag) || a.is_a?(::CLASP::Option) }
129
+ aliases.each { |a| raise TypeError, "each element in aliases must be a Flag or an Option" unless [ ::CLASP::Alias, ::CLASP::Flag, ::CLASP::Option ].any? { |c| c === a } }
130
130
 
131
131
  alias_dups = {}
132
132
  aliases.each { |a| a.aliases.each { |aa| warn "WARNING: alias '#{aa}' is already used for alias '#{a}'" if alias_dups.has_key? aa; alias_dups[aa] = a; } }
@@ -175,6 +175,14 @@ def self.show_usage aliases, options={}
175
175
  voas[$1] << [ a, $2 ]
176
176
  end
177
177
 
178
+ fas = {}
179
+
180
+ aliases.select { |a| Alias === a }.each do |a|
181
+
182
+ fas[a.name] = [] unless fas.has_key? $1
183
+ fas[a.name] << a
184
+ end
185
+
178
186
  aliases = aliases.reject { |a| a.name =~ /^-+[a-zA-Z0-3_-]+[=:].+/ }
179
187
 
180
188
  info_lines.each { |info_line| stream.puts info_line } unless info_lines.empty?
@@ -189,8 +197,18 @@ def self.show_usage aliases, options={}
189
197
  aliases.each do |a|
190
198
 
191
199
  case a
200
+ when Alias
201
+
202
+ next
192
203
  when Flag
193
204
 
205
+ if fas.has_key? a.name
206
+
207
+ fas[a.name].each do |fa|
208
+
209
+ fa.aliases.each { |al| stream.puts "\t#{al}" }
210
+ end
211
+ end
194
212
  a.aliases.each { |al| stream.puts "\t#{al}" }
195
213
  stream.puts "\t#{a.name}"
196
214
  stream.puts "\t\t#{a.help}"
@@ -5,7 +5,7 @@
5
5
  # Purpose: Version for CLASP.Ruby library
6
6
  #
7
7
  # Created: 16th November 2014
8
- # Updated: 7th February 2018
8
+ # Updated: 23rd February 2018
9
9
  #
10
10
  # Home: http://github.com/synesissoftware/CLASP.Ruby
11
11
  #
@@ -51,7 +51,7 @@
51
51
  module CLASP
52
52
 
53
53
  # Current version of the CLASP.Ruby library
54
- VERSION = '0.12.2'
54
+ VERSION = '0.13.2'
55
55
 
56
56
  private
57
57
  VERSION_PARTS_ = VERSION.split(/[.]/).collect { |n| n.to_i } # :nodoc:
@@ -8,12 +8,13 @@ Aliases = [
8
8
 
9
9
  CLASP.Flag('--help', help: 'shows this help and quits'),
10
10
  CLASP.Flag('--version', alias: '-v', help: 'shows this version and quits'),
11
+ CLASP.Alias('--version', aliases: [ '-ver', '-V' ]),
11
12
 
12
13
  CLASP.Option('--directory', alias: '-d', help: 'a directory within which to process'),
13
14
  CLASP.Option('--patterns', alias: '-p', help: "one or more patterns against which the entries will be matched, separated by '|' or the platform-specific separator - ':' UNIX, ';' Windows"),
14
15
 
15
16
  CLASP.Option('--case-sensitive', alias: '-c', help: 'determines whether case sensitive', values_range: %W{ yes no true false }, default_value: false),
16
- CLASP.Option('--case-sensitive=false', alias: '-I'),
17
+ CLASP.Alias('--case-sensitive=false', alias: '-I'),
17
18
  ]
18
19
 
19
20
  Arguments = CLASP::Arguments.new(ARGV, Aliases)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clasp-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.2
4
+ version: 0.13.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Wilson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-07 00:00:00.000000000 Z
11
+ date: 2018-02-23 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  Command-Line Argument Sorting and Parsing library that provides a powerful
@@ -68,9 +68,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
68
68
  version: '0'
69
69
  requirements: []
70
70
  rubyforge_project:
71
- rubygems_version: 2.4.2
71
+ rubygems_version: 2.7.5
72
72
  signing_key:
73
73
  specification_version: 4
74
74
  summary: CLASP.Ruby
75
75
  test_files: []
76
- has_rdoc: