appl 1.2 → 1.5

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 (5) hide show
  1. checksums.yaml +5 -5
  2. data/bin/intar +12 -21
  3. data/lib/appl.rb +2 -5
  4. data/lib/intar.rb +21 -28
  5. metadata +5 -19
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c17ebbb3f574a1d27df9610144f9881c3b8ef910
4
- data.tar.gz: 6e68ffdb0dd1e1c227dc371f29e9d93fb7a1abef
2
+ SHA256:
3
+ metadata.gz: 3670591a91a6270557abff4db7e629db25edcced3372b809dfcd045118ecf427
4
+ data.tar.gz: fecd11d08475460397ec407536bea1002e74cc80e2e35025ef15819c3eb7ebdd
5
5
  SHA512:
6
- metadata.gz: c16e0eb7be520d7eace0ab904c838d61ab3eaa29b34d3f2fda9d5c23b35f03721f244ffb814389399bb6f1a175ba68cdd39a2b9fefb7f4cc7bb4f84ce8dbeef0
7
- data.tar.gz: 98cf8b5bde3d91115a0763e0561718f04a99d560134d52448f68384662af9814cad6fdc44a283352e00897cf323fd450e4f1c9e77de7c052f9a75ab7dbc4ae51
6
+ metadata.gz: da220e1d481946d3f418e724c78b308a8a50bd8173d6b57d41ccf82329a962f6783342ab8d1d46b7ea87524f1378e2cffccf4cda13f577c9f7dc556c70edc802
7
+ data.tar.gz: c3d50105e3584840e0e5511774aa2a2dd315092add7a597056a7df0f3c31bf309244c66091d5e94c18b21a47820782eb3f0a1a93c3cba4e8a81bb7269b4ca7bc
data/bin/intar CHANGED
@@ -13,7 +13,7 @@ class IntarApp < Application
13
13
  NAME = "intar"
14
14
  VERSION = APPL_VERSION
15
15
  SUMMARY = "Interactive Ruby"
16
- COPYRIGHT = "(C) 2008-2013 Bertram Scharpf <software@bertram-scharpf.de>"
16
+ COPYRIGHT = "(C) 2008-2016 Bertram Scharpf <software@bertram-scharpf.de>"
17
17
  LICENSE = "BSD"
18
18
  AUTHOR = "Bertram Scharpf <software@bertram-scharpf.de>"
19
19
 
@@ -120,27 +120,18 @@ EOT
120
120
  end
121
121
  end
122
122
 
123
-
124
123
  def read_cfg
125
- c = @configfile
126
- return unless c
127
- unless c[ File::SEPARATOR] or (File.exists? c) then
128
- c = File.expand_path c, "~"
129
- return unless File.exists? c
130
- end
131
- r = File.read c
132
- r.prepend "$SAFE = 1#$/"
133
- Thread.new {
134
- begin
135
- eval r, TOPLEVEL_BINDING
136
- rescue Exception
137
- $@.pop 2
138
- e = $@.shift
139
- puts "#{e}: #$! (#{$!.class})"
140
- $@.each { |l| puts "\t#{l}" }
141
- raise "Error in config file #{c}"
142
- end
143
- }.value
124
+ return unless @configfile
125
+ h = "~" unless @configfile[ File::SEPARATOR]
126
+ c = File.expand_path @configfile, h
127
+ return unless File.exists? c
128
+ load c
129
+ rescue Exception
130
+ $@.pop 2
131
+ e = $@.shift
132
+ puts "#{e}: #$! (#{$!.class})"
133
+ $@.each { |l| puts "\t#{l}" }
134
+ raise "Error in config file #{c}"
144
135
  end
145
136
 
146
137
  def nil_if_none var
@@ -5,7 +5,7 @@
5
5
 
6
6
  class Application
7
7
 
8
- APPL_VERSION = "1.2".freeze
8
+ APPL_VERSION = "1.5".freeze
9
9
 
10
10
  OPTIONS_ENV = nil
11
11
 
@@ -91,8 +91,6 @@ This base class does nothing by default.
91
91
  $!.to_i rescue 1
92
92
  end
93
93
 
94
- HASH_ORDER = RUBY_VERSION >= "1.9"
95
-
96
94
  class <<self
97
95
 
98
96
  def run args = nil
@@ -209,7 +207,6 @@ This base class does nothing by default.
209
207
  all_aliases.each { |k,v|
210
208
  a[ v].push k
211
209
  }
212
- a.values.each { |v| v.sort! } unless HASH_ORDER
213
210
  each_option { |opt,desc,arg,dfl,|
214
211
  yield opt, arg, dfl, desc
215
212
  a[ opt].each { |l|
@@ -223,7 +220,6 @@ This base class does nothing by default.
223
220
 
224
221
  def each_option
225
222
  o = all_options
226
- o = o.sort_by { |k,v| k.swapcase } unless HASH_ORDER
227
223
  o.each { |opt,(desc,arg,dfl,act)|
228
224
  case dfl
229
225
  when Symbol then dfl = const_get dfl
@@ -293,6 +289,7 @@ This base class does nothing by default.
293
289
  end
294
290
  end
295
291
  r.concat $*
292
+ $*.clear
296
293
  r
297
294
  end
298
295
 
@@ -47,7 +47,7 @@ require "supplement/terminal"
47
47
 
48
48
 
49
49
  class Object
50
- def empty_binding
50
+ def intar_binding
51
51
  binding
52
52
  end
53
53
  end
@@ -62,7 +62,7 @@ class Intar
62
62
  def initialize filename
63
63
  @filename = filename
64
64
  return unless @filename
65
- h = "~" unless @filename.starts_with "./"
65
+ h = "~" unless @filename[ File::SEPARATOR]
66
66
  @filename = File.expand_path @filename, h
67
67
  File.exists? @filename and File.open @filename do |h|
68
68
  c = []
@@ -238,16 +238,16 @@ class Intar
238
238
  autoload :Etc, "etc"
239
239
  autoload :Socket, "socket"
240
240
 
241
- def cur_prompt
241
+ def cur_prompt prev
242
242
  t = Time.now
243
243
  self.class.prompt.gsub /%(?:
244
- \(([^\)]*)\)
244
+ \(([^\)]+)?\)
245
245
  |
246
246
  ([+-]?[0-9]+(?:\.[0-9]+)?)
247
247
  )?(.)/nx do
248
248
  case $3
249
249
  when "s" then @obj.to_s
250
- when "i" then $1.notempty? ? (@obj.send $1) : @obj.inspect
250
+ when "i" then $1 ? (@obj.send $1) : @obj.inspect
251
251
  when "n" then "%#$2d" % @n
252
252
  when "t" then t.strftime $1||"%X"
253
253
  when "u" then Etc.getpwuid.name
@@ -255,7 +255,7 @@ class Intar
255
255
  when "w" then cwd_short
256
256
  when "W" then File.basename cwd_short
257
257
  when "c" then (colour *($1 || $2 || "").split.map { |x| x.to_i }).to_s
258
- when ">" then Process.uid == 0 ? "#" : ">"
258
+ when ">" then prev ? "." : Process.uid == 0 ? "#" : ">"
259
259
  when "%" then $3
260
260
  else $&
261
261
  end
@@ -284,29 +284,23 @@ class Intar
284
284
  def readline
285
285
  r, @previous = @previous, nil
286
286
  r or @n += 1
287
- cp = cur_prompt
288
- loop do
289
- begin
290
- l = Readline.readline r ? "" : cp
291
- rescue Interrupt
292
- puts "^C -- #{$!.inspect}"
293
- retry
294
- end
295
- if r then
296
- break if l.nil?
297
- r << $/ << l
298
- break if l.empty?
299
- else
300
- return if l.nil?
301
- next unless l =~ /\S/
302
- r = l
303
- break unless l =~ /\\+\z/ and $&.length % 2 != 0
304
- end
287
+ cp = cur_prompt r
288
+ begin
289
+ l = Readline.readline cp
290
+ rescue Interrupt
291
+ puts "^C -- #{$!.inspect}"
292
+ retry
293
+ end
294
+ return if l.nil?
295
+ if r then
296
+ r << $/ << l
297
+ else
298
+ r = l
305
299
  end
300
+ self.class.hist_add l
306
301
  cp.strip!
307
302
  cp.gsub! /\e\[[0-9]*(;[0-9]*)*m/, ""
308
303
  @file = "#{self.class}/#{cp}"
309
- self.class.hist_add r
310
304
  r
311
305
  end
312
306
 
@@ -354,10 +348,10 @@ class Intar
354
348
  class CmdFailed < Exception ; end
355
349
 
356
350
  def run *precmds
357
- bind = @obj.empty_binding
351
+ bind = @obj.intar_binding
358
352
  precmds.each { |l| eval l, bind }
359
353
  oldset = eval OLDSET, bind
360
- @cl = eval "caller.length", bind
354
+ @cl = (eval "caller.length", bind) + 2 # 2 = eval + run()
361
355
  while l = readline do
362
356
  re_sh_pref = /\A#{Regexp.quote self.class.sh_pref}/
363
357
  re_pi_suff = /#{Regexp.quote self.class.pi_suff}\z/
@@ -432,7 +426,6 @@ class Intar
432
426
  bt = $@.dup
433
427
  if bt.length > @cl then
434
428
  bt.pop @cl
435
- bt.push bt.pop[ /(.*:\d+):.*/, 1]
436
429
  end
437
430
  puts bt
438
431
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: appl
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.2'
4
+ version: '1.5'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bertram Scharpf
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-29 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: supplement
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '2'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '2'
11
+ date: 2019-03-13 00:00:00.000000000 Z
12
+ dependencies: []
27
13
  description: |
28
14
  A base class for command line applications doing options parsing
29
15
  and generating exit codes.
@@ -39,7 +25,7 @@ files:
39
25
  - lib/intar.rb
40
26
  homepage: http://www.bertram-scharpf.de/software/appl
41
27
  licenses:
42
- - BSD
28
+ - BSD-2-Clause
43
29
  metadata: {}
44
30
  post_install_message:
45
31
  rdoc_options: []
@@ -58,7 +44,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
58
44
  requirements:
59
45
  - Just Ruby
60
46
  rubyforge_project: NONE
61
- rubygems_version: 2.6.4
47
+ rubygems_version: 2.7.8
62
48
  signing_key:
63
49
  specification_version: 4
64
50
  summary: Easy option parsing