cli-dispatcher 1.2.1 → 1.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/cli-dispatcher.rb +33 -10
- data/lib/structured.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1f11805cc9ecff05fe987fe958cb4b6bf6a3a49d2a56596ff0eee761936b3ce3
|
4
|
+
data.tar.gz: aac95196261ffb6835e1ca0220c5786f260f71bd8f9e904eaa7a824943cacd04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2a65276ba20ff7532ea71aff7219ade85ec908a317a8753740b42f1531283269e78df415ac6dbb607bfd009800e6e94cdd3692f01c2344b0c4653791455658b
|
7
|
+
data.tar.gz: f2ec39cb1df8e03763a8b7b1a70fc01efa696d16df14f593abd8f80acdbd1c54359d05b99104837245be76d9b665896fa24665928ef025bc1bb149110b19c92a
|
data/lib/cli-dispatcher.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'optparse'
|
2
|
+
require 'texttools'
|
2
3
|
|
3
4
|
#
|
4
5
|
# Constructs a program that can operate a number of user-provided commands. To
|
@@ -6,18 +7,23 @@ require 'optparse'
|
|
6
7
|
#
|
7
8
|
# def cmd_name(args...)
|
8
9
|
#
|
9
|
-
# Then create an instance of the class and call one of the dispatch methods
|
10
|
+
# Then create an instance of the class and call one of the dispatch methods,
|
11
|
+
# typically:
|
10
12
|
#
|
11
|
-
#
|
13
|
+
# [DispatcherSubclass].new.dispatch_argv
|
12
14
|
#
|
13
|
-
#
|
15
|
+
# To provide help and/or a category for a command, define the methods
|
14
16
|
#
|
15
|
-
#
|
16
|
-
#
|
17
|
+
# def help_name; [string] end
|
18
|
+
# def cat_name; [string] end
|
19
|
+
#
|
20
|
+
# For the help command, the first line should be a short description of the
|
21
|
+
# command, which will be used in a summary table describing the command. For the
|
22
|
+
# category, all commands with the same category will be grouped together in the
|
23
|
+
# help summary display.
|
17
24
|
#
|
18
25
|
# This class incorporates optparse, providing the commands setup_options and
|
19
|
-
# add_options to pass
|
20
|
-
# through options specifications.
|
26
|
+
# add_options to pass through options specifications.
|
21
27
|
#
|
22
28
|
class Dispatcher
|
23
29
|
|
@@ -118,11 +124,28 @@ class Dispatcher
|
|
118
124
|
warn("Run 'help [command]' for further help on that command.")
|
119
125
|
warn("")
|
120
126
|
|
121
|
-
methods.map { |m|
|
127
|
+
grouped_methods = methods.map { |m|
|
122
128
|
s = m.to_s
|
123
129
|
s.start_with?("cmd_") ? s.delete_prefix("cmd_") : nil
|
124
|
-
}.compact.
|
125
|
-
|
130
|
+
}.compact.group_by { |m|
|
131
|
+
cat_m = "cat_#{m}".to_sym
|
132
|
+
respond_to?(cat_m) ? send(cat_m) : nil
|
133
|
+
}
|
134
|
+
help_cmds(grouped_methods.delete(nil)) if grouped_methods.include?(nil)
|
135
|
+
|
136
|
+
grouped_methods.sort.each do |cat, cmds|
|
137
|
+
warn("\n#{cat}\n\n")
|
138
|
+
help_cmds(cmds)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
def help_cmds(cmds)
|
143
|
+
cmds.sort.each do |cmd|
|
144
|
+
warn(TextTools.line_break(
|
145
|
+
help_string(cmd, all: false),
|
146
|
+
prefix: " " * 11,
|
147
|
+
first_prefix: cmd.ljust(10) + ' ',
|
148
|
+
))
|
126
149
|
end
|
127
150
|
end
|
128
151
|
|
data/lib/structured.rb
CHANGED
@@ -561,7 +561,7 @@ module Structured
|
|
561
561
|
# returned, and processing should also stop.
|
562
562
|
#
|
563
563
|
def process_nil_val(val, data)
|
564
|
-
return [ val, false ]
|
564
|
+
return [ val, false ] unless val.nil?
|
565
565
|
unless data[:optional]
|
566
566
|
input_err("Required element is missing (or was deleted by a preproc)")
|
567
567
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: cli-dispatcher
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Charles Duan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-01-14 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
Library for creating command-line programs that accept commands. Also
|