lit-cli 0.0.3 → 0.5.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 +15 -2
- data/lib/config.rb +124 -0
- data/lib/lit_cli.rb +147 -0
- data/lib/lit_pry.rb +70 -0
- metadata +20 -4
- data/lib/api.rb +0 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d016a1786059f76f691d0dd55ab4a8d2e408f4b2ee5bca3d8e42ea29012d379
|
4
|
+
data.tar.gz: 5f0756f25977560051e7b07b86ae795584e954fa14eeb4533f56505c60d9cdfd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b902f2d26e1b868be3026783a2f99e10a34ca1be0851cd73b5c16c2a4ef23fad146b5f9f51ddaca41975b249833c6f382cd47468f21ef6c2ecfa1638a9a2382e
|
7
|
+
data.tar.gz: 01c08ebe1937ed4d31240aed5bcda06c4d5f85b9d6c28c23ca21b939e547e6267fc7e6248d7f3d14972bd5e9b1ea27dc74df5c38fd3d39f2aaa0a09e5340fef2
|
data/bin/lit
CHANGED
@@ -8,9 +8,22 @@
|
|
8
8
|
# lit rails server
|
9
9
|
################################################################################
|
10
10
|
|
11
|
-
# Enable Lit API.
|
12
11
|
ENV['LIT_ENABLED'] = 'true'
|
13
12
|
|
13
|
+
# Get flags from arguments.
|
14
|
+
args = []
|
15
|
+
flags = []
|
16
|
+
ARGV.each do |arg|
|
17
|
+
if arg.start_with? '@'
|
18
|
+
flags << arg.delete_prefix('@')
|
19
|
+
else
|
20
|
+
args << arg
|
21
|
+
end
|
22
|
+
end
|
23
|
+
ENV['LIT_FLAGS'] = flags.join " "
|
24
|
+
|
25
|
+
# Get user input.
|
26
|
+
command = args.join " "
|
27
|
+
|
14
28
|
# Action original command.
|
15
|
-
command = ARGV.join " "
|
16
29
|
system command
|
data/lib/config.rb
ADDED
@@ -0,0 +1,124 @@
|
|
1
|
+
require 'set'
|
2
|
+
|
3
|
+
module LitCLI
|
4
|
+
|
5
|
+
##############################################################################
|
6
|
+
# Default config that can be overridden from the command line or application.
|
7
|
+
#
|
8
|
+
# @usage:
|
9
|
+
# LitCLI.configure do |config|
|
10
|
+
# config.<property> = <value>
|
11
|
+
# end
|
12
|
+
#
|
13
|
+
# @precedence:
|
14
|
+
# 3. Defaults - initialize()
|
15
|
+
# 2. Application - LitCLI.configure()
|
16
|
+
# 1. Command line flags - cli_configure()
|
17
|
+
##############################################################################
|
18
|
+
|
19
|
+
class Config
|
20
|
+
|
21
|
+
# Track errors and only show them once.
|
22
|
+
@@errors = Set.new
|
23
|
+
|
24
|
+
attr_accessor :enabled
|
25
|
+
attr_accessor :statuses
|
26
|
+
attr_accessor :types
|
27
|
+
# Flags.
|
28
|
+
attr_accessor :step
|
29
|
+
attr_accessor :status
|
30
|
+
attr_accessor :type
|
31
|
+
attr_accessor :delay
|
32
|
+
|
33
|
+
def initialize()
|
34
|
+
|
35
|
+
@statuses = {
|
36
|
+
:info => { icon: "ℹ", color: :blue },
|
37
|
+
:pass => { icon: "✔", color: :green },
|
38
|
+
:warn => { icon: "⚠", color: :yellow },
|
39
|
+
:fail => { icon: "⨯", color: :red },
|
40
|
+
:error => { icon: "!", color: :red },
|
41
|
+
:debug => { icon: "?", color: :purple },
|
42
|
+
}
|
43
|
+
|
44
|
+
@types = nil
|
45
|
+
|
46
|
+
# Lit is disabled by default, then enabled via the `lit` command.
|
47
|
+
# Or it can be permanently enabled, without the use of the `lit` command.
|
48
|
+
@enabled = false
|
49
|
+
|
50
|
+
##
|
51
|
+
# FLAGS.
|
52
|
+
#
|
53
|
+
# Flag defaults when not supplied via command line.
|
54
|
+
##
|
55
|
+
|
56
|
+
# Boolean on whether or not to step through each lit() breakpoint.
|
57
|
+
@step = false
|
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
|
+
|
65
|
+
# Integer or float representing amount of seconds to delay each lit() by.
|
66
|
+
@delay = 0
|
67
|
+
|
68
|
+
cli_configure()
|
69
|
+
end
|
70
|
+
|
71
|
+
# Override config from command line.
|
72
|
+
def cli_configure()
|
73
|
+
@enabled = true if ENV['LIT_ENABLED'] == 'true'
|
74
|
+
|
75
|
+
# Convert flag string to hash.
|
76
|
+
flags = {}
|
77
|
+
if ENV['LIT_FLAGS'] && !ENV['LIT_FLAGS'].empty?
|
78
|
+
ENV['LIT_FLAGS'].split().each do |flag|
|
79
|
+
values = flag.split('=')
|
80
|
+
|
81
|
+
key = values.shift.to_sym
|
82
|
+
|
83
|
+
# No arguments.
|
84
|
+
if values.empty?
|
85
|
+
flags[key] = nil
|
86
|
+
else
|
87
|
+
args = values.pop.split(',')
|
88
|
+
# Single argument.
|
89
|
+
if args.count == 1
|
90
|
+
flags[key] = args.first
|
91
|
+
# Multiple arguments.
|
92
|
+
else
|
93
|
+
flags[key] = args
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
@step = true if flags.has_key? :step
|
100
|
+
@status = Array(flags[:status]).map(&:to_sym) if valid? flags, :status
|
101
|
+
@type = Array(flags[:type]).map(&:to_sym) if valid? flags, :type
|
102
|
+
@delay = flags[:delay].to_f if valid? flags, :delay
|
103
|
+
end
|
104
|
+
|
105
|
+
def valid? flags, flag
|
106
|
+
# Has flag even been entered on the command line?
|
107
|
+
unless flags.has_key? flag
|
108
|
+
return false
|
109
|
+
end
|
110
|
+
|
111
|
+
if flags[flag].nil?
|
112
|
+
error = "🔥 ERROR: Invalid argument for @#{flag}."
|
113
|
+
unless @@errors.include? error
|
114
|
+
@@errors.add error
|
115
|
+
puts error
|
116
|
+
end
|
117
|
+
return false
|
118
|
+
end
|
119
|
+
|
120
|
+
true
|
121
|
+
end
|
122
|
+
|
123
|
+
end
|
124
|
+
end
|
data/lib/lit_cli.rb
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
require 'pry'
|
2
|
+
require 'pastel'
|
3
|
+
require 'config'
|
4
|
+
require 'lit_pry'
|
5
|
+
|
6
|
+
module LitCLI
|
7
|
+
@@pastel = Pastel.new
|
8
|
+
@@config = Config.new
|
9
|
+
@@is_prying = false
|
10
|
+
|
11
|
+
def lit(message, status = :info, type = nil)
|
12
|
+
if @@config.enabled
|
13
|
+
return if LitCLI.filter_status? status
|
14
|
+
return if LitCLI.filter_type? type
|
15
|
+
LitCLI.render(message, status, type)
|
16
|
+
LitCLI.step()
|
17
|
+
LitCLI.delay()
|
18
|
+
end
|
19
|
+
end
|
20
|
+
alias 🔥 lit
|
21
|
+
|
22
|
+
def self.render(message, status, type)
|
23
|
+
text = "🔥"
|
24
|
+
|
25
|
+
# Time.
|
26
|
+
time = LitCLI.format(Time.now().strftime("%k:%M"), color: :cyan)
|
27
|
+
text << " #{time}"
|
28
|
+
|
29
|
+
# Status.
|
30
|
+
config = @@config.statuses[status]
|
31
|
+
text << LitCLI.format(" #{config[:icon]} #{status.to_s}", config)
|
32
|
+
|
33
|
+
# Type.
|
34
|
+
if !@@config.types.nil? && @@config.types.has_key?(type)
|
35
|
+
config = @@config.types[type]
|
36
|
+
if config.has_key? :icon
|
37
|
+
text << LitCLI.format(" #{config[:icon]} #{type.to_s}", config)
|
38
|
+
else
|
39
|
+
text << LitCLI.format(" #{type.to_s}", config)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
# Message.
|
44
|
+
text << " #{message}"
|
45
|
+
|
46
|
+
puts text
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.step()
|
50
|
+
if @@config.step
|
51
|
+
puts "🔥 Press ENTER to step or P to Pry:"
|
52
|
+
input = gets.chomp
|
53
|
+
binding while input == nil
|
54
|
+
@@is_prying = true if input.downcase == "p"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def self.filter_status? status
|
59
|
+
unless @@config.status.nil? || @@config.status.include?(status)
|
60
|
+
return true
|
61
|
+
end
|
62
|
+
|
63
|
+
false
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.filter_type? type
|
67
|
+
unless @@config.type.nil? || @@config.type.include?(type)
|
68
|
+
return true
|
69
|
+
end
|
70
|
+
|
71
|
+
false
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.delay()
|
75
|
+
if @@config.delay > 0
|
76
|
+
sleep(@@config.delay)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.is_prying?
|
81
|
+
@@config.step && @@is_prying
|
82
|
+
end
|
83
|
+
|
84
|
+
def self.format(text, config)
|
85
|
+
|
86
|
+
if config.has_key? :styles
|
87
|
+
# Change characters first.
|
88
|
+
config[:styles].each do |style|
|
89
|
+
case style
|
90
|
+
when :upcase
|
91
|
+
text = text.upcase
|
92
|
+
when :downcase
|
93
|
+
text = text.downcase
|
94
|
+
end
|
95
|
+
end
|
96
|
+
# Then apply styling.
|
97
|
+
config[:styles].each do |style|
|
98
|
+
case style
|
99
|
+
when :clear
|
100
|
+
text = @@pastel.clear(text)
|
101
|
+
when :bold
|
102
|
+
text = @@pastel.bold(text)
|
103
|
+
when :dim
|
104
|
+
text = @@pastel.dim(text)
|
105
|
+
when :italic
|
106
|
+
text = @@pastel.italic(text)
|
107
|
+
when :underline
|
108
|
+
text = @@pastel.underline(text)
|
109
|
+
when :inverse
|
110
|
+
text = @@pastel.inverse(text)
|
111
|
+
when :hidden
|
112
|
+
text = @@pastel.hidden(text)
|
113
|
+
when :strike, :strikethrough
|
114
|
+
text = @@pastel.strikethrough(text)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
if config.has_key? :color
|
120
|
+
case config[:color]
|
121
|
+
when :blue
|
122
|
+
text = @@pastel.bright_blue(text)
|
123
|
+
when :green
|
124
|
+
text = @@pastel.green(text)
|
125
|
+
when :yellow
|
126
|
+
text = @@pastel.yellow(text)
|
127
|
+
when :red
|
128
|
+
text = @@pastel.red(text)
|
129
|
+
when :purple, :magenta
|
130
|
+
text = @@pastel.magenta(text)
|
131
|
+
when :cyan
|
132
|
+
text = @@pastel.cyan(text)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
text
|
137
|
+
end
|
138
|
+
|
139
|
+
# Override config from application.
|
140
|
+
def self.configure()
|
141
|
+
yield(@@config)
|
142
|
+
|
143
|
+
# Override config from command line.
|
144
|
+
@@config.cli_configure()
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
data/lib/lit_pry.rb
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# Only override kernel methods when Lit's @step flag is true.
|
2
|
+
if ENV['LIT_FLAGS'] && ENV['LIT_FLAGS'].include?('step')
|
3
|
+
module Kernel
|
4
|
+
|
5
|
+
def require_relative relative_path
|
6
|
+
filename = relative_path
|
7
|
+
|
8
|
+
# Get directory of the file that called this file.
|
9
|
+
absolute_path = caller_locations.first.absolute_path.split('/')
|
10
|
+
absolute_path.pop
|
11
|
+
|
12
|
+
# When relative path is current directory.
|
13
|
+
if relative_path.start_with?('./')
|
14
|
+
filename = relative_path.delete_prefix! './'
|
15
|
+
end
|
16
|
+
|
17
|
+
# When relative path is parent directory.
|
18
|
+
while relative_path.start_with?('../')
|
19
|
+
relative_path.delete_prefix! '../'
|
20
|
+
absolute_path.pop
|
21
|
+
end
|
22
|
+
|
23
|
+
# Append default extension.
|
24
|
+
unless filename.end_with? '.rb'
|
25
|
+
filename << '.rb'
|
26
|
+
end
|
27
|
+
|
28
|
+
filepath = File.join(absolute_path.join('/'), relative_path)
|
29
|
+
|
30
|
+
# Add pry binding beneath each lit message.
|
31
|
+
new_lines = ''
|
32
|
+
File.foreach(filepath) do |line|
|
33
|
+
new_lines << line
|
34
|
+
if line.strip.start_with? 'lit "'
|
35
|
+
new_lines << "binding.pry if LitCLI.is_prying?\n"
|
36
|
+
new_lines << "@@is_prying = false\n"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
eval(new_lines)
|
41
|
+
end
|
42
|
+
|
43
|
+
# TODO: Investigate RubyGems `require` before overriding.
|
44
|
+
# SEE: https://github.com/ruby/ruby/blob/v2_6_3/lib/rubygems/core_ext/kernel_require.rb
|
45
|
+
#
|
46
|
+
# def require path
|
47
|
+
# absolute_path = File.join(Dir.pwd, path)
|
48
|
+
# #p "requiring #{absolute_path}"
|
49
|
+
# #p __dir__
|
50
|
+
# #p File.dirname(File.realpath(__FILE__))
|
51
|
+
# #p File.realpath(__FILE__)
|
52
|
+
#
|
53
|
+
# # Split client-side and server-side code.
|
54
|
+
# new_lines = []
|
55
|
+
# binding_line = "binding.pry if LitCLI.is_prying?"
|
56
|
+
#
|
57
|
+
# # Add pry binding beneath each lit message.
|
58
|
+
# p path
|
59
|
+
# File.foreach(path) do |line|
|
60
|
+
# new_lines << line
|
61
|
+
# if line.strip.start_with? 'lit "'
|
62
|
+
# new_lines << binding_line
|
63
|
+
# end
|
64
|
+
# end
|
65
|
+
#
|
66
|
+
# eval(new_lines.join)
|
67
|
+
# end
|
68
|
+
|
69
|
+
end
|
70
|
+
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.0
|
4
|
+
version: 0.5.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-08 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
|
@@ -32,7 +46,9 @@ extensions: []
|
|
32
46
|
extra_rdoc_files: []
|
33
47
|
files:
|
34
48
|
- bin/lit
|
35
|
-
- lib/
|
49
|
+
- lib/config.rb
|
50
|
+
- lib/lit_cli.rb
|
51
|
+
- lib/lit_pry.rb
|
36
52
|
homepage: https://reflekt.dev/lit
|
37
53
|
licenses:
|
38
54
|
- MPL-2.0
|
data/lib/api.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
# TODO: Define environment variable in parent process, not just child process.
|
2
|
-
# ENV['LIT_SUPPORTED'] = 'true'
|
3
|
-
|
4
|
-
require 'pastel'
|
5
|
-
|
6
|
-
module LitAPI
|
7
|
-
|
8
|
-
@@pastel = Pastel.new
|
9
|
-
|
10
|
-
def lit(message, status = :info)
|
11
|
-
|
12
|
-
if ENV['LIT_ENABLED'] == 'true'
|
13
|
-
|
14
|
-
time = Time.now().strftime("%k:%M")
|
15
|
-
status_style = status.to_s.upcase
|
16
|
-
status_icons = {
|
17
|
-
:info => "ℹ",
|
18
|
-
:pass => "✔",
|
19
|
-
:fail => "⨯"
|
20
|
-
}
|
21
|
-
|
22
|
-
message = "🔥 #{time}: #{message} (#{status_icons[status]} #{status_style})"
|
23
|
-
|
24
|
-
case status
|
25
|
-
when :info
|
26
|
-
puts @@pastel.bright_blue(message)
|
27
|
-
when :pass, :success
|
28
|
-
puts @@pastel.green(message)
|
29
|
-
when :fail
|
30
|
-
puts @@pastel.red(message)
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|