appl 1.6.2 → 1.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 +4 -4
- data/bin/intar +18 -29
- data/doc/demoappl +3 -3
- data/doc/demofan +90 -0
- data/lib/appl.rb +47 -68
- data/lib/applfan.rb +81 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 799aaa0707086bc632ccb65a3edfd9adc5d8078e06f60114ffe01b92e086657d
|
4
|
+
data.tar.gz: 5283ca005a83855d096f2f5fca5015fd64afaa1df1e0348a0a5f814d33a66dcd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b7529480160d067b949652c5003e77864a5a358e45b1999713f770082f93cdf6ae70fa9886ba0b7b934b130e1b453931ba6396ad0296791628547bdaada6ddd
|
7
|
+
data.tar.gz: 62629af63de9b84692ff6e02eafad0601e13d9a3ed0b83ba294b83b37b0ca0f7a637135d89966f7a3e79b9b0d36d2328d0ba477a31144c31776e6b02bcf21786
|
data/bin/intar
CHANGED
@@ -28,33 +28,10 @@ class IntarApp < Application
|
|
28
28
|
|
29
29
|
EOT
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
Intar.show = s.to_i
|
36
|
-
end
|
37
|
-
def prompt= p
|
38
|
-
Intar.prompt = p if p
|
39
|
-
end
|
40
|
-
def bw!
|
41
|
-
Intar.colour = false
|
42
|
-
end
|
43
|
-
def catch_exit!
|
44
|
-
Intar.catch_exit = (Intar.catch_exit||0) + 3
|
45
|
-
end
|
46
|
-
def histall!
|
47
|
-
Intar.histhid = false
|
48
|
-
end
|
49
|
-
def histfile= h
|
50
|
-
Intar.histfile = nil_if_none h
|
51
|
-
end
|
52
|
-
def histmax= m
|
53
|
-
Intar.histmax = (Integer m rescue m.to_i)
|
54
|
-
end
|
55
|
-
def configfile= c
|
56
|
-
@configfile = nil_if_none c
|
57
|
-
end
|
31
|
+
attr_writer :show, :prompt, :histmax
|
32
|
+
def histfile= f ; @histfile = nil_if_none f ; end
|
33
|
+
def configfile= f ; @configfile = nil_if_none f ; end
|
34
|
+
attr_bang :quiet, :bw, :catch_exit, :histall
|
58
35
|
|
59
36
|
define_option "p", :prompt=, "STR",
|
60
37
|
"prompt - see source code for % escapes"
|
@@ -63,8 +40,8 @@ class IntarApp < Application
|
|
63
40
|
define_option "q", :quiet!, "don't show results"
|
64
41
|
alias_option "q", "quiet"
|
65
42
|
|
66
|
-
define_option "
|
67
|
-
alias_option "
|
43
|
+
define_option "s", :show=, "N", "show result line limit (0=all)"
|
44
|
+
alias_option "s", "show"
|
68
45
|
|
69
46
|
define_option "r", :require, "FILE", "Ruby require"
|
70
47
|
alias_option "r", "require"
|
@@ -103,6 +80,18 @@ class IntarApp < Application
|
|
103
80
|
def run
|
104
81
|
# @debug = true # Only development.
|
105
82
|
read_cfg
|
83
|
+
if @quiet then
|
84
|
+
Intar.show = 0
|
85
|
+
elsif @show then
|
86
|
+
Intar.show = Integer @show
|
87
|
+
end
|
88
|
+
Intar.prompt = @prompt if @prompt
|
89
|
+
Intar.colour = false if @bw
|
90
|
+
Intar.catch_exit = (Intar.catch_exit||0) + 3 if @catch_exit
|
91
|
+
Intar.histhid = false if @histall
|
92
|
+
Intar.histfile = @histfile if @histfile
|
93
|
+
Intar.histmax = Integer @histmax if @histmax
|
94
|
+
|
106
95
|
main = eval "self", TOPLEVEL_BINDING
|
107
96
|
Intar.open main do |i|
|
108
97
|
i.run *(@args.shift @args.length)
|
data/doc/demoappl
CHANGED
@@ -46,9 +46,9 @@ class DemoAppl < Application
|
|
46
46
|
define_option "V", :version, "show version information"
|
47
47
|
alias_option "V", "version"
|
48
48
|
|
49
|
-
|
50
|
-
|
51
|
-
UNPROCA = "Warning
|
49
|
+
STOPOPT = "Stop option processing"
|
50
|
+
UNKNOWN = "Not a valid option: `%s'."
|
51
|
+
UNPROCA = "Warning. Unprocessed arguments: %s"
|
52
52
|
|
53
53
|
def run
|
54
54
|
puts inspect
|
data/doc/demofan
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
#
|
4
|
+
# demofan -- Test the Application class with commands
|
5
|
+
#
|
6
|
+
|
7
|
+
require "applfan"
|
8
|
+
|
9
|
+
|
10
|
+
class DemoFan < ApplicationFan
|
11
|
+
|
12
|
+
NAME = "demofan"
|
13
|
+
VERSION = "1.0"
|
14
|
+
SUMMARY = "Test the Application class with commands"
|
15
|
+
COPYRIGHT = "(C) 2020 Bertram Scharpf"
|
16
|
+
LICENSE = "For internal use only"
|
17
|
+
AUTHOR = "Bertram Scharpf <software@bertram-scharpf.de>"
|
18
|
+
|
19
|
+
DESCRIPTION = <<~EOT
|
20
|
+
This is an example how to define an Application subclass
|
21
|
+
with commands inside.
|
22
|
+
EOT
|
23
|
+
|
24
|
+
attr_bang :verbose
|
25
|
+
define_option "v", :verbose!, "verbose mode"
|
26
|
+
|
27
|
+
define_option "h", :help, "show this options list"
|
28
|
+
alias_option "h", "help"
|
29
|
+
define_option "V", :version, "show version information"
|
30
|
+
alias_option "V", "version"
|
31
|
+
|
32
|
+
def run
|
33
|
+
super do |cmd|
|
34
|
+
cmd.verbose! if @verbose
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
class Init < Command
|
39
|
+
NAME = "init"
|
40
|
+
SUMMARY = "Initialize"
|
41
|
+
DESCRIPTION = <<~EOT
|
42
|
+
Initialization of nothing.
|
43
|
+
EOT
|
44
|
+
define_option "h", :help, "show init's options list"
|
45
|
+
alias_option "h", "help"
|
46
|
+
def verbose! ; end
|
47
|
+
def run
|
48
|
+
puts "Initializing...done."
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class Run < Command
|
53
|
+
NAME = "run"
|
54
|
+
SUMMARY = "Run a job"
|
55
|
+
DESCRIPTION = <<~EOT
|
56
|
+
Running nothing.
|
57
|
+
EOT
|
58
|
+
define_option "h", :help, "show run's options list"
|
59
|
+
alias_option "h", "help"
|
60
|
+
def verbose! ; @verbose = true ; end
|
61
|
+
def run
|
62
|
+
if @verbose then
|
63
|
+
puts "Starting..."
|
64
|
+
puts "Running..."
|
65
|
+
puts "Done."
|
66
|
+
else
|
67
|
+
puts "Running...done."
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
class Cleanup < Command
|
73
|
+
NAME = "cleanup"
|
74
|
+
SUMMARY = "Cleanup"
|
75
|
+
DESCRIPTION = <<~EOT
|
76
|
+
Cleanup of nothing.
|
77
|
+
EOT
|
78
|
+
define_option "h", :help, "show cleanup's options list"
|
79
|
+
alias_option "h", "help"
|
80
|
+
def verbose! ; end
|
81
|
+
def run
|
82
|
+
puts "Cleaning up...done."
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
|
89
|
+
DemoFan.run
|
90
|
+
|
data/lib/appl.rb
CHANGED
@@ -5,13 +5,16 @@
|
|
5
5
|
|
6
6
|
class Application
|
7
7
|
|
8
|
-
APPL_VERSION = "1.
|
8
|
+
APPL_VERSION = "1.8".freeze
|
9
9
|
|
10
10
|
OPTIONS_ENV = nil
|
11
11
|
|
12
12
|
STOPOPT = "stop option processing"
|
13
|
-
UNKNOWN = "Unknown option"
|
14
|
-
UNPROCA = "Warning: unprocessed arguments"
|
13
|
+
UNKNOWN = "Unknown option: `%s'."
|
14
|
+
UNPROCA = "Warning: unprocessed arguments: %s"
|
15
|
+
|
16
|
+
W_OPTS = 10
|
17
|
+
W_ARGS = 16
|
15
18
|
|
16
19
|
class OptionError < StandardError ; end
|
17
20
|
class Done < Exception ; end
|
@@ -46,40 +49,27 @@ class Application
|
|
46
49
|
end
|
47
50
|
|
48
51
|
def help
|
49
|
-
|
50
|
-
puts c.version
|
51
|
-
puts
|
52
|
-
puts c::DESCRIPTION
|
53
|
-
puts
|
54
|
-
c.show_options
|
55
|
-
if block_given? then
|
56
|
-
puts
|
57
|
-
yield
|
58
|
-
end
|
52
|
+
self.class.help
|
59
53
|
raise Done
|
60
54
|
end
|
61
55
|
|
62
56
|
def version
|
63
|
-
self.class.
|
57
|
+
self.class.version
|
64
58
|
raise Done
|
65
59
|
end
|
66
60
|
|
67
|
-
VERSION = "0"
|
68
|
-
NAME = "appl"
|
69
|
-
SUMMARY = "Dummy application"
|
70
|
-
DESCRIPTION = <<~EOT
|
71
|
-
This base class does nothing by default.
|
72
|
-
EOT
|
73
|
-
|
74
61
|
def run
|
75
62
|
end
|
76
63
|
|
77
|
-
def
|
78
|
-
run
|
64
|
+
def warn_unprocessed
|
79
65
|
if @args.any? then
|
80
|
-
|
81
|
-
puts "#{self.class::UNPROCA}: #{u}"
|
66
|
+
$stderr.puts self.class.root::UNPROCA % (@args.join " ")
|
82
67
|
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def execute
|
71
|
+
run
|
72
|
+
warn_unprocessed
|
83
73
|
0
|
84
74
|
rescue SignalException
|
85
75
|
raise if @debug
|
@@ -98,14 +88,6 @@ class Application
|
|
98
88
|
exit e
|
99
89
|
end
|
100
90
|
|
101
|
-
def version
|
102
|
-
if self::VERSION =~ %r/\s/ then
|
103
|
-
self::VERSION
|
104
|
-
else
|
105
|
-
"#{self::NAME} #{self::VERSION} -- #{self::SUMMARY}"
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
91
|
private
|
110
92
|
|
111
93
|
def execute args = nil
|
@@ -119,7 +101,9 @@ class Application
|
|
119
101
|
end
|
120
102
|
|
121
103
|
def inherited sub
|
122
|
-
sub.
|
104
|
+
sub.name or return
|
105
|
+
o, a = @options.dup.to_h, @aliases.dup.to_h
|
106
|
+
sub.instance_eval { @options, @aliases = o, a }
|
123
107
|
end
|
124
108
|
|
125
109
|
def attr_bang *syms
|
@@ -162,16 +146,12 @@ class Application
|
|
162
146
|
end
|
163
147
|
|
164
148
|
def delete_option opt
|
165
|
-
self < Application or return
|
166
|
-
superclass.delete_option opt
|
167
|
-
@options.delete opt
|
168
149
|
@aliases.reject! { |k,v| v == opt }
|
150
|
+
@options.delete opt
|
169
151
|
nil
|
170
152
|
end
|
171
153
|
|
172
154
|
def unalias_option opt
|
173
|
-
self < Application or return
|
174
|
-
superclass.unalias_option opt
|
175
155
|
@aliases.delete opt
|
176
156
|
nil
|
177
157
|
end
|
@@ -179,32 +159,12 @@ class Application
|
|
179
159
|
protected
|
180
160
|
|
181
161
|
def find_option_act opt
|
182
|
-
|
183
|
-
@options[ opt] || @options[ @aliases[ opt]] ||
|
184
|
-
(superclass.find_option_act opt)
|
185
|
-
end
|
186
|
-
|
187
|
-
def all_options
|
188
|
-
if self < Application then
|
189
|
-
r = superclass.all_options
|
190
|
-
r.update @options
|
191
|
-
else
|
192
|
-
{}
|
193
|
-
end
|
194
|
-
end
|
195
|
-
|
196
|
-
def all_aliases
|
197
|
-
if self < Application then
|
198
|
-
r = superclass.all_aliases
|
199
|
-
r.update @aliases
|
200
|
-
else
|
201
|
-
{}
|
202
|
-
end
|
162
|
+
@options[ opt] || @options[ @aliases[ opt]]
|
203
163
|
end
|
204
164
|
|
205
165
|
def options_desc &block
|
206
166
|
a = Hash.new do |h,k| h[ k] = [] end
|
207
|
-
|
167
|
+
@aliases.each { |k,v|
|
208
168
|
a[ v].push k
|
209
169
|
}
|
210
170
|
each_option { |opt,desc,arg,dfl,|
|
@@ -213,14 +173,13 @@ class Application
|
|
213
173
|
yield l, nil, nil, nil
|
214
174
|
}
|
215
175
|
}
|
216
|
-
yield "", nil, nil,
|
176
|
+
yield "", nil, nil, root::STOPOPT
|
217
177
|
end
|
218
178
|
|
219
179
|
public
|
220
180
|
|
221
181
|
def each_option
|
222
|
-
|
223
|
-
o.each { |opt,(desc,arg,dfl,act)|
|
182
|
+
@options.each { |opt,(desc,arg,dfl,act)|
|
224
183
|
case dfl
|
225
184
|
when Symbol then dfl = const_get dfl
|
226
185
|
end
|
@@ -230,7 +189,7 @@ class Application
|
|
230
189
|
|
231
190
|
def option_act args, opt, rest
|
232
191
|
dada = find_option_act opt
|
233
|
-
dada or raise OptionError,
|
192
|
+
dada or raise OptionError, root::UNKNOWN % opt
|
234
193
|
desc, arg, dfl, act = *dada
|
235
194
|
r = [ act]
|
236
195
|
if arg then
|
@@ -246,12 +205,32 @@ class Application
|
|
246
205
|
arg &&= "#{arg}"
|
247
206
|
dfl &&= "[#{dfl}]"
|
248
207
|
arg << dfl if arg && dfl
|
249
|
-
puts "
|
208
|
+
puts " %-*s %-*s %s" % [ root::W_OPTS, opt, root::W_ARGS, arg, desc]
|
250
209
|
end
|
251
210
|
end
|
252
211
|
|
253
|
-
def
|
254
|
-
|
212
|
+
def root
|
213
|
+
self
|
214
|
+
end
|
215
|
+
|
216
|
+
def applname
|
217
|
+
self::NAME
|
218
|
+
end
|
219
|
+
|
220
|
+
def help
|
221
|
+
puts "#{applname} -- #{self::SUMMARY}"
|
222
|
+
puts
|
223
|
+
puts self::DESCRIPTION
|
224
|
+
puts
|
225
|
+
show_options
|
226
|
+
if block_given? then
|
227
|
+
puts
|
228
|
+
yield
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
def version
|
233
|
+
puts "#{applname} #{self::VERSION} -- #{self::SUMMARY}"
|
255
234
|
puts self::COPYRIGHT if const_defined? :COPYRIGHT
|
256
235
|
puts "License: #{self::LICENSE}" if const_defined? :LICENSE
|
257
236
|
a = []
|
data/lib/applfan.rb
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
#
|
2
|
+
# lib/applfan.rb -- ApplicationFan class
|
3
|
+
#
|
4
|
+
|
5
|
+
require "appl"
|
6
|
+
|
7
|
+
|
8
|
+
ApplicationFan = Class.new Application
|
9
|
+
|
10
|
+
class ApplicationFan
|
11
|
+
|
12
|
+
AVAILCMDS = "Available commands (say -h after one for help)"
|
13
|
+
NOCOMMAND = "No command given. Say -h for a list."
|
14
|
+
UNKNWNCMD = "Unknown command: `%s'. Say -h for a list."
|
15
|
+
|
16
|
+
W_CMDS = 16
|
17
|
+
|
18
|
+
class CommandError < StandardError ; end
|
19
|
+
|
20
|
+
class <<self
|
21
|
+
|
22
|
+
attr_accessor :commands
|
23
|
+
|
24
|
+
def find_command name
|
25
|
+
@commands.find { |c| c::NAME == name }
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
def help
|
30
|
+
super do
|
31
|
+
if block_given? then
|
32
|
+
yield
|
33
|
+
puts
|
34
|
+
end
|
35
|
+
puts self::AVAILCMDS
|
36
|
+
puts
|
37
|
+
@commands.each { |c|
|
38
|
+
puts " %-*s %s" % [ self::W_CMDS, c::NAME, c::SUMMARY]
|
39
|
+
}
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def inherited sub
|
46
|
+
sub.instance_eval do
|
47
|
+
@commands = []
|
48
|
+
const_set :Command, (
|
49
|
+
Class.new Application do
|
50
|
+
define_singleton_method :inherited do |c|
|
51
|
+
sub.commands.push c
|
52
|
+
super c
|
53
|
+
end
|
54
|
+
define_singleton_method :root do
|
55
|
+
sub
|
56
|
+
end
|
57
|
+
define_singleton_method :applname do
|
58
|
+
"#{root::NAME} #{self::NAME}"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
)
|
62
|
+
end
|
63
|
+
super
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
def run
|
69
|
+
c = @args.shift
|
70
|
+
c or raise CommandError, self.class::NOCOMMAND
|
71
|
+
cmd = self.class.find_command c
|
72
|
+
cmd or raise CommandError, self.class::UNKNWNCMD % c
|
73
|
+
(cmd.new @args.slice! 0, @args.length).tap { |sub|
|
74
|
+
yield sub if block_given?
|
75
|
+
sub.run
|
76
|
+
sub.warn_unprocessed
|
77
|
+
}
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: appl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: '1.8'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bertram Scharpf
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
A base class for command line applications doing options parsing
|
@@ -21,7 +21,9 @@ extra_rdoc_files: []
|
|
21
21
|
files:
|
22
22
|
- bin/intar
|
23
23
|
- doc/demoappl
|
24
|
+
- doc/demofan
|
24
25
|
- lib/appl.rb
|
26
|
+
- lib/applfan.rb
|
25
27
|
- lib/intar.rb
|
26
28
|
homepage: http://www.bertram-scharpf.de/software/appl
|
27
29
|
licenses:
|