lit-cli 0.6.2 → 0.8.1
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 -15
- data/lib/lit_pry.rb +30 -9
- 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: 1bff5862a0ee594b96b966d6ad15ef676d05596d482d24fdc8a306a56c3da7fb
|
4
|
+
data.tar.gz: 1c9f6b6abbab643a39240b2eb8ce683ed837d61a3ca8566f35503ace57d9dbe5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: addedd58a2dfe45a83b19597441735848a9014b9c379ce0864116bf2adfb325f0748d0d3733d5c6df6ca6a5d8731bb91bc86eed887d32ecc001270e64bc9268c
|
7
|
+
data.tar.gz: 03637e11d55ac63c0fe89d28355ce34cdda0159790069a59e8c2039bd803f83771d17cdf6a1b4e3eaa0da8c37d8b18aa65254184e449fbe3749661fb874953bb
|
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
@@ -13,9 +13,9 @@ module LitCLI
|
|
13
13
|
return if LitCLI.filter_status? status
|
14
14
|
return if LitCLI.filter_type? type
|
15
15
|
|
16
|
-
LitCLI.render(message, status, type, context)
|
16
|
+
indent = LitCLI.render(message, status, type, context)
|
17
17
|
|
18
|
-
LitCLI.step()
|
18
|
+
LitCLI.step(indent)
|
19
19
|
yield if block_given?
|
20
20
|
|
21
21
|
LitCLI.delay()
|
@@ -24,41 +24,71 @@ module LitCLI
|
|
24
24
|
alias 🔥 lit
|
25
25
|
|
26
26
|
def self.render(message, status, type, context)
|
27
|
-
|
27
|
+
output = "🔥"
|
28
28
|
|
29
29
|
# Time.
|
30
30
|
time = LitCLI.format(Time.now().strftime("%k:%M"), color: :cyan)
|
31
|
-
|
31
|
+
output << " #{time}"
|
32
32
|
|
33
33
|
# Status.
|
34
34
|
config = @@config.statuses[status]
|
35
|
-
|
35
|
+
output << LitCLI.format(" #{config[:icon]} #{status.to_s}", config)
|
36
36
|
|
37
37
|
# Type.
|
38
38
|
if !@@config.types.nil? && @@config.types.has_key?(type)
|
39
39
|
config = @@config.types[type]
|
40
40
|
if config.has_key? :icon
|
41
|
-
|
41
|
+
output << LitCLI.format(" #{config[:icon]} #{type.to_s}", config)
|
42
42
|
else
|
43
|
-
|
43
|
+
output << LitCLI.format(" #{type.to_s}", config)
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
47
|
# Context.
|
48
|
-
|
48
|
+
output << LitCLI.format(" #{context}", styles: [:bold, :dim])
|
49
49
|
|
50
|
-
#
|
51
|
-
|
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
|
52
67
|
|
53
|
-
|
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
|
77
|
+
|
78
|
+
puts output << " " + words.join()
|
79
|
+
|
80
|
+
return indent
|
54
81
|
end
|
55
82
|
|
56
|
-
def self.step()
|
83
|
+
def self.step(indent)
|
57
84
|
if @@config.step
|
58
|
-
puts "🔥 Press ENTER to step or P to Pry:"
|
85
|
+
puts "#{indent}🔥 Press ENTER to step or P to Pry:"
|
59
86
|
input = gets.chomp
|
60
87
|
binding while input == nil
|
61
|
-
|
88
|
+
if input.downcase == "p"
|
89
|
+
puts @@pastel.dim("Enter X to exit Pry or !!! to exit program.")
|
90
|
+
@@is_prying = true
|
91
|
+
end
|
62
92
|
end
|
63
93
|
end
|
64
94
|
|
@@ -149,7 +179,7 @@ module LitCLI
|
|
149
179
|
def self.configure()
|
150
180
|
yield(@@config)
|
151
181
|
|
152
|
-
# Override config from command line.
|
182
|
+
# Override config from flags on command line.
|
153
183
|
@@config.cli_configure()
|
154
184
|
end
|
155
185
|
|
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.
|
@@ -60,7 +60,6 @@ if ENV['LIT_FLAGS'] && ENV['LIT_FLAGS'].include?('step')
|
|
60
60
|
unless @@lit_processed_paths.include? file_path
|
61
61
|
@@lit_processed_paths.add file_path
|
62
62
|
|
63
|
-
binding = "{ binding.pry if LitCLI.is_prying?; @@is_prying = false }"
|
64
63
|
new_lines = ''
|
65
64
|
line_count = 0
|
66
65
|
new_lines_count = 0
|
@@ -72,14 +71,11 @@ if ENV['LIT_FLAGS'] && ENV['LIT_FLAGS'].include?('step')
|
|
72
71
|
if line.strip.start_with? 'require_relative '
|
73
72
|
line = line.strip + ", '#{absolute_path.join('/')}'\n"
|
74
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
|
75
77
|
else
|
76
|
-
|
77
|
-
if line.strip.start_with? 'lit '
|
78
|
-
lit_args = line.strip.delete_prefix('lit ').delete_suffix("\n")
|
79
|
-
new_lines << "lit(#{lit_args}) #{binding} \n"
|
80
|
-
else
|
81
|
-
new_lines << line
|
82
|
-
end
|
78
|
+
new_lines << line
|
83
79
|
end
|
84
80
|
end
|
85
81
|
|
@@ -98,5 +94,30 @@ if ENV['LIT_FLAGS'] && ENV['LIT_FLAGS'].include?('step')
|
|
98
94
|
# Setting file_path in eval() negates this fix but will keep just in case.
|
99
95
|
return binding unless LitCLI.is_prying?
|
100
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
|
101
108
|
end
|
102
109
|
end
|
110
|
+
|
111
|
+
##
|
112
|
+
# Add custom Pry command for a nicer exiting experience.
|
113
|
+
# @see https://github.com/pry/pry/wiki/Custom-commands
|
114
|
+
##
|
115
|
+
command_description = "Alias for `exit`"
|
116
|
+
|
117
|
+
Pry::Commands.block_command "x", command_description do
|
118
|
+
run "exit"
|
119
|
+
end
|
120
|
+
|
121
|
+
Pry::Commands.block_command "X", command_description do
|
122
|
+
run "exit"
|
123
|
+
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.1
|
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
|