clasp-ruby 0.23.0.1 → 0.23.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +63 -52
  3. data/examples/cr-example.rb +16 -16
  4. data/examples/flag_and_option_specifications.md +25 -25
  5. data/examples/flag_and_option_specifications.rb +6 -6
  6. data/examples/show_usage_and_version.md +5 -5
  7. data/examples/show_usage_and_version.rb +1 -1
  8. data/examples/simple_command_line_no_specifications.rb +1 -1
  9. data/lib/clasp/arguments.rb +538 -537
  10. data/lib/clasp/clasp.rb +7 -7
  11. data/lib/clasp/cli.rb +140 -135
  12. data/lib/clasp/doc_.rb +3 -3
  13. data/lib/clasp/old_module.rb +3 -3
  14. data/lib/clasp/specifications.rb +337 -333
  15. data/lib/clasp/util/exceptions.rb +17 -17
  16. data/lib/clasp/util/value_parser.rb +97 -97
  17. data/lib/clasp/version.rb +15 -15
  18. data/lib/clasp-ruby.rb +3 -2
  19. data/lib/clasp.rb +3 -2
  20. data/test/scratch/test_list_command_line.rb +6 -6
  21. data/test/scratch/test_specifications.rb +14 -14
  22. data/test/scratch/test_usage.rb +6 -6
  23. data/test/scratch/test_usage_from_DATA.rb +1 -1
  24. data/test/scratch/test_usage_with_duplicate_specifications.rb +6 -6
  25. data/test/unit/tc_ARGV_rewrite.rb +36 -38
  26. data/test/unit/tc_arguments_1.rb +694 -694
  27. data/test/unit/tc_arguments_2.rb +52 -53
  28. data/test/unit/tc_arguments_3.rb +77 -77
  29. data/test/unit/tc_arguments_inspect.rb +55 -56
  30. data/test/unit/tc_cli.rb +4 -4
  31. data/test/unit/tc_default_value.rb +91 -91
  32. data/test/unit/tc_defaults_1.rb +38 -38
  33. data/test/unit/tc_examples_Arguments.rb +130 -132
  34. data/test/unit/tc_extras.rb +24 -26
  35. data/test/unit/tc_option_required.rb +38 -39
  36. data/test/unit/tc_option_value_aliases.rb +44 -44
  37. data/test/unit/tc_specifications.rb +7 -8
  38. data/test/unit/tc_typed_options.rb +204 -204
  39. data/test/unit/tc_usage.rb +112 -55
  40. data/test/unit/tc_with_action.rb +23 -24
  41. data/test/unit/ts_all.rb +1 -1
  42. metadata +5 -4
@@ -10,101 +10,158 @@ require 'stringio'
10
10
 
11
11
  class Test_Usage < Test::Unit::TestCase
12
12
 
13
- def test_empty_default
13
+ def test_empty_default
14
14
 
15
- specifications = []
15
+ specifications = []
16
16
 
17
- stream = StringIO.new
17
+ stream = StringIO.new
18
18
 
19
- CLASP.show_usage specifications, stream: stream, program_name: 'myprog'
19
+ CLASP.show_usage specifications, stream: stream, program_name: 'myprog'
20
20
 
21
- assert_equal "USAGE: myprog [ ... flags and options ... ]\n\n", stream.string
22
- end
21
+ expected = <<EOF_output
22
+ USAGE: myprog [ ... flags and options ... ]
23
23
 
24
- def test_empty_all
24
+ EOF_output
25
+ actual = stream.string
25
26
 
26
- specifications = []
27
+ assert_equal expected, actual
28
+ end
27
29
 
28
- stream = StringIO.new
30
+ def test_empty_all
29
31
 
30
- CLASP.show_usage specifications, stream: stream, program_name: 'myprog', flags_and_options: ''
32
+ specifications = []
31
33
 
32
- assert_equal "USAGE: myprog\n\n", stream.string
33
- end
34
+ stream = StringIO.new
34
35
 
35
- def test_empty_all_with_info_line_of_one_string
36
+ CLASP.show_usage specifications, stream: stream, program_name: 'myprog', flags_and_options: ''
36
37
 
37
- specifications = []
38
+ expected = <<EOF_output
39
+ USAGE: myprog
38
40
 
39
- stream = StringIO.new
41
+ EOF_output
42
+ actual = stream.string
40
43
 
41
- info = 'myprog version'.freeze
44
+ assert_equal expected, actual
45
+ end
42
46
 
43
- CLASP.show_usage specifications, stream: stream, program_name: 'myprog', flags_and_options: '', info_lines: info
47
+ def test_empty_all_with_info_line_of_one_string
44
48
 
45
- assert_equal "myprog version\nUSAGE: myprog\n\n", stream.string
46
- end
49
+ specifications = []
47
50
 
48
- def test_empty_all_with_info_lines
51
+ stream = StringIO.new
49
52
 
50
- specifications = []
53
+ info = 'myprog version'.freeze
51
54
 
52
- stream = StringIO.new
55
+ CLASP.show_usage specifications, stream: stream, program_name: 'myprog', flags_and_options: '', info_lines: info
53
56
 
54
- info_lines = [
57
+ expected = <<EOF_output
58
+ myprog version
59
+ USAGE: myprog
55
60
 
56
- 'Synesis Software My Program',
57
- 'version 1',
58
- ].freeze
61
+ EOF_output
62
+ actual = stream.string
59
63
 
60
- CLASP.show_usage specifications, stream: stream, program_name: 'myprog', flags_and_options: '', info_lines: info_lines
64
+ assert_equal expected, actual
65
+ end
61
66
 
62
- assert_equal "Synesis Software My Program\nversion 1\nUSAGE: myprog\n\n", stream.string
63
- end
67
+ def test_empty_all_with_info_lines
64
68
 
65
- def test_empty_all_with_info_lines_including_version
69
+ specifications = []
66
70
 
67
- specifications = []
71
+ stream = StringIO.new
68
72
 
69
- stream = StringIO.new
73
+ info_lines = [
70
74
 
71
- info_lines = [
75
+ 'Synesis Software My Program',
76
+ 'version 1',
77
+ ].freeze
72
78
 
73
- 'Synesis Software My Program',
74
- :version
75
- ].freeze
79
+ CLASP.show_usage specifications, stream: stream, program_name: 'myprog', flags_and_options: '', info_lines: info_lines
76
80
 
77
- CLASP.show_usage specifications, stream: stream, program_name: 'myprog', flags_and_options: '', info_lines: info_lines, version: [ 1, 0, 1], version_prefix: 'v'
81
+ expected = <<EOF_output
82
+ Synesis Software My Program
83
+ version 1
84
+ USAGE: myprog
78
85
 
79
- assert_equal "Synesis Software My Program\nmyprog v1.0.1\nUSAGE: myprog\n\n", stream.string
80
- end
86
+ EOF_output
87
+ actual = stream.string
81
88
 
82
- def test_one_alias_default
89
+ assert_equal expected, actual
90
+ end
83
91
 
84
- specifications = [
92
+ def test_empty_all_with_info_lines_including_version
85
93
 
86
- CLASP::Flag.Version
87
- ]
94
+ specifications = []
88
95
 
89
- stream = StringIO.new
96
+ stream = StringIO.new
90
97
 
91
- CLASP.show_usage specifications, stream: stream, program_name: 'myprog'
98
+ info_lines = [
92
99
 
93
- assert_equal "USAGE: myprog [ ... flags and options ... ]\n\nflags/options:\n\n\t--version\n\t\t#{CLASP::Flag.Version.help}\n\n", stream.string
94
- end
100
+ 'Synesis Software My Program',
101
+ :version
102
+ ].freeze
95
103
 
96
- def test_one_alias_all
104
+ CLASP.show_usage specifications, stream: stream, program_name: 'myprog', flags_and_options: '', info_lines: info_lines, version: [ 1, 0, 1], version_prefix: 'v'
97
105
 
98
- specifications = [
106
+ expected = <<EOF_output
107
+ Synesis Software My Program
108
+ myprog v1.0.1
109
+ USAGE: myprog
99
110
 
100
- CLASP::Flag.Version
101
- ]
111
+ EOF_output
112
+ actual = stream.string
102
113
 
103
- stream = StringIO.new
114
+ assert_equal expected, actual
115
+ end
104
116
 
105
- CLASP.show_usage specifications, stream: stream, program_name: 'myprog', flags_and_options: ''
117
+ def test_one_alias_default
106
118
 
107
- assert_equal "USAGE: myprog\n\nflags/options:\n\n\t--version\n\t\t#{CLASP::Flag.Version.help}\n\n", stream.string
108
- end
119
+ specifications = [
120
+
121
+ CLASP::Flag.Version
122
+ ]
123
+
124
+ stream = StringIO.new
125
+
126
+ CLASP.show_usage specifications, stream: stream, program_name: 'myprog'
127
+
128
+ expected = <<EOF_output
129
+ USAGE: myprog [ ... flags and options ... ]
130
+
131
+ flags/options:
132
+
133
+ \t--version
134
+ \t\t#{CLASP::Flag.Version.help}
135
+
136
+ EOF_output
137
+ actual = stream.string
138
+
139
+ assert_equal expected, actual
140
+ end
141
+
142
+ def test_one_alias_all
143
+
144
+ specifications = [
145
+
146
+ CLASP::Flag.Version
147
+ ]
148
+
149
+ stream = StringIO.new
150
+
151
+ CLASP.show_usage specifications, stream: stream, program_name: 'myprog', flags_and_options: ''
152
+
153
+ expected = <<EOF_output
154
+ USAGE: myprog
155
+
156
+ flags/options:
157
+
158
+ \t--version
159
+ \t\t#{CLASP::Flag.Version.help}
160
+
161
+ EOF_output
162
+ actual = stream.string
163
+
164
+ assert_equal expected, actual
165
+ end
109
166
  end
110
167
 
@@ -10,41 +10,40 @@ require 'test/unit'
10
10
 
11
11
  class Test_WithAction < Test::Unit::TestCase
12
12
 
13
- def test_flag_with_action
13
+ def test_flag_with_action
14
14
 
15
- debug = false
15
+ debug = false
16
16
 
17
- specifications = [
17
+ specifications = [
18
18
 
19
- CLASP.Flag('--debug', alias: '-d') { debug = true }
20
- ]
21
- argv = []
22
- args = CLASP.parse argv, specifications
19
+ CLASP.Flag('--debug', alias: '-d') { debug = true }
20
+ ]
21
+ argv = []
22
+ args = CLASP.parse argv, specifications
23
23
 
24
- assert_equal 0, args.flags.size
25
- assert_equal 0, args.options.size
26
- assert_equal 0, args.values.size
24
+ assert_equal 0, args.flags.size
25
+ assert_equal 0, args.options.size
26
+ assert_equal 0, args.values.size
27
27
 
28
- assert_false debug
28
+ assert_false debug
29
29
 
30
- argv2 = [ '--debug' ]
31
- args2 = CLASP.parse argv2, specifications
30
+ argv2 = [ '--debug' ]
31
+ args2 = CLASP.parse argv2, specifications
32
32
 
33
- assert_equal 1, args2.flags.size
34
- assert_equal 0, args2.options.size
35
- assert_equal 0, args2.values.size
33
+ assert_equal 1, args2.flags.size
34
+ assert_equal 0, args2.options.size
35
+ assert_equal 0, args2.values.size
36
36
 
37
- assert_false debug
37
+ assert_false debug
38
38
 
39
- if ix = args2.flags.index('--debug')
39
+ if ix = args2.flags.index('--debug')
40
40
 
41
- flag = args2.flags[ix]
41
+ flag = args2.flags[ix]
42
42
 
43
- flag.argument_specification.action.call(flag, flag.argument_specification)
44
- end
43
+ flag.argument_specification.action.call(flag, flag.argument_specification)
44
+ end
45
45
 
46
- assert_true debug
47
- end
46
+ assert_true debug
47
+ end
48
48
  end
49
49
 
50
-
data/test/unit/ts_all.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  #
3
3
  # executes all other tests
4
4
 
5
- this_dir = File.expand_path(File.dirname(__FILE__))
5
+ this_dir = File.expand_path(File.dirname(__FILE__))
6
6
 
7
7
  # all tc_*rb in current directory
8
8
  Dir[File.join(this_dir, 'tc_*rb')].each { |file| require file }
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.23.0.1
4
+ version: 0.23.0.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: 2023-12-01 00:00:00.000000000 Z
11
+ date: 2024-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xqsr3
@@ -25,8 +25,9 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0.38'
27
27
  description: |
28
- Command-Line Argument Sorting and Parsing library that provides a powerful
29
- abstraction of command-line interpretation facilities. CLASP.Ruby is a Ruby port of the popular CLASP (C/C++) library, and provides declarative specification of command-line flags and options, aliasing, flag combination, UNIX de-facto standard flag processing, and a number of utility functions for expressing usage and version information.
28
+ Command-Line Argument Sorting and Parsing library that provides a powerful abstraction of command-line interpretation facilities.
29
+
30
+ CLASP.Ruby is a Ruby port of the popular CLASP (C/C++) library, and provides declarative specification of command-line flags and options, aliasing, flag combination, UNIX de-facto standard flag processing, and a number of utility functions for expressing usage and version information.
30
31
  email: matthew@synesis.com.au
31
32
  executables: []
32
33
  extensions: []