appl 1.12 → 1.13
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/appl.rb +18 -8
- data/lib/applfan.rb +5 -10
- 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: 9e3306b330c4d69ef88e6b75511d7b0ab1e030f990aac1800305dcfa4afd0f65
|
4
|
+
data.tar.gz: eff477635d40b6ff9c443b0fe1256107c85d31bf6aa7c0a2088f26ffa239111c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ae84d8de622e2e2b4763ef8fbda40b9210edd326d48358707364f4a4c99b0fbee05c1ed1dc5b31d83d3f7429e74922a81af5eb22de7572a1a3c6ad7bec99925
|
7
|
+
data.tar.gz: ab2ea5f6b9f7850bd62e741201cc10bdaa1c1c6be549c0a45fa435bb7ee55779fabfade33a0801fd931d7313d0b90f3a991b1ec38ee6749db19562ee6969afe2
|
data/lib/appl.rb
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
class Application
|
7
7
|
|
8
|
-
APPL_VERSION = "1.
|
8
|
+
APPL_VERSION = "1.13".freeze
|
9
9
|
|
10
10
|
OPTIONS_ENV = nil
|
11
11
|
|
@@ -13,14 +13,16 @@ class Application
|
|
13
13
|
UNKNOWN = "Unknown option: `%s'."
|
14
14
|
UNPROCA = "Warning: unprocessed arguments: %s"
|
15
15
|
|
16
|
+
ALIASES = [].freeze
|
17
|
+
|
16
18
|
W_OPTS = 10
|
17
19
|
W_ARGS = 16
|
18
20
|
|
19
21
|
class OptionError < StandardError ; end
|
20
22
|
class Done < Exception ; end
|
21
23
|
|
22
|
-
def initialize args = nil
|
23
|
-
@args = args
|
24
|
+
def initialize name = nil, args = nil
|
25
|
+
@name, @args = name, args
|
24
26
|
self.class.each_option { |opt,desc,arg,dfl,act|
|
25
27
|
begin
|
26
28
|
send act, dfl if dfl
|
@@ -92,7 +94,8 @@ class Application
|
|
92
94
|
private
|
93
95
|
|
94
96
|
def execute args = nil
|
95
|
-
|
97
|
+
n = File.basename $0
|
98
|
+
i = new n, args||cmdline_arguments
|
96
99
|
i.execute
|
97
100
|
rescue Done
|
98
101
|
0
|
@@ -214,12 +217,19 @@ class Application
|
|
214
217
|
self
|
215
218
|
end
|
216
219
|
|
217
|
-
def
|
218
|
-
self::NAME
|
220
|
+
def all_names
|
221
|
+
[ self::NAME, *self::ALIASES].join "|"
|
219
222
|
end
|
220
223
|
|
221
224
|
def help
|
222
|
-
|
225
|
+
n = []
|
226
|
+
s = self
|
227
|
+
begin
|
228
|
+
l = s.all_names
|
229
|
+
n.unshift l
|
230
|
+
s = s.root
|
231
|
+
end while s != root
|
232
|
+
puts "#{n.join ' '} -- #{self::SUMMARY}"
|
223
233
|
puts
|
224
234
|
puts self::DESCRIPTION
|
225
235
|
puts
|
@@ -231,7 +241,7 @@ class Application
|
|
231
241
|
end
|
232
242
|
|
233
243
|
def version
|
234
|
-
puts "#{
|
244
|
+
puts "#{self::NAME} #{self::VERSION} -- #{self::SUMMARY}"
|
235
245
|
puts self::COPYRIGHT if const_defined? :COPYRIGHT
|
236
246
|
puts "License: #{self::LICENSE}" if const_defined? :LICENSE
|
237
247
|
a = []
|
data/lib/applfan.rb
CHANGED
@@ -5,9 +5,7 @@
|
|
5
5
|
require "appl"
|
6
6
|
|
7
7
|
|
8
|
-
ApplicationFan
|
9
|
-
|
10
|
-
class ApplicationFan
|
8
|
+
class ApplicationFan < Application
|
11
9
|
|
12
10
|
AVAILCMDS = "Available commands (say -h after one for help)"
|
13
11
|
NOCOMMAND = "No command given. Say -h for a list."
|
@@ -22,7 +20,7 @@ class ApplicationFan
|
|
22
20
|
attr_accessor :commands
|
23
21
|
|
24
22
|
def find_command name
|
25
|
-
@commands.find { |c| c::NAME == name }
|
23
|
+
@commands.find { |c| c::NAME == name or c::ALIASES.include? name }
|
26
24
|
end
|
27
25
|
|
28
26
|
|
@@ -35,7 +33,7 @@ class ApplicationFan
|
|
35
33
|
puts self::AVAILCMDS
|
36
34
|
puts
|
37
35
|
@commands.each { |c|
|
38
|
-
puts " %-*s %s" % [ self::W_CMDS, c
|
36
|
+
puts " %-*s %s" % [ self::W_CMDS, c.all_names, c::SUMMARY]
|
39
37
|
}
|
40
38
|
end
|
41
39
|
end
|
@@ -52,10 +50,7 @@ class ApplicationFan
|
|
52
50
|
super c
|
53
51
|
end
|
54
52
|
define_singleton_method :root do
|
55
|
-
sub
|
56
|
-
end
|
57
|
-
define_singleton_method :applname do
|
58
|
-
"#{root::NAME} #{self::NAME}"
|
53
|
+
sub.root
|
59
54
|
end
|
60
55
|
end
|
61
56
|
)
|
@@ -70,7 +65,7 @@ class ApplicationFan
|
|
70
65
|
c or raise CommandError, self.class::NOCOMMAND
|
71
66
|
cmd = self.class.find_command c
|
72
67
|
cmd or raise CommandError, self.class::UNKNWNCMD % c
|
73
|
-
sub = cmd.new @args.slice! 0, @args.length
|
68
|
+
sub = cmd.new c, (@args.slice! 0, @args.length)
|
74
69
|
yield sub if block_given?
|
75
70
|
sub.execute
|
76
71
|
end
|
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.13'
|
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: 2021-04-11 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: |
|
14
14
|
A base class for command line applications doing options parsing
|