cli-dispatcher 1.2.6 → 1.2.8

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: be7440d7ccb3b1dfd9b90eae4b32d62597a864e4dd6676deaf9dc36e08d08470
4
- data.tar.gz: 3338fab7655d4074368786f822ffac62c9b12d3e74ea98ef7bc554f44b248e93
3
+ metadata.gz: a74c717519d1436132b56f8785fbd3b8b8038f1be9066580c8b4f961945ee4f6
4
+ data.tar.gz: c2484c21170248bba3f244a395321ee7e500b99881a89060b8da6ac2aed56b6d
5
5
  SHA512:
6
- metadata.gz: 16e45a2046ebbd9679789549b53e15afb4b4cd556bf1857feb25e61c4d90f55a4bb4d555f242fc66af926550566aa4e75fcf5bd693133475c00070ffbc102b91
7
- data.tar.gz: 2f09de799fcca6242233880aa6452abf600e3d179f6ddd7b9b3d03747980d327e68e56cb8609264c3ac7b29397f5285d2264c4b96ef55c5d1eb4c74e05a26cb0
6
+ metadata.gz: e255a21bf5fd03c2431c51daabc933e7e18debe6f7bd6178146bf2b23c5069eb41ce681d7700b325a8cc01c46b4a5df5c1d8a9b9c3f221c14a848d6645814684
7
+ data.tar.gz: 5148804c936128ba58c545d935cefdc7f6b1c063acddd98227e18149e1ef19e993ba9ed35e5783f703d925ec4877de9dbbbfbc1f1af8b5148b674ede88202fa0
@@ -193,22 +193,58 @@ class Dispatcher
193
193
 
194
194
  #
195
195
  # Adds commands relevant when this dispatcher uses Structured data inputs.
196
+ # This method allows for generating documentation on Structured classes.
197
+ #
198
+ # The calling class should implement a method explain_classes that lists at
199
+ # least one Structured class that can be explained.
196
200
  #
197
201
  def self.add_structured_commands
198
202
  def help_explain
199
203
  return <<~EOF
200
204
  Displays an explanation of a Structured class.
201
205
 
202
- Use this to assist in generating or checking a Rubric file.
206
+ This will produce documentation on the elements permitted within the
207
+ class. If no class is given, then a listing of known Structured classes
208
+ is produced.
203
209
  EOF
204
210
  end
205
211
 
206
- def cmd_explain(class_name)
212
+ def cmd_explain(class_name = nil)
213
+ if class_name.nil?
214
+ cache = {}
215
+ puts "The following are Structured classes known to this program. Run"
216
+ puts "the command \"explain [class]\" for documentation on any of them."
217
+ puts
218
+ explain_classes.each do |c|
219
+ list_classes(c, cache)
220
+ end
221
+ return
222
+ end
223
+
207
224
  c = Object.const_get(class_name)
208
- unless c.is_a?(Class) && c.include?(Structured)
225
+ if c.is_a?(Class) && c.include?(Structured)
226
+ c.explain
227
+ else
209
228
  raise "Invalid class #{class_name}"
210
229
  end
211
- c.explain
230
+ end
231
+
232
+ unless defined? explain_classes
233
+ def explain_classes
234
+ return []
235
+ end
236
+ end
237
+
238
+ def list_classes(c, cache, level = 0)
239
+ unless c.include?(Structured)
240
+ raise "Cannot list classes of a non-Structured class"
241
+ end
242
+ puts((" " * level) + c.to_s)
243
+ return if cache.include?(c)
244
+ cache[c] = true
245
+ c.subtypes.each do |sc|
246
+ list_classes(sc, cache, level + 1)
247
+ end
212
248
  end
213
249
 
214
250
  def help_template
@@ -111,6 +111,10 @@ module StructuredPolymorphic
111
111
  end
112
112
  end
113
113
 
114
+ def subtypes
115
+ return @subclasses.values
116
+ end
117
+
114
118
  def template(indent: '')
115
119
  res = "#{indent}# #{name}\n"
116
120
  if @class_description
data/lib/structured.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require_relative 'texttools'
2
2
  require 'yaml'
3
+ require 'date'
3
4
 
4
5
  #
5
6
  # Sets up a class to receive an initializing hash and to populate information
@@ -649,21 +650,27 @@ module Structured
649
650
  #
650
651
  def try_autoconvert(type, item)
651
652
 
652
- if type == String && item.is_a?(Symbol)
653
+ case { item.class => type }
654
+
655
+ when { Symbol => String }
653
656
  return item.to_s
654
- end
655
657
 
656
- if type == Symbol && item.is_a?(String)
658
+ when { String => Symbol }
657
659
  return item.to_sym
658
- end
659
660
 
660
- # Special case in which strings will be converted to Regexps
661
- if type == Regexp && item.is_a?(String)
661
+ when { String => Regexp }
662
662
  begin
663
663
  return Regexp.new(item)
664
664
  rescue RegexpError
665
665
  input_err("#{item} is not a valid regular expression")
666
666
  end
667
+
668
+ when { String => Date }
669
+ begin
670
+ return Date.parse(item)
671
+ rescue Date::Error
672
+ input_err("#{item} is not a valid date")
673
+ end
667
674
  end
668
675
 
669
676
  return item
@@ -744,6 +751,18 @@ module Structured
744
751
  end
745
752
  end
746
753
 
754
+ #
755
+ # Returns a list of all Structured types that are in elements of this class.
756
+ #
757
+ def subtypes
758
+ datas = @elements.values
759
+ datas << @default_element if @default_element
760
+ return datas.map { |data|
761
+ data[:type].is_a?(Hash) ? data[:type].first : data[:type]
762
+ }.flatten.select { |c| c.is_a?(Class) && c.include?(Structured) }.uniq
763
+ end
764
+
765
+
747
766
  #
748
767
  # Produces a template YAML file for this Structured object.
749
768
  def template(indent: '')
metadata CHANGED
@@ -1,13 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cli-dispatcher
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.6
4
+ version: 1.2.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Charles Duan
8
+ autorequire:
8
9
  bindir: bin
9
10
  cert_chain: []
10
- date: 2025-12-04 00:00:00.000000000 Z
11
+ date: 2026-02-20 00:00:00.000000000 Z
11
12
  dependencies: []
12
13
  description: |
13
14
  Library for creating command-line programs that accept commands. Also
@@ -28,6 +29,7 @@ licenses:
28
29
  metadata:
29
30
  source_code_uri: https://github.com/charlesduan/cli-dispatcher
30
31
  documentation_uri: https://rubydoc.info/gems/cli-dispatcher/
32
+ post_install_message:
31
33
  rdoc_options: []
32
34
  require_paths:
33
35
  - lib
@@ -42,7 +44,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
42
44
  - !ruby/object:Gem::Version
43
45
  version: '0'
44
46
  requirements: []
45
- rubygems_version: 3.6.9
47
+ rubygems_version: 3.3.5
48
+ signing_key:
46
49
  specification_version: 4
47
50
  summary: Command-line command dispatcher
48
51
  test_files: []