libclimate-ruby 0.16.0.1 → 0.17.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c1e94d5cc4ba07147cf90cdd5a0429d30bef55324228eac1c27246020f35b267
4
- data.tar.gz: 0fbd451ec141cdaeb5e6f2d4f720d970d0287bbc24140a9c90957a1fbd247d8a
3
+ metadata.gz: 93f46385f402db50a58439b942019ed126dd63473b62a26e838891bc0df15fb1
4
+ data.tar.gz: b38cc0a266ca7aea7ff3bef2e5532c99b92cf4fe5a6cacd2ddd48d98f61451ae
5
5
  SHA512:
6
- metadata.gz: e56af8baca9f1278d41f9efa9acc8a4cd7fed0736592f875415874078a341bfbbf9c1563daa0f7bc7c2b8eeb1c4f683ad19b1c74ac27903ec6c4af73344bbddb
7
- data.tar.gz: 8ac03e855c3f425857aa9fee828c637a7368cff1af1ce82ef167d3b111f74d37dc3b0d3a42d279c517a51a3ccac7dbcdf7ad7bc41d626d3eb8cd08172644707b
6
+ metadata.gz: 8676f6ed6c9ad75d9fa713139e825a3f3fb3e757a8b5d416995b8989b160a32e2c16f2ecb1b3b79d32f12bcc325073be42bfeb867bdb47f314c53f1444e22bae
7
+ data.tar.gz: 1cc2874f4963d361c6e756a314508787baf7fafc0a5175c9174a6b4efc5dcd89e469f1f89c855d302e6d4e14cc36e2f954aea6c9c74e491e34d7a2985b4860ce
@@ -1,17 +1,17 @@
1
1
 
2
2
  # ######################################################################## #
3
- # File: lib/libclimate/climate.rb
3
+ # File: lib/libclimate/climate.rb
4
4
  #
5
- # Purpose: Definition of the ::LibCLImate::Climate class
5
+ # Purpose: Definition of the ::LibCLImate::Climate class
6
6
  #
7
- # Created: 13th July 2015
8
- # Updated: 24th July 2022
7
+ # Created: 13th July 2015
8
+ # Updated: 10th August 2024
9
9
  #
10
- # Home: http://github.com/synesissoftware/libCLImate.Ruby
10
+ # Home: http://github.com/synesissoftware/libCLImate.Ruby
11
11
  #
12
- # Author: Matthew Wilson
12
+ # Author: Matthew Wilson
13
13
  #
14
- # Copyright (c) 2019-2022, Matthew Wilson and Synesis Information Systems
14
+ # Copyright (c) 2019-2024, Matthew Wilson and Synesis Information Systems
15
15
  # Copyright (c) 2015-2019, Matthew Wilson and Synesis Software
16
16
  # All rights reserved.
17
17
  #
@@ -144,7 +144,7 @@ module LibCLImate
144
144
  #
145
145
  # program_options = {}
146
146
  #
147
- # climate = LibCLImate::Climate.new do |cl|
147
+ # climate = LibCLImate::Climate.new(value_attributes: true) do |cl|
148
148
  #
149
149
  # cl.add_flag('--verbose', alias: '-v', help: 'Makes program output verbose') { program_options[:verbose] = true }
150
150
  #
@@ -153,8 +153,9 @@ module LibCLImate
153
153
  # program_options[:flavour] = check_flavour(o.value) or cl.abort "Invalid flavour '#{o.value}'; use --help for usage"
154
154
  # end
155
155
  #
156
- # cl.usage_values = '<value-1> [ ... <value-N> ]'
157
- # cl.constrain_values = 1..100000
156
+ # cl.usage_values = '<source-path> [ <destination-path> ]'
157
+ # cl.constrain_values = 1..2
158
+ # cl.value_names = %w{ source-path destination-path }
158
159
  #
159
160
  # cl.info_lines = [
160
161
  #
@@ -164,6 +165,10 @@ module LibCLImate
164
165
  # ]
165
166
  # end
166
167
  #
168
+ # r = climate.run ARGV
169
+ #
170
+ # puts "copying from '#{r.source_path}' to '#{r.destination_path || '.'}'"
171
+ #
167
172
  class Climate
168
173
 
169
174
  include ::Xqsr3::Quality::ParameterChecking
@@ -789,6 +794,7 @@ class Climate
789
794
  # - +:no_help_flag+ (boolean) Prevents the use of the +CLASP::Flag.Help+ flag-specification
790
795
  # - +:no_version_flag+ (boolean) Prevents the use of the +CLASP::Flag.Version+ flag-specification
791
796
  # - +:program_name+ (::String) An explicit program-name, which is inferred from +$0+ if this is +nil+
797
+ # - +:value_attributes+ (boolean) Causes any possible value-names, as described in `#value_names`, to be applied as attributes with the given values, if any, on the command-line
792
798
  # - +:version+ (String, [Integer], [String]) A version specification. If not specified, this is inferred
793
799
  # - +:version_context+ Object or class that defines a context for searching the version. Ignored if +:version+ is specified
794
800
  #
@@ -830,6 +836,8 @@ class Climate
830
836
  version_context = options[:version_context]
831
837
  @version = options[:version] || infer_version_(version_context)
832
838
 
839
+ @value_attributes = options[:value_attributes]
840
+
833
841
  unless options[:no_help_flag]
834
842
 
835
843
  f = CLASP::Flag.Help()
@@ -929,7 +937,7 @@ class Climate
929
937
  #
930
938
  # === Returns
931
939
  # (ParseResults) Results
932
- def parse(argv = ARGV) # :yields: ParseResults
940
+ def parse(argv = ARGV, **options) # :yields: ParseResults
933
941
 
934
942
  raise ArgumentError, "argv may not be nil" if argv.nil?
935
943
 
@@ -957,7 +965,7 @@ class Climate
957
965
  # (ParseResults) Results
958
966
  def parse_and_verify(argv = ARGV, **options) # :yields: ParseResults
959
967
 
960
- r = parse argv
968
+ r = parse argv, **options
961
969
 
962
970
  r.verify(**options)
963
971
 
@@ -976,17 +984,17 @@ class Climate
976
984
  # an instance of a type derived from +::Hash+ with the additional
977
985
  # attributes +flags+, +options+, +values+, +double_slash_index+ and
978
986
  # +argv+.
979
- def run(argv = ARGV) # :yields: customised +::Hash+
987
+ def run(argv = ARGV, **options) # :yields: customised +::Hash+
980
988
 
981
989
  raise ArgumentError, "argv may not be nil" if argv.nil?
982
990
 
983
991
  arguments = CLASP::Arguments.new argv, specifications
984
992
 
985
- run_ argv, arguments
993
+ run_ argv, arguments, **options
986
994
  end
987
995
 
988
996
  private
989
- def run_(argv, arguments) # :nodoc:
997
+ def run_(argv, arguments, **opts) # :nodoc:
990
998
 
991
999
  flags = arguments.flags
992
1000
  options = arguments.options
@@ -1154,6 +1162,31 @@ class Climate
1154
1162
  argv
1155
1163
  end
1156
1164
 
1165
+
1166
+ if opts[:value_attributes] || @value_attributes
1167
+
1168
+ (value_names || []).each_with_index do |name, index|
1169
+
1170
+ name = name.gsub(/-/, '_').to_sym
1171
+
1172
+ if results.respond_to? name
1173
+
1174
+ warn "cannot create attribute `#{name}` on instance of `#{results.class}` because that name is already used"
1175
+ else
1176
+
1177
+ value = results.values[index]
1178
+
1179
+ results.define_singleton_method(name) do
1180
+
1181
+ value
1182
+ end
1183
+ end
1184
+ end
1185
+ end
1186
+
1187
+
1188
+ results.freeze
1189
+
1157
1190
  results
1158
1191
  end
1159
1192
  public
@@ -1396,6 +1429,7 @@ class Climate
1396
1429
  end # class Climate
1397
1430
  end # module LibCLImate
1398
1431
 
1432
+
1399
1433
  # ############################## end of file ############################# #
1400
1434
 
1401
1435
 
@@ -1,14 +1,14 @@
1
1
  # ######################################################################## #
2
- # File: libclimate/libclimate.rb
2
+ # File: libclimate/libclimate.rb
3
3
  #
4
- # Purpose: Main file for libclimate.Ruby library
4
+ # Purpose: Main file for libclimate.Ruby library
5
5
  #
6
- # Created: 13th July 2015
7
- # Updated: 13th April 2019
6
+ # Created: 13th July 2015
7
+ # Updated: 10th August 2024
8
8
  #
9
- # Home: http://github.com/synesissoftware/libCLImate.Ruby
9
+ # Home: http://github.com/synesissoftware/libCLImate.Ruby
10
10
  #
11
- # Copyright (c) 2015-2019, Matthew Wilson and Synesis Software
11
+ # Copyright (c) 2015-2024, Matthew Wilson and Synesis Software
12
12
  # All rights reserved.
13
13
  #
14
14
  # Redistribution and use in source and binary forms, with or without
@@ -50,6 +50,7 @@ require 'libclimate/version'
50
50
  module LibCLImate
51
51
  end # module LibCLImate
52
52
 
53
+
53
54
  # ############################## end of file ############################# #
54
55
 
55
56
 
@@ -1,14 +1,14 @@
1
1
  # ######################################################################## #
2
- # File: libclimate/version.rb
2
+ # File: libclimate/version.rb
3
3
  #
4
- # Purpose: Version for libclimate.Ruby library
4
+ # Purpose: Version for libclimate.Ruby library
5
5
  #
6
- # Created: 13th July 2015
7
- # Updated: 1st December 2023
6
+ # Created: 13th July 2015
7
+ # Updated: 10th August 2024
8
8
  #
9
- # Home: http://github.com/synesissoftware/libCLImate.Ruby
9
+ # Home: http://github.com/synesissoftware/libCLImate.Ruby
10
10
  #
11
- # Copyright (c) 2019-2023, Matthew Wilson and Synesis Information Systems
11
+ # Copyright (c) 2019-2024, Matthew Wilson and Synesis Information Systems
12
12
  # Copyright (c) 2015-2019, Matthew Wilson and Synesis Software
13
13
  # All rights reserved.
14
14
  #
@@ -44,7 +44,7 @@
44
44
  module LibCLImate
45
45
 
46
46
  # Current version of the libCLImate.Ruby library
47
- VERSION = '0.16.0.1'
47
+ VERSION = '0.17.0'
48
48
 
49
49
  private
50
50
  VERSION_PARTS_ = VERSION.split(/[.]/).collect { |n| n.to_i } # :nodoc:
@@ -55,9 +55,9 @@ module LibCLImate
55
55
  VERSION_MINOR = VERSION_PARTS_[1] # :nodoc:
56
56
  # # Revision version of the libCLImate.Ruby library
57
57
  VERSION_REVISION = VERSION_PARTS_[2] # :nodoc:
58
-
59
58
  end # module LibCLImate
60
59
 
60
+
61
61
  # ############################## end of file ############################# #
62
62
 
63
63
 
@@ -92,7 +92,7 @@ class Test_Climate_values_constraints < Test::Unit::TestCase
92
92
  stdout = StringIO.new
93
93
  stderr = StringIO.new
94
94
 
95
- climate = LibCLImate::Climate.new do |cl|
95
+ climate = LibCLImate::Climate.new(value_attributes: true) do |cl|
96
96
 
97
97
  cl.exit_on_missing = false
98
98
 
@@ -129,6 +129,67 @@ class Test_Climate_values_constraints < Test::Unit::TestCase
129
129
  assert_equal 2, r.values.size
130
130
  assert_empty stdout.string
131
131
  assert_empty stderr.string
132
+ assert r.respond_to? :input_path
133
+ assert r.respond_to? :output_path
134
+
135
+ stdout.string = ''
136
+ stderr.string = ''
137
+ r = climate.run [ 'value-1', 'value-2', 'value-3' ]
138
+ assert_equal 3, r.values.size
139
+ assert_empty stdout.string
140
+ assert_not_empty stderr.string
141
+ assert_match /wrong number of values.*3 given.*2 required.*/, stderr.string
142
+ end
143
+
144
+ def test_constrain_with_integer_and_names_2
145
+
146
+ stdout = StringIO.new
147
+ stderr = StringIO.new
148
+
149
+ climate = LibCLImate::Climate.new(value_attributes: true) do |cl|
150
+
151
+ cl.exit_on_missing = false
152
+
153
+ cl.stdout = stdout
154
+ cl.stderr = stderr
155
+
156
+ cl.constrain_values = 1..2
157
+ cl.value_names = [
158
+
159
+ 'input-path',
160
+ 'output-path',
161
+ ]
162
+ end
163
+
164
+ stdout.string = ''
165
+ stderr.string = ''
166
+ r = climate.run [ ]
167
+ assert_equal 0, r.values.size
168
+ assert_empty stdout.string
169
+ assert_not_empty stderr.string
170
+ assert_match /input-path not specified.*#{climate.usage_help_suffix}/, stderr.string
171
+
172
+ stdout.string = ''
173
+ stderr.string = ''
174
+ r = climate.run [ 'value-1' ]
175
+ assert_equal 1, r.values.size
176
+ assert_empty stdout.string
177
+ assert_empty stderr.string
178
+ assert r.respond_to? :input_path
179
+ assert r.respond_to? :output_path
180
+ assert_equal 'value-1', r.input_path
181
+ assert_nil r.output_path
182
+
183
+ stdout.string = ''
184
+ stderr.string = ''
185
+ r = climate.run [ 'value-1', 'value-2' ]
186
+ assert_equal 2, r.values.size
187
+ assert_empty stdout.string
188
+ assert_empty stderr.string
189
+ assert r.respond_to? :input_path
190
+ assert r.respond_to? :output_path
191
+ assert_equal 'value-1', r.input_path
192
+ assert_equal 'value-2', r.output_path
132
193
 
133
194
  stdout.string = ''
134
195
  stderr.string = ''
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: libclimate-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.0.1
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Wilson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-12-01 00:00:00.000000000 Z
11
+ date: 2024-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clasp-ruby
@@ -17,6 +17,9 @@ dependencies:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0.23'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.23.0.2
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -24,26 +27,23 @@ dependencies:
24
27
  - - "~>"
25
28
  - !ruby/object:Gem::Version
26
29
  version: '0.23'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 0.23.0.2
27
33
  - !ruby/object:Gem::Dependency
28
34
  name: xqsr3
29
35
  requirement: !ruby/object:Gem::Requirement
30
36
  requirements:
31
37
  - - "~>"
32
38
  - !ruby/object:Gem::Version
33
- version: '0.37'
34
- - - ">="
35
- - !ruby/object:Gem::Version
36
- version: 0.37.3
39
+ version: '0.39'
37
40
  type: :runtime
38
41
  prerelease: false
39
42
  version_requirements: !ruby/object:Gem::Requirement
40
43
  requirements:
41
44
  - - "~>"
42
45
  - !ruby/object:Gem::Version
43
- version: '0.37'
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: 0.37.3
46
+ version: '0.39'
47
47
  description: |
48
48
  libCLImate is a portable, lightweight mini-framework that encapsulates the common aspects of Command-Line Interface boilerplate, including:
49
49