clasp-ruby 0.23.0.2 → 0.23.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6116d56077b53fd8d42a2f1275e08d5921982e2d4ffe425e9df637d6a7d97861
4
- data.tar.gz: 778800e1fcacd3b7ccbb6911c3251c5fcca73fef3447c01318b458c36ef7472a
3
+ metadata.gz: 20c2f03782787016c1a8d5d2f2ef4ec5278578571f4a806e38cbaceb83ba0f0c
4
+ data.tar.gz: 6e6c1f2fadf64a6afd4a09e0126663f2526bcf1b56e3f311cc3e7d91cd50990a
5
5
  SHA512:
6
- metadata.gz: 56d7aa277b5f5441c9472d0bb1e8961ccd577ae6477e3ec82f5a932aa6033aa3bbd4506d290e664a4f74c1f2cf9915fb4bb7b41606f884a32e1f7a29dec0ab20
7
- data.tar.gz: 33474797746dfe908b5d083d4aaedf4922d9b2cd990b0264595f557c1075d70ef0aa07d0940e1d3ed94869c0a70b999fdc3a3677f64145b2b2e6578afd904f13
6
+ metadata.gz: 10a26aab12d7e303be72ef78547bbb3035820112f41bc26542370c8071dcb09e392c4c05fd60c20e9cdc915683a2efeffc828ca90e2829b0d96597f09d6d510d
7
+ data.tar.gz: 25ee3bff884c3e50385686e1d7a37a520fbc10538d716b720a4bd95528f044adc5133c35358192703ca3218681532b8b9cda8a0d84b0a7d59ed83e7877938ca6
@@ -11,31 +11,31 @@ PROGRAM_VERSION = '0.1.2'
11
11
 
12
12
  Specifications = [
13
13
 
14
- CLASP.Flag('--all', alias: '-a', help: 'processes all item types'),
15
- CLASP.Flag('-c', help: 'count the processed items'),
16
- CLASP.Option('--opt1', alias: '-o', help: 'an option of some kind', values_range: %w{ val1, val2 }),
17
- CLASP.Flag('--opt1=val1', alias: '-v'),
18
-
19
- # see next section for why these two are here
20
- CLASP::Flag.Help,
21
- CLASP::Flag.Version,
14
+ CLASP.Flag('--all', alias: '-a', help: 'processes all item types'),
15
+ CLASP.Flag('-c', help: 'count the processed items'),
16
+ CLASP.Option('--opt1', alias: '-o', help: 'an option of some kind', values_range: %w{ val1, val2 }),
17
+ CLASP.Flag('--opt1=val1', alias: '-v'),
18
+
19
+ # see next section for why these two are here
20
+ CLASP::Flag.Help,
21
+ CLASP::Flag.Version,
22
22
  ]
23
23
 
24
24
  Args = CLASP::Arguments.new(ARGV, Specifications)
25
25
 
26
26
  Args.flags.each do |f|
27
27
 
28
- case f.name
29
- when CLASP::Flag.Help.name
28
+ case f.name
29
+ when CLASP::Flag.Help.name
30
30
 
31
- CLASP.show_usage(Specifications, exit: 0, values: '<input-file> <output-file>')
32
- when CLASP::Flag.Version.name
31
+ CLASP.show_usage(Specifications, exit: 0, values: '<input-file> <output-file>')
32
+ when CLASP::Flag.Version.name
33
33
 
34
- CLASP.show_version(Specifications, exit: 0, version: PROGRAM_VERSION)
35
- when '--all'
34
+ CLASP.show_version(Specifications, exit: 0, version: PROGRAM_VERSION)
35
+ when '--all'
36
36
 
37
- ;
38
- end
37
+ ;
38
+ end
39
39
  end
40
40
 
41
41
  puts Args.flags.size
@@ -12,10 +12,10 @@ ProgramVersion = [ 0, 0, 1 ]
12
12
 
13
13
  InfoLines = [
14
14
 
15
- 'CLASP.Ruby examples',
16
- :version,
17
- "Illustrates use of CLASP.Ruby's use of flags, options, and aliases",
18
- '',
15
+ 'CLASP.Ruby examples',
16
+ :version,
17
+ "Illustrates use of CLASP.Ruby's use of flags, options, and aliases",
18
+ '',
19
19
  ]
20
20
 
21
21
  # Specify specifications, parse, and checking standard flags
@@ -26,24 +26,24 @@ Flag_Chatty = CLASP.Flag('--verbosity=chatty', alias: '-c')
26
26
 
27
27
  Specifications = [
28
28
 
29
- Flag_Debug,
30
- Option_Verbosity,
31
- Flag_Chatty,
29
+ Flag_Debug,
30
+ Option_Verbosity,
31
+ Flag_Chatty,
32
32
 
33
- CLASP::FlagSpecification.Help,
34
- CLASP::FlagSpecification.Version,
33
+ CLASP::FlagSpecification.Help,
34
+ CLASP::FlagSpecification.Version,
35
35
  ]
36
36
 
37
37
  args = CLASP::Arguments.new ARGV, Specifications
38
38
 
39
39
  if args.flags.include?(CLASP::FlagSpecification.Help)
40
40
 
41
- CLASP.show_usage(Specifications, exit_code: 0, version: ProgramVersion, stream: $stdout, info_lines: InfoLines, default_indicator: '*default*')
41
+ CLASP.show_usage(Specifications, exit_code: 0, version: ProgramVersion, stream: $stdout, info_lines: InfoLines, default_indicator: '*default*')
42
42
  end
43
43
 
44
44
  if args.flags.include?('--version')
45
45
 
46
- CLASP.show_version(Specifications, exit_code: 0, version: ProgramVersion, stream: $stdout)
46
+ CLASP.show_version(Specifications, exit_code: 0, version: ProgramVersion, stream: $stdout)
47
47
  end
48
48
 
49
49
 
@@ -51,12 +51,12 @@ end
51
51
 
52
52
  if (opt = args.find_option('--verbosity'))
53
53
 
54
- $stdout.puts "verbosity is specified as: #{opt.value}"
54
+ $stdout.puts "verbosity is specified as: #{opt.value}"
55
55
  end
56
56
 
57
57
  if args.flags.include?('--debug')
58
58
 
59
- $stdout.puts 'Debug mode is specified'
59
+ $stdout.puts 'Debug mode is specified'
60
60
  end
61
61
 
62
62
 
@@ -65,9 +65,9 @@ end
65
65
 
66
66
  if (unused = args.find_first_unknown())
67
67
 
68
- $stderr.puts "#{args.program_name}: unrecognised flag/option: #{unused}"
68
+ $stderr.puts "#{args.program_name}: unrecognised flag/option: #{unused}"
69
69
 
70
- exit 1
70
+ exit 1
71
71
  end
72
72
 
73
73
 
@@ -12,30 +12,30 @@ ProgramVersion = [ 0, 0, 1 ]
12
12
 
13
13
  InfoLines = [
14
14
 
15
- 'CLASP.Ruby examples',
16
- :version,
17
- "Illustrates use of CLASP.Ruby's CLASP.show_usage() and CLASP.show_version() methods",
18
- '',
15
+ 'CLASP.Ruby examples',
16
+ :version,
17
+ "Illustrates use of CLASP.Ruby's CLASP.show_usage() and CLASP.show_version() methods",
18
+ '',
19
19
  ]
20
20
 
21
21
  # Specify specifications, parse, and checking standard flags
22
22
 
23
23
  Specifications = [
24
24
 
25
- CLASP::FlagSpecification.Help,
26
- CLASP::FlagSpecification.Version,
25
+ CLASP::FlagSpecification.Help,
26
+ CLASP::FlagSpecification.Version,
27
27
  ]
28
28
 
29
29
  args = CLASP::Arguments.new ARGV, Specifications
30
30
 
31
31
  if args.flags.include?('--help')
32
32
 
33
- CLASP.show_usage(Specifications, exit_code: 0, version: ProgramVersion, stream: $stdout, info_lines: InfoLines)
33
+ CLASP.show_usage(Specifications, exit_code: 0, version: ProgramVersion, stream: $stdout, info_lines: InfoLines)
34
34
  end
35
35
 
36
36
  if args.flags.include?('--version')
37
37
 
38
- CLASP.show_version(Specifications, exit_code: 0, version: ProgramVersion, stream: $stdout)
38
+ CLASP.show_version(Specifications, exit_code: 0, version: ProgramVersion, stream: $stdout)
39
39
  end
40
40
 
41
41
 
@@ -43,12 +43,11 @@ end
43
43
 
44
44
  if (unused = args.find_first_unknown())
45
45
 
46
- $stderr.puts "#{args.program_name}: unrecognised flag/option: #{unused}"
46
+ $stderr.puts "#{args.program_name}: unrecognised flag/option: #{unused}"
47
47
 
48
- exit 1
48
+ exit 1
49
49
  end
50
50
 
51
51
 
52
52
  $stdout.puts 'no flags specified'
53
53
 
54
-
@@ -1,18 +1,17 @@
1
1
 
2
2
  # ######################################################################## #
3
- # File: clasp/arguments.rb
3
+ # File: clasp/arguments.rb
4
4
  #
5
- # Purpose: Definition of the Arguments class, the main class in
6
- # CLASP.Ruby
5
+ # Purpose: Definition of the Arguments class, the main class in CLASP.Ruby
7
6
  #
8
- # Created: 14th February 2014
9
- # Updated: 20th January 2024
7
+ # Created: 14th February 2014
8
+ # Updated: 6th March 2025
10
9
  #
11
- # Home: http://github.com/synesissoftware/CLASP.Ruby
10
+ # Home: http://github.com/synesissoftware/CLASP.Ruby
12
11
  #
13
- # Author: Matthew Wilson
12
+ # Author: Matthew Wilson
14
13
  #
15
- # Copyright (c) 2019-2024, Matthew Wilson and Synesis Information Systems
14
+ # Copyright (c) 2019-2025, Matthew Wilson and Synesis Information Systems
16
15
  # Copyright (c) 2014-2019, Matthew Wilson and Synesis Software
17
16
  # All rights reserved.
18
17
  #
@@ -72,14 +71,14 @@ class Arguments
72
71
  # should not be called directly from application code
73
72
  def initialize(arg, given_index, given_name, resolved_name, argument_spec, given_hyphens, given_label, extras) # :nodoc:
74
73
 
75
- @arg = arg
76
- @given_index = given_index
77
- @given_name = given_name
78
- @argument_specification = argument_spec
79
- @given_hyphens = given_hyphens
80
- @given_label = given_label
81
- @name = resolved_name || given_name
82
- @extras = extras.nil? ? {} : extras
74
+ @arg = arg
75
+ @given_index = given_index
76
+ @given_name = given_name
77
+ @argument_specification = argument_spec
78
+ @given_hyphens = given_hyphens
79
+ @given_label = given_label
80
+ @name = resolved_name || given_name
81
+ @extras = extras.nil? ? {} : extras
83
82
  end
84
83
 
85
84
  # (Integer) The command-line index of the argument
@@ -160,10 +159,10 @@ class Arguments
160
159
 
161
160
  if constraint.empty?
162
161
 
163
- resolved_value = (value || '').empty? ? argument_spec.default_value : value
162
+ resolved_value = (value || '').empty? ? argument_spec.default_value : value
164
163
  else
165
164
 
166
- resolved_value = value_from_Hash(constraint, value, arg, given_index, given_name, argument_spec, extras)
165
+ resolved_value = value_from_Hash(constraint, value, arg, given_index, given_name, argument_spec, extras)
167
166
  end
168
167
  else
169
168
 
@@ -171,19 +170,19 @@ class Arguments
171
170
  end
172
171
  else
173
172
 
174
- resolved_value = value
173
+ resolved_value = value
175
174
  end
176
175
 
177
- @arg = arg
178
- @given_index = given_index
179
- @given_name = given_name
180
- @argument_specification = argument_spec
181
- @given_hyphens = given_hyphens
182
- @given_label = given_label
183
- @given_value = value
184
- @value = resolved_value
185
- @name = resolved_name || given_name
186
- @extras = extras.nil? ? {} : extras
176
+ @arg = arg
177
+ @given_index = given_index
178
+ @given_name = given_name
179
+ @argument_specification = argument_spec
180
+ @given_hyphens = given_hyphens
181
+ @given_label = given_label
182
+ @given_value = value
183
+ @value = resolved_value
184
+ @name = resolved_name || given_name
185
+ @extras = extras.nil? ? {} : extras
187
186
  end
188
187
 
189
188
  # (Integer) The command-line index of the argument
@@ -300,12 +299,12 @@ class Arguments
300
299
  end
301
300
  end
302
301
 
303
- specs = []
302
+ specs = []
304
303
 
305
- _clasp = h['clasp'] or raise ArgumentError, "missing top-level 'clasp' element in load configuration"
304
+ _clasp = h['clasp'] or raise ArgumentError, "missing top-level 'clasp' element in load configuration"
306
305
  ::Hash === _clasp or raise ArgumentError, "top-level 'clasp' element must be a #{::Hash}"
307
306
 
308
- _specs = (_clasp['arg-specs'] || _clasp['specifications'] || _clasp['aliases']) or raise ArgumentError, "missing element 'clasp/specifications'"
307
+ _specs = (_clasp['arg-specs'] || _clasp['specifications'] || _clasp['aliases']) or raise ArgumentError, "missing element 'clasp/specifications'"
309
308
  ::Array === _specs or raise ArgumentError, "top-level 'specifications' element must be a #{::Hash}"
310
309
 
311
310
  _specs.each do |_spec|
@@ -327,9 +326,9 @@ class Arguments
327
326
  warn "flag specification missing required 'name' field"
328
327
  else
329
328
 
330
- _alias = _details['alias']
331
- _aliases = _details['aliases']
332
- _help = _details['help'] || _details['description']
329
+ _alias = _details['alias']
330
+ _aliases = _details['aliases']
331
+ _help = _details['help'] || _details['description']
333
332
 
334
333
  specs << CLASP.Flag(_name, alias: _alias, aliases: _aliases, help: _help)
335
334
  end
@@ -342,13 +341,13 @@ class Arguments
342
341
  warn "option specification missing required 'name' field"
343
342
  else
344
343
 
345
- _alias = _details['alias']
346
- _aliases = _details['aliases']
347
- _default_value = _details['default_value'] || _details['default']
348
- _help = _details['help'] || _details['description']
349
- _required = _details['required']
350
- _required_message = _details['required_message']
351
- _values_range = _details['values_range'] || _details['values']
344
+ _alias = _details['alias']
345
+ _aliases = _details['aliases']
346
+ _default_value = _details['default_value'] || _details['default']
347
+ _help = _details['help'] || _details['description']
348
+ _required = _details['required']
349
+ _required_message = _details['required_message']
350
+ _values_range = _details['values_range'] || _details['values']
352
351
 
353
352
  specs << CLASP.Option(_name, alias: _alias, aliases: _aliases, default_value: _default_value, help: _help, required: _required, required_message: _required_message, values_range: _values_range)
354
353
  end
@@ -361,8 +360,8 @@ class Arguments
361
360
  warn "alias specification missing required 'resolved' field"
362
361
  else
363
362
 
364
- _alias = _details['alias']
365
- _aliases = _details['aliases']
363
+ _alias = _details['alias']
364
+ _aliases = _details['aliases']
366
365
 
367
366
  unless _alias || _aliases
368
367
 
@@ -404,20 +403,20 @@ class Arguments
404
403
 
405
404
  # have to do this name-swap, as 'options' has CLASP-specific
406
405
  # meaning
407
- init_opts, options = options.dup, nil
406
+ init_opts, options = options.dup, nil
408
407
 
409
408
  init_opts[:mutate_argv] = true unless init_opts.has_key? :mutate_argv
410
409
 
411
- @program_name = init_opts[:program_name] || Arguments.derive_program_name_
410
+ @program_name = init_opts[:program_name] || Arguments.derive_program_name_
412
411
 
413
- @argv = argv
414
- argv = argv.dup
415
- @argv_original_copy = argv.dup.freeze
412
+ @argv = argv
413
+ argv = argv.dup
414
+ @argv_original_copy = argv.dup.freeze
416
415
 
417
- @specifications = specifications
418
- @aliases = @specifications
416
+ @specifications = specifications
417
+ @aliases = @specifications
419
418
 
420
- specifications = nil if specifications and specifications.empty?
419
+ specifications = nil if specifications and specifications.empty?
421
420
 
422
421
  flags, options, values, double_slash_index = Arguments.parse_(argv, specifications)
423
422
 
@@ -430,31 +429,31 @@ class Arguments
430
429
 
431
430
  def to_s
432
431
 
433
- s = ''
432
+ s = ''
434
433
 
435
- s += '['
436
- s += self.map { |v| %Q<"#{v}"> }.join(', ')
437
- s += ']'
434
+ s += '['
435
+ s += self.map { |v| %Q<"#{v}"> }.join(', ')
436
+ s += ']'
438
437
 
439
438
  s
440
439
  end
441
440
 
442
441
  def inspect
443
442
 
444
- s = ''
443
+ s = ''
445
444
 
446
- s += "#<#{self.class}:0x#{(object_id << 1).to_s(16)} ["
447
- s += self.map { |v| v.inspect }.join(', ')
448
- s += "]>"
445
+ s += "#<#{self.class}:0x#{(object_id << 1).to_s(16)} ["
446
+ s += self.map { |v| v.inspect }.join(', ')
447
+ s += "]>"
449
448
 
450
449
  s
451
450
  end
452
451
  end
453
452
  end
454
453
 
455
- @flags = flags.freeze
456
- @options = options.freeze
457
- @values = values.freeze
454
+ @flags = flags.freeze
455
+ @options = options.freeze
456
+ @values = values.freeze
458
457
 
459
458
  @double_slash_index = double_slash_index
460
459
 
@@ -483,14 +482,14 @@ class Arguments
483
482
  # @!visibility private
484
483
  def self.parse_(argv, specifications) # :nodoc:
485
484
 
486
- flags = []
487
- options = []
488
- values = []
485
+ flags = []
486
+ options = []
487
+ values = []
489
488
 
490
489
  double_slash_index = nil
491
490
 
492
- forced_value = false
493
- pending_option = nil
491
+ forced_value = false
492
+ pending_option = nil
494
493
 
495
494
  argv.each_with_index do |arg, index|
496
495
 
@@ -509,27 +508,27 @@ class Arguments
509
508
  # do regex test to see if option/flag/value
510
509
  if arg =~ /^(-+)([^=]+)/
511
510
 
512
- hyphens = $1
513
- given_label = $2
514
- given_name = "#$1#$2"
515
- value = ($' and not $'.empty?) ? $'[1 ... $'.size] : nil
516
- argument_spec = nil
517
- resolved_name = nil
511
+ hyphens = $1
512
+ given_label = $2
513
+ given_name = "#$1#$2"
514
+ value = ($' and not $'.empty?) ? $'[1 ... $'.size] : nil
515
+ argument_spec = nil
516
+ resolved_name = nil
518
517
 
519
518
  (specifications || []).each do |s|
520
519
 
521
520
  if s.name == given_name or s.aliases.include? given_name
522
521
 
523
- argument_spec = s
524
- resolved_name = s.name
522
+ argument_spec = s
523
+ resolved_name = s.name
525
524
 
526
525
  # need to check whether the alias is a default-option
527
526
  # and, if so, expand out its name and value, and replace
528
527
  # the name and (if none previously specified) the value
529
528
  if resolved_name =~ /^(-+)([^=]+)=/
530
529
 
531
- resolved_name = "#$1#$2"
532
- value ||= $'
530
+ resolved_name = "#$1#$2"
531
+ value ||= $'
533
532
 
534
533
  # now find the underlying (option) specification
535
534
  specifications.each do |t|
@@ -554,9 +553,9 @@ class Arguments
554
553
  flag_aliases = []
555
554
  given_label[0 ... given_label.size].each_char do |c|
556
555
 
557
- new_flag = "-#{c.chr}"
556
+ new_flag = "-#{c.chr}"
558
557
 
559
- flag_alias = nil
558
+ flag_alias = nil
560
559
 
561
560
  # special case where the flag's actual name is short form and found here
562
561
  flag_alias ||= specifications.detect { |s| s.is_a?(CLASP::FlagSpecification) && s.name == new_flag }
@@ -566,11 +565,11 @@ class Arguments
566
565
 
567
566
  if not flag_alias
568
567
 
569
- flag_aliases = nil
568
+ flag_aliases = nil
570
569
  break
571
570
  else
572
571
 
573
- flag_aliases << flag_alias
572
+ flag_aliases << flag_alias
574
573
  end
575
574
  end
576
575
 
@@ -583,7 +582,7 @@ class Arguments
583
582
  # convert to argv and invoke
584
583
  flags_argv = flag_aliases.map { |s| s.name }
585
584
 
586
- grp_flags, grp_options, grp_value, grp_double_slash_index = Arguments.parse_(flags_argv, specifications)
585
+ grp_flags, grp_options, grp_value, _grp_double_slash_index = Arguments.parse_(flags_argv, specifications)
587
586
 
588
587
  grp_flags.map! { |f| FlagArgument.new(arg, index, given_name, f.name, f.argument_specification, hyphens.size, given_label, argument_spec ? argument_spec.extras : nil) }
589
588
  grp_options.map! { |o| OptionArgument.new(arg, index, given_name, o.name, o.argument_specification, hyphens.size, given_label, o.value, argument_spec ? argument_spec.extras : nil) }
@@ -632,8 +631,8 @@ class Arguments
632
631
  next unless forced_value
633
632
  end
634
633
 
635
- arg = arg.dup
636
- arg_ix = ::Integer === index ? index : index.dup
634
+ arg = arg.dup
635
+ arg_ix = ::Integer === index ? index : index.dup
637
636
 
638
637
  arg.define_singleton_method(:given_index) { arg_ix }
639
638
 
@@ -761,9 +760,9 @@ class Arguments
761
760
  # backwards-compatible
762
761
 
763
762
  # @!visibility private
764
- Flag = FlagArgument # :nodoc:
763
+ Flag = FlagArgument # :nodoc:
765
764
  # @!visibility private
766
- Option = OptionArgument # :nodoc:
765
+ Option = OptionArgument # :nodoc:
767
766
  end # class Arguments
768
767
 
769
768
 
data/lib/clasp/clasp.rb CHANGED
@@ -1,17 +1,18 @@
1
1
 
2
2
  # ######################################################################## #
3
- # File: clasp/clasp.rb
3
+ # File: clasp/clasp.rb
4
4
  #
5
- # Purpose: Common 'require file' for CLASP.Ruby library
5
+ # Purpose: Common 'require file' for CLASP.Ruby library
6
6
  #
7
- # Created: 14th February 2014
8
- # Updated: 20th January 2024
7
+ # Created: 14th February 2014
8
+ # Updated: 6th March 2025
9
9
  #
10
- # Home: http://github.com/synesissoftware/CLASP.Ruby
10
+ # Home: http://github.com/synesissoftware/CLASP.Ruby
11
11
  #
12
- # Author: Matthew Wilson
12
+ # Author: Matthew Wilson
13
13
  #
14
- # Copyright (c) 2014-2024, Matthew Wilson and Synesis Software
14
+ # Copyright (c) 2019-2025, Matthew Wilson and Synesis Information Systems
15
+ # Copyright (c) 2014-2019, Matthew Wilson and Synesis Software
15
16
  # All rights reserved.
16
17
  #
17
18
  # Redistribution and use in source and binary forms, with or without
@@ -50,13 +51,16 @@ require 'clasp/specifications'
50
51
  require 'clasp/cli'
51
52
  require 'clasp/version'
52
53
 
54
+ =begin
55
+ =end
56
+
53
57
  module CLASP
54
58
 
55
- # TBC (but is a shorthand for calling +Arguments.new()+
56
- def self.parse(argv = ARGV, specifications = nil, options = {})
59
+ # TBC (but is a shorthand for calling +Arguments.new()+
60
+ def self.parse(argv = ARGV, specifications = nil, options = {})
57
61
 
58
- return Arguments.new(argv, specifications, options)
59
- end
62
+ return Arguments.new(argv, specifications, options)
63
+ end
60
64
  end # module CLASP
61
65
 
62
66