appl 1.12 → 1.13

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/appl.rb +18 -8
  3. data/lib/applfan.rb +5 -10
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 840b8916d8f8d5b79f0f87bdee61772a9f6e00bffa3cc3c69aeaad93b7b950fe
4
- data.tar.gz: 570c63f80082520339691d6fe3c1aad68a953e7eee90866b21dfe50c9705af80
3
+ metadata.gz: 9e3306b330c4d69ef88e6b75511d7b0ab1e030f990aac1800305dcfa4afd0f65
4
+ data.tar.gz: eff477635d40b6ff9c443b0fe1256107c85d31bf6aa7c0a2088f26ffa239111c
5
5
  SHA512:
6
- metadata.gz: d634ae0936e200f45b741a8ed2dce2900c7ad548993e08da923104b1f95612c0a2e94b72482d41a5041b754f68a6231a8e101986771052ee24818d5273d475e8
7
- data.tar.gz: 0ed10689b122791eef9c7f8468881a8449740e0858209f5d0867241b67b64f1ef4f26db7703c7586a3f06371075b66a6f577f2056effcf5907b7862dc6b2628f
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.12".freeze
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||self.class.cmdline_arguments
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
- i = new args
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 applname
218
- self::NAME
220
+ def all_names
221
+ [ self::NAME, *self::ALIASES].join "|"
219
222
  end
220
223
 
221
224
  def help
222
- puts "#{applname} -- #{self::SUMMARY}"
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 "#{applname} #{self::VERSION} -- #{self::SUMMARY}"
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 = Class.new Application
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::NAME, c::SUMMARY]
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.12'
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: 2020-11-19 00:00:00.000000000 Z
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