lit-cli 0.3.0 → 0.6.2
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 +109 -32
- data/lib/lit_pry.rb +102 -0
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 865eec42e3e343a9432bc24ee852290159545a83c0d80c835555d3a7de965355
|
4
|
+
data.tar.gz: ca99ccd747ac4091e93d1e703183ea63f122ed46b6883bd24588ad0c6ccdf809
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64c4afe108dfadbdf6690963a1fb891ecf9dcf4bfd28402087cbeeafc37796e00d9564ce9d436139a1832af211330a61f428d15d5bb07add496347584245191e
|
7
|
+
data.tar.gz: dee1223cefa077ce2b38cf060169ad1bb882b9fec8aac7a42e76834a77fc2a8b6c53d30a62b6695750388742bca48633b59d4656fac1c3dbe563e1e1e2e46d41
|
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
@@ -1,41 +1,76 @@
|
|
1
|
+
require 'pry'
|
1
2
|
require 'pastel'
|
2
3
|
require 'config'
|
4
|
+
require 'lit_pry'
|
3
5
|
|
4
6
|
module LitCLI
|
5
7
|
@@pastel = Pastel.new
|
6
8
|
@@config = Config.new
|
9
|
+
@@is_prying = false
|
7
10
|
|
8
|
-
def lit(message,
|
11
|
+
def lit(message, status = :info, type = nil, context = nil)
|
9
12
|
if @@config.enabled
|
10
|
-
return if
|
11
|
-
|
12
|
-
|
13
|
-
|
13
|
+
return if LitCLI.filter_status? status
|
14
|
+
return if LitCLI.filter_type? type
|
15
|
+
|
16
|
+
LitCLI.render(message, status, type, context)
|
17
|
+
|
18
|
+
LitCLI.step()
|
19
|
+
yield if block_given?
|
20
|
+
|
21
|
+
LitCLI.delay()
|
14
22
|
end
|
15
23
|
end
|
16
24
|
alias 🔥 lit
|
17
25
|
|
18
|
-
def render(type)
|
19
|
-
|
26
|
+
def self.render(message, status, type, context)
|
27
|
+
text = "🔥"
|
28
|
+
|
29
|
+
# Time.
|
30
|
+
time = LitCLI.format(Time.now().strftime("%k:%M"), color: :cyan)
|
31
|
+
text << " #{time}"
|
32
|
+
|
33
|
+
# Status.
|
34
|
+
config = @@config.statuses[status]
|
35
|
+
text << LitCLI.format(" #{config[:icon]} #{status.to_s}", config)
|
20
36
|
|
21
|
-
|
22
|
-
|
23
|
-
|
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
|
46
|
+
|
47
|
+
# Context.
|
48
|
+
text << LitCLI.format(" #{context}", styles: [:bold, :dim])
|
24
49
|
|
25
|
-
|
50
|
+
# Message.
|
51
|
+
text << " #{message}"
|
26
52
|
|
27
|
-
puts
|
53
|
+
puts text
|
28
54
|
end
|
29
55
|
|
30
|
-
def step()
|
56
|
+
def self.step()
|
31
57
|
if @@config.step
|
32
|
-
puts "🔥
|
58
|
+
puts "🔥 Press ENTER to step or P to Pry:"
|
33
59
|
input = gets.chomp
|
34
60
|
binding while input == nil
|
61
|
+
@@is_prying = true if input.downcase == "p"
|
35
62
|
end
|
36
63
|
end
|
37
64
|
|
38
|
-
def
|
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
|
39
74
|
unless @@config.type.nil? || @@config.type.include?(type)
|
40
75
|
return true
|
41
76
|
end
|
@@ -43,29 +78,71 @@ module LitCLI
|
|
43
78
|
false
|
44
79
|
end
|
45
80
|
|
46
|
-
def delay()
|
81
|
+
def self.delay()
|
47
82
|
if @@config.delay > 0
|
48
83
|
sleep(@@config.delay)
|
49
84
|
end
|
50
85
|
end
|
51
86
|
|
52
|
-
def self.
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
87
|
+
def self.is_prying?
|
88
|
+
@@config.step && @@is_prying
|
89
|
+
end
|
90
|
+
|
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
|
68
143
|
end
|
144
|
+
|
145
|
+
text
|
69
146
|
end
|
70
147
|
|
71
148
|
# Override config from application.
|
data/lib/lit_pry.rb
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
# Only override kernel methods when Lit's @step flag is true.
|
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
|
+
|
8
|
+
module Kernel
|
9
|
+
|
10
|
+
@@lit_processed_paths = Set.new
|
11
|
+
|
12
|
+
def require_relative relative_path, current_directory = nil
|
13
|
+
return false if relative_path.nil?
|
14
|
+
|
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
|
49
|
+
|
50
|
+
file_name = relative_path
|
51
|
+
end
|
52
|
+
|
53
|
+
# Append default extension.
|
54
|
+
unless file_name.end_with? '.rb'
|
55
|
+
file_name << '.rb'
|
56
|
+
end
|
57
|
+
|
58
|
+
file_path = File.join(absolute_path.join('/'), file_name)
|
59
|
+
|
60
|
+
unless @@lit_processed_paths.include? file_path
|
61
|
+
@@lit_processed_paths.add file_path
|
62
|
+
|
63
|
+
binding = "{ binding.pry if LitCLI.is_prying?; @@is_prying = false }"
|
64
|
+
new_lines = ''
|
65
|
+
line_count = 0
|
66
|
+
new_lines_count = 0
|
67
|
+
|
68
|
+
File.foreach(file_path) do |line|
|
69
|
+
line_count = line_count + 1
|
70
|
+
|
71
|
+
# Pass current directory into the next file's requires.
|
72
|
+
if line.strip.start_with? 'require_relative '
|
73
|
+
line = line.strip + ", '#{absolute_path.join('/')}'\n"
|
74
|
+
new_lines << line
|
75
|
+
else
|
76
|
+
# Add pry binding beneath each lit message.
|
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
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
eval(new_lines, get_binding(__dir__ = absolute_path), file_path)
|
87
|
+
|
88
|
+
return true
|
89
|
+
# Path has already been required.
|
90
|
+
else
|
91
|
+
return false
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
def get_binding(__dir__)
|
96
|
+
# Don't go to this binding when Pry session activated.
|
97
|
+
# The variables have already been evaluated by eval(). NEEDS CONFIRMATION.
|
98
|
+
# Setting file_path in eval() negates this fix but will keep just in case.
|
99
|
+
return binding unless LitCLI.is_prying?
|
100
|
+
end
|
101
|
+
end
|
102
|
+
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.2
|
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-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pastel
|
@@ -24,7 +24,21 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
-
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Console logs that are only visible after prefixing commands with 'lit'.
|
28
42
|
email: maediprichard@gmail.com
|
29
43
|
executables:
|
30
44
|
- lit
|
@@ -34,6 +48,7 @@ files:
|
|
34
48
|
- bin/lit
|
35
49
|
- lib/config.rb
|
36
50
|
- lib/lit_cli.rb
|
51
|
+
- lib/lit_pry.rb
|
37
52
|
homepage: https://reflekt.dev/lit
|
38
53
|
licenses:
|
39
54
|
- MPL-2.0
|