lit-cli 0.6.1 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/lit +1 -1
- data/lib/config.rb +12 -4
- data/lib/lit_cli.rb +45 -14
- data/lib/lit_pry.rb +20 -7
- 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: d7d27ec65b3d6ead4109e2ec4509c30ad071645bb2f0cac4b8e9fd0ee27e1e2e
|
4
|
+
data.tar.gz: efd72529bd96e50d8e286ab9cf3fe610e6077728282a15bd640c5195d15a8562
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5ab9a686068313a84c120a354303ccdc2d9d24db4e6eafaf0ea45c9adedf8b59952b0503f52268b5765b45a5bb1f0bc0800d0b199d770a3f87b9c90e4d1b700
|
7
|
+
data.tar.gz: 548cb66165d4f9b9b396dbd7e2d554008d7450d2bafadfdb13a8fe19b61b104bf80428d1ae3c90120bc368bf8ce4d84484594237f82929bd37f8712797c7fe71
|
data/bin/lit
CHANGED
data/lib/config.rb
CHANGED
@@ -53,9 +53,6 @@ module LitCLI
|
|
53
53
|
# Flag defaults when not supplied via command line.
|
54
54
|
##
|
55
55
|
|
56
|
-
# Boolean on whether or not to step through each lit() breakpoint.
|
57
|
-
@step = false
|
58
|
-
|
59
56
|
# Array of statuses to filter by, for example: [:warn, :error, :fail]
|
60
57
|
@status = nil
|
61
58
|
|
@@ -65,12 +62,23 @@ module LitCLI
|
|
65
62
|
# Integer or float representing amount of seconds to delay each lit() by.
|
66
63
|
@delay = 0
|
67
64
|
|
65
|
+
##
|
66
|
+
# PRIVATE.
|
67
|
+
##
|
68
|
+
|
69
|
+
# Boolean on whether or not to step through each lit() breakpoint.
|
70
|
+
# Setting to true here wont enable Pry, best to enable via command line.
|
71
|
+
@step = false
|
72
|
+
|
68
73
|
cli_configure()
|
69
74
|
end
|
70
75
|
|
71
76
|
# Override config from command line.
|
72
77
|
def cli_configure()
|
73
|
-
|
78
|
+
|
79
|
+
# Enable lit via the command line.
|
80
|
+
@enabled = true if ENV['LIT_ENABLED'] && ENV['LIT_ENABLED'].to_i >= (Time.now.to_i() - 1)
|
81
|
+
return unless @enabled
|
74
82
|
|
75
83
|
# Convert flag string to hash.
|
76
84
|
flags = {}
|
data/lib/lit_cli.rb
CHANGED
@@ -12,46 +12,77 @@ module LitCLI
|
|
12
12
|
if @@config.enabled
|
13
13
|
return if LitCLI.filter_status? status
|
14
14
|
return if LitCLI.filter_type? type
|
15
|
-
|
16
|
-
LitCLI.
|
15
|
+
|
16
|
+
indent = LitCLI.render(message, status, type, context)
|
17
|
+
|
18
|
+
LitCLI.step(indent)
|
19
|
+
yield if block_given?
|
20
|
+
|
17
21
|
LitCLI.delay()
|
18
22
|
end
|
19
23
|
end
|
20
24
|
alias 🔥 lit
|
21
25
|
|
22
26
|
def self.render(message, status, type, context)
|
23
|
-
|
27
|
+
output = "🔥"
|
24
28
|
|
25
29
|
# Time.
|
26
30
|
time = LitCLI.format(Time.now().strftime("%k:%M"), color: :cyan)
|
27
|
-
|
31
|
+
output << " #{time}"
|
28
32
|
|
29
33
|
# Status.
|
30
34
|
config = @@config.statuses[status]
|
31
|
-
|
35
|
+
output << LitCLI.format(" #{config[:icon]} #{status.to_s}", config)
|
32
36
|
|
33
37
|
# Type.
|
34
38
|
if !@@config.types.nil? && @@config.types.has_key?(type)
|
35
39
|
config = @@config.types[type]
|
36
40
|
if config.has_key? :icon
|
37
|
-
|
41
|
+
output << LitCLI.format(" #{config[:icon]} #{type.to_s}", config)
|
38
42
|
else
|
39
|
-
|
43
|
+
output << LitCLI.format(" #{type.to_s}", config)
|
40
44
|
end
|
41
45
|
end
|
42
46
|
|
43
47
|
# Context.
|
44
|
-
|
48
|
+
output << LitCLI.format(" #{context}", styles: [:bold, :dim])
|
49
|
+
|
50
|
+
# Line break.
|
51
|
+
while message.start_with?('^')
|
52
|
+
message.delete_prefix!('^').strip!
|
53
|
+
unless @@config.status || @@config.type
|
54
|
+
output = "\n" + output
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# Indent.
|
59
|
+
indent = ''
|
60
|
+
while message.start_with?('>')
|
61
|
+
message.delete_prefix!('>').strip!
|
62
|
+
unless @@config.status || @@config.type
|
63
|
+
indent = indent + ' '
|
64
|
+
output = ' ' + output
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# Highlight numbers and methods.
|
69
|
+
words = []
|
70
|
+
message.split(/(#\d+|\w+\(\))/).each do |word|
|
71
|
+
if word.start_with?('#') || word.end_with?(')')
|
72
|
+
words << @@pastel.yellow(word)
|
73
|
+
else
|
74
|
+
words << word
|
75
|
+
end
|
76
|
+
end
|
45
77
|
|
46
|
-
|
47
|
-
text << " #{message}"
|
78
|
+
puts output << " " + words.join()
|
48
79
|
|
49
|
-
|
80
|
+
return indent
|
50
81
|
end
|
51
82
|
|
52
|
-
def self.step()
|
83
|
+
def self.step(indent)
|
53
84
|
if @@config.step
|
54
|
-
puts "🔥 Press ENTER to step or P to Pry:"
|
85
|
+
puts "#{indent}🔥 Press ENTER to step or P to Pry:"
|
55
86
|
input = gets.chomp
|
56
87
|
binding while input == nil
|
57
88
|
@@is_prying = true if input.downcase == "p"
|
@@ -145,7 +176,7 @@ module LitCLI
|
|
145
176
|
def self.configure()
|
146
177
|
yield(@@config)
|
147
178
|
|
148
|
-
# Override config from command line.
|
179
|
+
# Override config from flags on command line.
|
149
180
|
@@config.cli_configure()
|
150
181
|
end
|
151
182
|
|
data/lib/lit_pry.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# Only override kernel methods when Lit's @step flag is true.
|
2
|
-
if ENV['LIT_FLAGS'] && ENV['LIT_FLAGS'].include?('step')
|
2
|
+
if ENV['LIT_ENABLED'] && ENV['LIT_ENABLED'].to_i >= (Time.now.to_i() - 1) && ENV['LIT_FLAGS'] && ENV['LIT_FLAGS'].include?('step')
|
3
3
|
require 'set'
|
4
4
|
|
5
5
|
# TODO: Investigate RubyGems `require` before overriding.
|
@@ -61,24 +61,26 @@ if ENV['LIT_FLAGS'] && ENV['LIT_FLAGS'].include?('step')
|
|
61
61
|
@@lit_processed_paths.add file_path
|
62
62
|
|
63
63
|
new_lines = ''
|
64
|
+
line_count = 0
|
65
|
+
new_lines_count = 0
|
66
|
+
|
64
67
|
File.foreach(file_path) do |line|
|
68
|
+
line_count = line_count + 1
|
65
69
|
|
66
70
|
# Pass current directory into the next file's requires.
|
67
71
|
if line.strip.start_with? 'require_relative '
|
68
72
|
line = line.strip + ", '#{absolute_path.join('/')}'\n"
|
69
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
|
70
77
|
else
|
71
78
|
new_lines << line
|
72
79
|
end
|
73
|
-
|
74
|
-
# Add pry binding beneath each lit message.
|
75
|
-
if line.strip.start_with? 'lit "'
|
76
|
-
new_lines << "binding.pry if LitCLI.is_prying?\n"
|
77
|
-
new_lines << "@@is_prying = false\n"
|
78
|
-
end
|
79
80
|
end
|
80
81
|
|
81
82
|
eval(new_lines, get_binding(__dir__ = absolute_path), file_path)
|
83
|
+
|
82
84
|
return true
|
83
85
|
# Path has already been required.
|
84
86
|
else
|
@@ -92,5 +94,16 @@ if ENV['LIT_FLAGS'] && ENV['LIT_FLAGS'].include?('step')
|
|
92
94
|
# Setting file_path in eval() negates this fix but will keep just in case.
|
93
95
|
return binding unless LitCLI.is_prying?
|
94
96
|
end
|
97
|
+
|
98
|
+
def self.add_lit_binding(line)
|
99
|
+
['lit ', 'lit(', '🔥 ', '🔥(', '🔥'].each do |needle|
|
100
|
+
if line.strip.start_with? needle
|
101
|
+
args = line.strip.delete_prefix(needle).delete_suffix(")").chomp
|
102
|
+
return "lit(#{args}) { binding.pry if LitCLI.is_prying?; @@is_prying = false } \n"
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
false
|
107
|
+
end
|
95
108
|
end
|
96
109
|
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.8.0
|
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-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pastel
|