lit-cli 0.4.0 → 0.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/config.rb +20 -11
- data/lib/lit_cli.rb +96 -27
- data/lib/lit_pry.rb +90 -47
- 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: c0bb5bf94135acf7647df72b3431dc89663ee6bca855cfb3c75f298d8a79099d
|
4
|
+
data.tar.gz: a1c226eec222a72c0be6f38ee4940f5a3f70809557805bcc0992ebff50e11e89
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 335100d58b9ee3c5f6fa599725c91c0911237b1e6ba64fadd4d62b59569478e897eee752f4f9abf70365ae102fa99f9a4d849099c8b99521e6207ec9ad00ae2a
|
7
|
+
data.tar.gz: 97b8638b199affa210e563aa529f8178a45fe0f5023c844460a78e6f742a3b20dbcb502cf64922001b40fa974a009118bce2d7040fba7d3cf88cc0190dc7281d
|
data/lib/config.rb
CHANGED
@@ -22,22 +22,27 @@ module LitCLI
|
|
22
22
|
@@errors = Set.new
|
23
23
|
|
24
24
|
attr_accessor :enabled
|
25
|
+
attr_accessor :statuses
|
25
26
|
attr_accessor :types
|
26
|
-
|
27
|
+
# Flags.
|
27
28
|
attr_accessor :step
|
29
|
+
attr_accessor :status
|
30
|
+
attr_accessor :type
|
28
31
|
attr_accessor :delay
|
29
32
|
|
30
33
|
def initialize()
|
31
34
|
|
32
|
-
@
|
33
|
-
:info => { icon: "ℹ", color: :blue },
|
34
|
-
:pass => { icon: "✔", color: :green },
|
35
|
-
:warn => { icon: "⚠", color: :yellow },
|
36
|
-
:fail => { icon: "⨯", color: :red },
|
37
|
-
:error => { icon: "!", color: :red },
|
38
|
-
:debug => { icon: "?", color: :purple },
|
35
|
+
@statuses = {
|
36
|
+
:info => { icon: "ℹ", color: :blue, styles: [:upcase] },
|
37
|
+
:pass => { icon: "✔", color: :green, styles: [:upcase] },
|
38
|
+
:warn => { icon: "⚠", color: :yellow, styles: [:upcase] },
|
39
|
+
:fail => { icon: "⨯", color: :red, styles: [:upcase] },
|
40
|
+
:error => { icon: "!", color: :red, styles: [:upcase] },
|
41
|
+
:debug => { icon: "?", color: :purple, styles: [:upcase] },
|
39
42
|
}
|
40
43
|
|
44
|
+
@types = nil
|
45
|
+
|
41
46
|
# Lit is disabled by default, then enabled via the `lit` command.
|
42
47
|
# Or it can be permanently enabled, without the use of the `lit` command.
|
43
48
|
@enabled = false
|
@@ -48,12 +53,15 @@ module LitCLI
|
|
48
53
|
# Flag defaults when not supplied via command line.
|
49
54
|
##
|
50
55
|
|
51
|
-
# Array of types to filter by, for example... [:warn, :error, :fail]
|
52
|
-
@type = nil
|
53
|
-
|
54
56
|
# Boolean on whether or not to step through each lit() breakpoint.
|
55
57
|
@step = false
|
56
58
|
|
59
|
+
# Array of statuses to filter by, for example: [:warn, :error, :fail]
|
60
|
+
@status = nil
|
61
|
+
|
62
|
+
# Array of types to filter by, for example: [:cat, :dog, :tree]
|
63
|
+
@type = nil
|
64
|
+
|
57
65
|
# Integer or float representing amount of seconds to delay each lit() by.
|
58
66
|
@delay = 0
|
59
67
|
|
@@ -89,6 +97,7 @@ module LitCLI
|
|
89
97
|
end
|
90
98
|
|
91
99
|
@step = true if flags.has_key? :step
|
100
|
+
@status = Array(flags[:status]).map(&:to_sym) if valid? flags, :status
|
92
101
|
@type = Array(flags[:type]).map(&:to_sym) if valid? flags, :type
|
93
102
|
@delay = flags[:delay].to_f if valid? flags, :delay
|
94
103
|
end
|
data/lib/lit_cli.rb
CHANGED
@@ -8,26 +8,49 @@ module LitCLI
|
|
8
8
|
@@config = Config.new
|
9
9
|
@@is_prying = false
|
10
10
|
|
11
|
-
def lit(message,
|
11
|
+
def lit(message, status = :info, type = nil, context = nil)
|
12
12
|
if @@config.enabled
|
13
|
-
return if LitCLI.
|
14
|
-
LitCLI.
|
13
|
+
return if LitCLI.filter_status? status
|
14
|
+
return if LitCLI.filter_type? type
|
15
|
+
|
16
|
+
LitCLI.render(message, status, type, context)
|
17
|
+
|
15
18
|
LitCLI.step()
|
19
|
+
yield if block_given?
|
20
|
+
|
16
21
|
LitCLI.delay()
|
17
22
|
end
|
18
23
|
end
|
19
24
|
alias 🔥 lit
|
20
25
|
|
21
|
-
def self.render(type)
|
22
|
-
|
26
|
+
def self.render(message, status, type, context)
|
27
|
+
text = "🔥"
|
23
28
|
|
24
|
-
|
25
|
-
|
26
|
-
|
29
|
+
# Time.
|
30
|
+
time = LitCLI.format(Time.now().strftime("%k:%M"), color: :cyan)
|
31
|
+
text << " #{time}"
|
27
32
|
|
28
|
-
|
33
|
+
# Status.
|
34
|
+
config = @@config.statuses[status]
|
35
|
+
text << LitCLI.format(" #{config[:icon]} #{status.to_s}", config)
|
36
|
+
|
37
|
+
# Type.
|
38
|
+
if !@@config.types.nil? && @@config.types.has_key?(type)
|
39
|
+
config = @@config.types[type]
|
40
|
+
if config.has_key? :icon
|
41
|
+
text << LitCLI.format(" #{config[:icon]} #{type.to_s}", config)
|
42
|
+
else
|
43
|
+
text << LitCLI.format(" #{type.to_s}", config)
|
44
|
+
end
|
45
|
+
end
|
29
46
|
|
30
|
-
|
47
|
+
# Context.
|
48
|
+
text << LitCLI.format(" #{context}", styles: [:bold, :dim])
|
49
|
+
|
50
|
+
# Message.
|
51
|
+
text << " #{message}"
|
52
|
+
|
53
|
+
puts text
|
31
54
|
end
|
32
55
|
|
33
56
|
def self.step()
|
@@ -39,7 +62,15 @@ module LitCLI
|
|
39
62
|
end
|
40
63
|
end
|
41
64
|
|
42
|
-
def self.
|
65
|
+
def self.filter_status? status
|
66
|
+
unless @@config.status.nil? || @@config.status.include?(status)
|
67
|
+
return true
|
68
|
+
end
|
69
|
+
|
70
|
+
false
|
71
|
+
end
|
72
|
+
|
73
|
+
def self.filter_type? type
|
43
74
|
unless @@config.type.nil? || @@config.type.include?(type)
|
44
75
|
return true
|
45
76
|
end
|
@@ -57,23 +88,61 @@ module LitCLI
|
|
57
88
|
@@config.step && @@is_prying
|
58
89
|
end
|
59
90
|
|
60
|
-
def self.
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
91
|
+
def self.format(text, config)
|
92
|
+
|
93
|
+
if config.has_key? :styles
|
94
|
+
# Change characters first.
|
95
|
+
config[:styles].each do |style|
|
96
|
+
case style
|
97
|
+
when :upcase
|
98
|
+
text = text.upcase
|
99
|
+
when :downcase
|
100
|
+
text = text.downcase
|
101
|
+
when :capitalize
|
102
|
+
text = text.capitalize
|
103
|
+
end
|
104
|
+
end
|
105
|
+
# Then apply styling.
|
106
|
+
config[:styles].each do |style|
|
107
|
+
case style
|
108
|
+
when :clear
|
109
|
+
text = @@pastel.clear(text)
|
110
|
+
when :bold
|
111
|
+
text = @@pastel.bold(text)
|
112
|
+
when :dim
|
113
|
+
text = @@pastel.dim(text)
|
114
|
+
when :italic
|
115
|
+
text = @@pastel.italic(text)
|
116
|
+
when :underline
|
117
|
+
text = @@pastel.underline(text)
|
118
|
+
when :inverse
|
119
|
+
text = @@pastel.inverse(text)
|
120
|
+
when :hidden
|
121
|
+
text = @@pastel.hidden(text)
|
122
|
+
when :strike, :strikethrough
|
123
|
+
text = @@pastel.strikethrough(text)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
if config.has_key? :color
|
129
|
+
case config[:color]
|
130
|
+
when :blue
|
131
|
+
text = @@pastel.bright_blue(text)
|
132
|
+
when :green
|
133
|
+
text = @@pastel.green(text)
|
134
|
+
when :yellow
|
135
|
+
text = @@pastel.yellow(text)
|
136
|
+
when :red
|
137
|
+
text = @@pastel.red(text)
|
138
|
+
when :purple, :magenta
|
139
|
+
text = @@pastel.magenta(text)
|
140
|
+
when :cyan
|
141
|
+
text = @@pastel.cyan(text)
|
142
|
+
end
|
76
143
|
end
|
144
|
+
|
145
|
+
text
|
77
146
|
end
|
78
147
|
|
79
148
|
# Override config from application.
|
data/lib/lit_pry.rb
CHANGED
@@ -1,68 +1,111 @@
|
|
1
1
|
# Only override kernel methods when Lit's @step flag is true.
|
2
2
|
if ENV['LIT_FLAGS'] && ENV['LIT_FLAGS'].include?('step')
|
3
|
+
require 'set'
|
4
|
+
|
5
|
+
# TODO: Investigate RubyGems `require` before overriding.
|
6
|
+
# SEE: https://github.com/ruby/ruby/blob/v2_6_3/lib/rubygems/core_ext/kernel_require.rb
|
7
|
+
|
3
8
|
module Kernel
|
4
9
|
|
5
|
-
|
6
|
-
filename = relative_path
|
10
|
+
@@lit_processed_paths = Set.new
|
7
11
|
|
8
|
-
|
9
|
-
|
10
|
-
absolute_path.pop
|
12
|
+
def require_relative relative_path, current_directory = nil
|
13
|
+
return false if relative_path.nil?
|
11
14
|
|
12
|
-
#
|
13
|
-
if relative_path.start_with?('
|
14
|
-
|
15
|
-
|
15
|
+
# Handle absolute path.
|
16
|
+
if relative_path.start_with?('/') && File.exist?(relative_path)
|
17
|
+
absolute_path = relative_path.split('/')
|
18
|
+
file_name = absolute_path.pop
|
19
|
+
# Handle relative path.
|
20
|
+
else
|
21
|
+
# Get directory of the file that called this file.
|
22
|
+
if current_directory.nil?
|
23
|
+
absolute_path = caller_locations.first.absolute_path.split('/')
|
24
|
+
absolute_path.pop
|
25
|
+
else
|
26
|
+
absolute_path = current_directory.split('/')
|
27
|
+
end
|
28
|
+
|
29
|
+
# When path is current directory.
|
30
|
+
if relative_path.start_with?('./')
|
31
|
+
relative_path.delete_prefix! './'
|
32
|
+
end
|
33
|
+
|
34
|
+
# When path is parent directory.
|
35
|
+
while relative_path.start_with?('../')
|
36
|
+
relative_path.delete_prefix! '../'
|
37
|
+
absolute_path.pop
|
38
|
+
end
|
39
|
+
|
40
|
+
# When path contains child directories.
|
41
|
+
if relative_path.split('/').count > 1
|
42
|
+
# Add child directories to absolute path and remove from relative path.
|
43
|
+
child_path = relative_path.split('/')
|
44
|
+
relative_path = child_path.pop
|
45
|
+
child_path.each do |dir|
|
46
|
+
absolute_path << dir
|
47
|
+
end
|
48
|
+
end
|
16
49
|
|
17
|
-
|
18
|
-
while relative_path.start_with?('../')
|
19
|
-
relative_path.delete_prefix! '../'
|
20
|
-
absolute_path.pop
|
50
|
+
file_name = relative_path
|
21
51
|
end
|
22
52
|
|
23
53
|
# Append default extension.
|
24
|
-
unless
|
25
|
-
|
54
|
+
unless file_name.end_with? '.rb'
|
55
|
+
file_name << '.rb'
|
26
56
|
end
|
27
57
|
|
28
|
-
|
58
|
+
file_path = File.join(absolute_path.join('/'), file_name)
|
29
59
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
new_lines
|
34
|
-
|
35
|
-
|
36
|
-
|
60
|
+
unless @@lit_processed_paths.include? file_path
|
61
|
+
@@lit_processed_paths.add file_path
|
62
|
+
|
63
|
+
new_lines = ''
|
64
|
+
line_count = 0
|
65
|
+
new_lines_count = 0
|
66
|
+
|
67
|
+
File.foreach(file_path) do |line|
|
68
|
+
line_count = line_count + 1
|
69
|
+
|
70
|
+
# Pass current directory into the next file's requires.
|
71
|
+
if line.strip.start_with? 'require_relative '
|
72
|
+
line = line.strip + ", '#{absolute_path.join('/')}'\n"
|
73
|
+
new_lines << line
|
74
|
+
# Add pry binding on each lit method.
|
75
|
+
elsif lit_line = Kernel.add_lit_binding(line)
|
76
|
+
new_lines << lit_line
|
77
|
+
else
|
78
|
+
new_lines << line
|
79
|
+
end
|
37
80
|
end
|
81
|
+
|
82
|
+
eval(new_lines, get_binding(__dir__ = absolute_path), file_path)
|
83
|
+
|
84
|
+
return true
|
85
|
+
# Path has already been required.
|
86
|
+
else
|
87
|
+
return false
|
38
88
|
end
|
89
|
+
end
|
39
90
|
|
40
|
-
|
91
|
+
def get_binding(__dir__)
|
92
|
+
# Don't go to this binding when Pry session activated.
|
93
|
+
# The variables have already been evaluated by eval(). NEEDS CONFIRMATION.
|
94
|
+
# Setting file_path in eval() negates this fix but will keep just in case.
|
95
|
+
return binding unless LitCLI.is_prying?
|
41
96
|
end
|
42
97
|
|
43
|
-
|
44
|
-
|
45
|
-
# absolute_path = File.join(Dir.pwd, path)
|
46
|
-
# #p "requiring #{absolute_path}"
|
47
|
-
# #p __dir__
|
48
|
-
# #p File.dirname(File.realpath(__FILE__))
|
49
|
-
# #p File.realpath(__FILE__)
|
50
|
-
#
|
51
|
-
# # Split client-side and server-side code.
|
52
|
-
# new_lines = []
|
53
|
-
# binding_line = "binding.pry if LitCLI.is_prying?"
|
54
|
-
#
|
55
|
-
# # Add pry binding beneath each lit message.
|
56
|
-
# p path
|
57
|
-
# File.foreach(path) do |line|
|
58
|
-
# new_lines << line
|
59
|
-
# if line.strip.start_with? 'lit "'
|
60
|
-
# new_lines << binding_line
|
61
|
-
# end
|
62
|
-
# end
|
63
|
-
#
|
64
|
-
# eval(new_lines.join)
|
65
|
-
# end
|
98
|
+
def self.add_lit_binding(line)
|
99
|
+
block = "{ binding.pry if LitCLI.is_prying?; @@is_prying = false }"
|
66
100
|
|
101
|
+
['lit ', 'lit(', '🔥 ', '🔥(', '🔥'].each do |needle|
|
102
|
+
if line.strip.start_with? needle
|
103
|
+
args = line.strip.delete_prefix(needle).delete_suffix(")").chomp
|
104
|
+
return "lit(#{args}) #{block} \n"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
false
|
109
|
+
end
|
67
110
|
end
|
68
111
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lit-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maedi Prichard
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02-
|
11
|
+
date: 2021-02-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pastel
|