lit-cli 0.1.0 → 0.2.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 -3
- data/lib/config.rb +81 -0
- data/lib/lit_cli.rb +44 -11
- 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: 642edf5650f6fbfd2b92ed421ee1b7a205c6fbe7fa14a4e9c24fe06d07d443c8
|
4
|
+
data.tar.gz: 9b090b0c6a37d47d2257eb5e1723df8ea5793e18d9eddb224a06817e111501ad
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 122442d065db2aaf73e01d4629940a57e12b5ae88bdd2bf57bcdaddaab2548950b9ee522ca1080ad5577bb9ab7e3db5aea61db0d7ca319f1c3a1415225bf76af
|
7
|
+
data.tar.gz: 3c438491edf8cd0b0c7854321486f37c0a443ccac2ed6d1de32776b1aa05822152030d73fed0a315e832ebea4d688a82484fa1ce6c3aaef5d26ddc7782e258d7
|
data/bin/lit
CHANGED
@@ -8,13 +8,11 @@
|
|
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
14
|
args = []
|
15
15
|
flags = []
|
16
|
-
|
17
|
-
# Get flags from arguments.
|
18
16
|
ARGV.each do |arg|
|
19
17
|
if arg.start_with? '@'
|
20
18
|
flags << arg.delete_prefix('@')
|
data/lib/config.rb
CHANGED
@@ -1,9 +1,29 @@
|
|
1
1
|
module LitCLI
|
2
|
+
|
3
|
+
##############################################################################
|
4
|
+
# Default config that can be overridden from the command line or application.
|
5
|
+
#
|
6
|
+
# @usage:
|
7
|
+
# LitCLI.configure do |config|
|
8
|
+
# config.<property> = <value>
|
9
|
+
# end
|
10
|
+
#
|
11
|
+
# @precedence:
|
12
|
+
# 3. Defaults - initialize()
|
13
|
+
# 2. Application - LitCLI.configure()
|
14
|
+
# 1. Command line flags - cli_configure()
|
15
|
+
##############################################################################
|
16
|
+
|
2
17
|
class Config
|
3
18
|
|
19
|
+
attr_accessor :enabled
|
4
20
|
attr_accessor :types
|
21
|
+
attr_accessor :type
|
22
|
+
attr_accessor :step
|
23
|
+
attr_accessor :delay
|
5
24
|
|
6
25
|
def initialize()
|
26
|
+
|
7
27
|
@types = {
|
8
28
|
:info => { icon: "ℹ", color: :blue },
|
9
29
|
:pass => { icon: "✔", color: :green },
|
@@ -12,6 +32,67 @@ module LitCLI
|
|
12
32
|
:error => { icon: "!", color: :red },
|
13
33
|
:debug => { icon: "?", color: :purple },
|
14
34
|
}
|
35
|
+
|
36
|
+
# Lit is disabled by default, then enabled via the `lit` command.
|
37
|
+
# Or it can be permanently enabled, without the use of the `lit` command.
|
38
|
+
@enabled = false
|
39
|
+
|
40
|
+
##
|
41
|
+
# FLAGS.
|
42
|
+
#
|
43
|
+
# Flag defaults when not supplied via command line.
|
44
|
+
##
|
45
|
+
|
46
|
+
# Array of types to filter by, for example... [:warn, :error, :fail]
|
47
|
+
@type = nil
|
48
|
+
|
49
|
+
# Boolean on whether or not to step through each lit() breakpoint.
|
50
|
+
@step = false
|
51
|
+
|
52
|
+
# Integer or float representing amount of seconds to delay each lit() by.
|
53
|
+
@delay = 0
|
54
|
+
|
55
|
+
cli_configure()
|
56
|
+
end
|
57
|
+
|
58
|
+
# Override config from command line.
|
59
|
+
def cli_configure()
|
60
|
+
@enabled = true if ENV['LIT_ENABLED'] == 'true'
|
61
|
+
|
62
|
+
# Convert flag string to hash.
|
63
|
+
flags = {}
|
64
|
+
if ENV['LIT_FLAGS'] && !ENV['LIT_FLAGS'].empty?
|
65
|
+
ENV['LIT_FLAGS'].split().each do |flag|
|
66
|
+
values = flag.split('=')
|
67
|
+
|
68
|
+
key = values.shift.to_sym
|
69
|
+
|
70
|
+
# No arguments.
|
71
|
+
if values.empty?
|
72
|
+
flags[key] = nil
|
73
|
+
else
|
74
|
+
args = values.pop.split(',')
|
75
|
+
# Single argument.
|
76
|
+
if args.count == 1
|
77
|
+
flags[key] = args.first
|
78
|
+
# Multiple arguments.
|
79
|
+
else
|
80
|
+
flags[key] = args
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
@type = flags[:type] if flags.has_key? :type
|
87
|
+
@step = true if flags.has_key? :step
|
88
|
+
|
89
|
+
if flags.has_key? :delay
|
90
|
+
unless flags[:delay].nil?
|
91
|
+
@delay = flags[:delay].to_f
|
92
|
+
else
|
93
|
+
puts "🔥 ERROR: Invalid argument."
|
94
|
+
end
|
95
|
+
end
|
15
96
|
end
|
16
97
|
|
17
98
|
end
|
data/lib/lit_cli.rb
CHANGED
@@ -2,23 +2,48 @@ require 'pastel'
|
|
2
2
|
require 'config'
|
3
3
|
|
4
4
|
module LitCLI
|
5
|
-
|
6
5
|
@@pastel = Pastel.new
|
7
|
-
@@config = Config.new
|
6
|
+
@@config = Config.new
|
8
7
|
|
9
8
|
def lit(message, type = :info)
|
10
|
-
if
|
11
|
-
|
9
|
+
if @@config.enabled
|
10
|
+
filter(type)
|
11
|
+
render(type)
|
12
|
+
step()
|
13
|
+
delay()
|
14
|
+
end
|
15
|
+
end
|
16
|
+
alias 🔥 lit
|
17
|
+
|
18
|
+
def render(type)
|
19
|
+
type_config = @@config.types[type]
|
12
20
|
|
13
|
-
|
14
|
-
|
15
|
-
|
21
|
+
time_text = LitCLI.colorize(Time.now().strftime("%k:%M"), :cyan)
|
22
|
+
type_text = type_config[:icon] + " " + type.to_s
|
23
|
+
type_text_color = LitCLI.colorize(type_text, type_config[:color])
|
24
|
+
|
25
|
+
message = "🔥 #{time_text} #{type_text_color} #{message}"
|
26
|
+
|
27
|
+
puts message
|
28
|
+
end
|
29
|
+
|
30
|
+
def filter(type)
|
31
|
+
if @@config.type
|
16
32
|
|
17
|
-
message = "🔥 #{time_text} #{type_text_color} #{message}"
|
18
|
-
puts message
|
19
33
|
end
|
20
34
|
end
|
21
|
-
|
35
|
+
|
36
|
+
def step()
|
37
|
+
if @@config.step
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def delay()
|
43
|
+
if @@config.delay > 0
|
44
|
+
sleep(@@config.delay)
|
45
|
+
end
|
46
|
+
end
|
22
47
|
|
23
48
|
def self.colorize(text, color)
|
24
49
|
case color
|
@@ -39,8 +64,16 @@ module LitCLI
|
|
39
64
|
end
|
40
65
|
end
|
41
66
|
|
42
|
-
|
67
|
+
# Override config from application.
|
68
|
+
def self.configure()
|
43
69
|
yield(@@config)
|
70
|
+
|
71
|
+
# Override config from command line.
|
72
|
+
@@config.cli_configure()
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.error(message)
|
76
|
+
puts "🔥 ERROR: #{message}"
|
44
77
|
end
|
45
78
|
|
46
79
|
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.2.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-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: pastel
|