snagglepuss 0.0.1.alpha → 0.0.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f7fad3a0990bf01a7d62ef171a5b29b2def9aa63721e4b69b111fcd58d22e3a9
4
- data.tar.gz: 5731a5acf520fe4e71868134de8741ea906ab7186a44e28a95063793f0a4d498
3
+ metadata.gz: de831b08b102db213d7a9b76b66ac0602304e52e30534178dca97d26becdb50b
4
+ data.tar.gz: 6b4aaad4ac4ad6cf77250847c42cbd7660f9920ede419de5c1ff7c817366cf72
5
5
  SHA512:
6
- metadata.gz: 17b9a9fc53d823e4cf4377451f53f24d6d9885a6c43a4d0b9e109db5e54aee677e50dd2d051079899cae7b60bfeb09daccd6dd56c831e5234e8be0989605206a
7
- data.tar.gz: 8ca692cb0eb989b2fecd2b43b9caa5ecc605ddd2d57b754b7a325ac9c25c4378bd3313c4f6863363706ead78dc9b6cc45b38e037739cf4a1c63188586b7a164e
6
+ metadata.gz: 13b5522498891d7adc8d058ae7ebda4f10bdd3a2fca72a0dc98c99825cfc3d60e3b4c47337dafaba13139521833111904481ed87078f22fcc36ef62fb7cd4d16
7
+ data.tar.gz: 7972db8e27abcf81591eafdc1378a2f0e09f8730a0b4c9337ad1580455effff442c81eeb12121177ac8427b99bb229f4bb84ad508868fb3d3ea075109a2f420d
data/changelog.md CHANGED
@@ -1,10 +1,17 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.0.1] - 2025-05-23
4
+
5
+ * Gracefully exit when no error occurs (i.e. $! == nil)
6
+ * Provide a header and footer that indicate when output starts and stops.
7
+ * Provide more colorful output.
8
+
9
+
3
10
  ## [0.0.1.alpha] - 2025-05-23
4
11
 
5
- - Add initial implementation.
12
+ * Add initial implementation.
6
13
 
7
14
 
8
15
  ## [0.1.0.alpha] - 2025-05-23
9
16
 
10
- - Initial release
17
+ * Initial release
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ if defined?(ColorMeRad)
4
+ if [
5
+ :error,
6
+ :label,
7
+ :exclamation,
8
+ :partition,
9
+ :path,
10
+ :function,
11
+ ].all?{ |key| ColorMeRad.color_for_key(key) == :light_yellow }
12
+ ColorMeRad.configure do |config|
13
+ config.set_colors \
14
+ :error => :red,
15
+ :label => :magenta,
16
+ :exclamation => :green,
17
+ :path => :blue,
18
+ :partition => :light_black,
19
+ :function => :magenta
20
+ end
21
+ end
22
+ end
23
+
24
+ module Snagglepuss
25
+ module Colorize
26
+ extend self
27
+
28
+ [
29
+ :key,
30
+ :data,
31
+ ].each do |method|
32
+ define_method method do |*args|
33
+ return args.first.to_s unless enabled?
34
+ ColorMeRad.send method, *args
35
+ end
36
+ end
37
+
38
+ def enabled?
39
+ return false unless defined?(ColorMeRad)
40
+ ColorMeRad.enabled?
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Snagglepuss
4
+ module LineFormatter
5
+ extend self
6
+
7
+ def execute(line)
8
+ return line unless Colorize.enabled?
9
+ return Colorize.key(line, :stacktrace) unless full_match?(line)
10
+
11
+ path, number, description = line.split(':')
12
+ function = description.match(/`(.*)'/)[1].to_s
13
+
14
+ '%s:%s in `%s`' % [
15
+ Colorize.key(path, :path),
16
+ Colorize.data(number.to_i),
17
+ Colorize.key(function, :function),
18
+ ]
19
+ end
20
+
21
+ private
22
+
23
+ def full_match?(line)
24
+ line.match(/[\/\w]+:\d+:in `.*'$/)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Snagglepuss
4
+ module ShowException
5
+ extend self
6
+
7
+ def execute(e)
8
+ exit_stage :right
9
+
10
+ show_backtrace_for e
11
+
12
+ puts '%s: %s' % [
13
+ Colorize.data(e.class),
14
+ Colorize.key(e.message, :error),
15
+ ]
16
+
17
+ exit_stage :left
18
+ end
19
+
20
+ private
21
+
22
+ def show_backtrace_for(e)
23
+ app_trace = []
24
+ e.backtrace.each do |line|
25
+ formatted = LineFormatter.execute(line)
26
+ puts formatted
27
+ next if EXCLUSIONS.any?{ |e| line.match(e) }
28
+
29
+ app_trace << formatted
30
+ end
31
+
32
+ puts '%s %s %s' % [
33
+ Colorize.key('<== ', :partition),
34
+ Colorize.key('Application trace', :label),
35
+ Colorize.key('=' * 57 + '>', :partition),
36
+ ]
37
+
38
+ puts app_trace
39
+
40
+ puts Colorize.key('=' * 80, :partition)
41
+ end
42
+
43
+ def exit_stage(direction)
44
+ exclamation = "Exit, stage #{direction}!"
45
+ padding = 80 - (exclamation.length + 5)
46
+
47
+ is_right = direction == :right
48
+
49
+ fill = is_right ? '<' : '>'
50
+ fill = Colorize.key(fill, :partition)
51
+
52
+ puts '%s %s %s' % [
53
+ (is_right ? fill * 3 : fill * padding),
54
+ Colorize.key("Exit, stage #{direction}!", :exclamation),
55
+ (is_right ? fill * padding : fill * 3),
56
+ ]
57
+ end
58
+ end
59
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Snagglepuss
4
- VERSION = '0.0.1.alpha'
4
+ VERSION = '0.0.1'
5
5
  end
data/lib/snagglepuss.rb CHANGED
@@ -1,59 +1,33 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative "snagglepuss/version"
4
-
5
- if defined?(ColorMeRad)
6
- if ColorMeRad.color_for_key(:error) == :light_yellow &&
7
- ColorMeRad.color_for_key(:label) == :light_yellow
8
- ColorMeRad.configure do |config|
9
- config.set_colors \
10
- :error => :red,
11
- :label => :magenta
12
- end
13
- end
14
- end
15
-
16
- module Colorize
17
- extend self
18
-
19
- [
20
- :key,
21
- :data,
22
- ].each do |method|
23
- define_method method do |*args|
24
- return args.first.to_s unless defined?(ColorMeRad)
25
- ColorMeRad.send method, *args
26
- end
27
- end
28
- end
3
+ require_relative 'snagglepuss/version'
4
+ require_relative 'snagglepuss/colorize'
5
+ require_relative 'snagglepuss/line_formatter'
6
+ require_relative 'snagglepuss/show_exception'
29
7
 
30
8
  module Snagglepuss
31
9
  extend self
32
10
 
33
- class Error < StandardError; end
11
+ SKIPPABLE_CLASSES = [
12
+ NilClass,
13
+ SystemExit,
14
+ ]
34
15
 
35
- def exit_gracefully(e)
36
- return if e.is_a?(SystemExit)
16
+ EXCLUSIONS = [
17
+ /\/\.?asdf\//,
18
+ /\/\.gems\//,
19
+ ]
37
20
 
38
- puts e.backtrace
39
- puts '=' * 80
40
- puts Colorize.key('Application trace:', :label)
41
- puts '-' * 80
42
- e.backtrace.each do |line|
43
- puts line if !line.match(/\/\.?asdf\//) && !line.match(/\/\.gems\//)
44
- end
45
- puts '=' * 80
21
+ def exit_stage_right(e)
22
+ return if SKIPPABLE_CLASSES.any?{ |c| e.is_a?(c) }
46
23
 
47
- puts '%s: %s' % [
48
- Colorize.data(e.class),
49
- Colorize.key(e.message, :error),
50
- ]
24
+ ShowException.execute e
51
25
 
52
26
  $stderr.reopen(IO::NULL)
53
27
  $stdout.reopen(IO::NULL)
54
28
  end
55
29
 
56
30
  at_exit do
57
- exit_gracefully $!
31
+ exit_stage_right $!
58
32
  end
59
33
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snagglepuss
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1.alpha
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Travis Herrick
@@ -34,6 +34,9 @@ extra_rdoc_files: []
34
34
  files:
35
35
  - changelog.md
36
36
  - lib/snagglepuss.rb
37
+ - lib/snagglepuss/colorize.rb
38
+ - lib/snagglepuss/line_formatter.rb
39
+ - lib/snagglepuss/show_exception.rb
37
40
  - lib/snagglepuss/version.rb
38
41
  - readme.md
39
42
  - snagglepuss.gemspec
@@ -54,9 +57,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
54
57
  version: 2.6.0
55
58
  required_rubygems_version: !ruby/object:Gem::Requirement
56
59
  requirements:
57
- - - ">"
60
+ - - ">="
58
61
  - !ruby/object:Gem::Version
59
- version: 1.3.1
62
+ version: '0'
60
63
  requirements: []
61
64
  rubygems_version: 3.3.3
62
65
  signing_key: