mdhost 0.1.1 → 0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +4 -0
- data/VERSION +1 -1
- data/lib/mdhost.rb +93 -15
- data/mdhost.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dbad6d4cf0eee94afaf0fb0d3b4b4de4daaefce726b93d6286f7d53b078c4d23
|
4
|
+
data.tar.gz: 2b2c6e7f473c8dc01e786ef247d44ab49b73e9bfc0d17d6ad420c5e5735ad8b9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8db2ff43540427438950d1b1b3a1977b1774f86e44a9bad1cd1336d742dd44dd7c02de0d560a267e06e436ff9e5b02aaa4764467c9b71634d740f4b71cc15ec
|
7
|
+
data.tar.gz: 2a98c530ee577254a2e9c59f67e64e898fbbd258e3478a4519c19584ba2d77eb98e828c3037769063bee90a8a07b204bfdb0b85eb5771628ae0d21fca3e28c27
|
data/.rubocop.yml
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3
|
data/lib/mdhost.rb
CHANGED
@@ -1,34 +1,73 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require "clipboard"
|
4
|
+
require "optimist"
|
4
5
|
|
5
|
-
|
6
|
+
FORMAT_SPECIFIER = '#{}'
|
6
7
|
|
7
8
|
module MDHost
|
8
9
|
class CLI
|
9
10
|
def initialize
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
@options = Optimist.options do
|
12
|
+
version "mdhost #{File.read(File.expand_path('../VERSION', __dir__)).strip}"
|
13
|
+
|
14
|
+
banner <<~BANNER
|
15
|
+
#{version}
|
16
|
+
|
17
|
+
Usage:
|
18
|
+
mdhost INPUT
|
19
|
+
mdhost --format FORMAT_STRING INPUTS...
|
20
|
+
|
21
|
+
Given a format string, inputs will be formatted to the location of
|
22
|
+
the sequence #{FORMAT_SPECIFIER}
|
23
|
+
|
24
|
+
Options:
|
25
|
+
BANNER
|
26
|
+
|
27
|
+
opt :format, "Format string to compose multiple inputs into", type: :string
|
28
|
+
opt :table_format, 'Format string to use for the table "Input" column', type: :string
|
29
|
+
|
30
|
+
educate_on_error
|
13
31
|
end
|
14
32
|
|
15
|
-
|
33
|
+
if ARGV.empty?
|
34
|
+
Optimist.educate
|
35
|
+
end
|
16
36
|
end
|
17
37
|
|
18
38
|
def run
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
39
|
+
@format_string = @options.format
|
40
|
+
|
41
|
+
if !@format_string && ARGV.length > 1
|
42
|
+
@format_string = FORMAT_SPECIFIER
|
43
|
+
end
|
44
|
+
|
45
|
+
if @format_string
|
46
|
+
Optimist.educate unless @format_string.include?(FORMAT_SPECIFIER)
|
47
|
+
run_format
|
48
|
+
else
|
49
|
+
@input = ARGV.first
|
50
|
+
run_single_input
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
# Pretty escape the input (we might be using it in the markdown so
|
55
|
+
# we want it to look clean)
|
56
|
+
def escape_input(input)
|
57
|
+
if input.include?("'") && input.include?('"')
|
58
|
+
"\"#{input.gsub('"', '\"')}\""
|
59
|
+
elsif input.include?('"')
|
60
|
+
"'#{input}'"
|
28
61
|
else
|
29
|
-
"\"#{
|
62
|
+
"\"#{input}\""
|
30
63
|
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def display_table(input)
|
67
|
+
system("eshost", "-h", "JavaScriptCore,SpiderMonkey,V8", "-te", input)
|
68
|
+
end
|
31
69
|
|
70
|
+
def results_for(escaped_input)
|
32
71
|
result = `eshost -e #{escaped_input}`.split(/\n+/)
|
33
72
|
|
34
73
|
# We can't just #each_slice by 2, because sometimes an engine acts up and
|
@@ -42,6 +81,15 @@ module MDHost
|
|
42
81
|
end
|
43
82
|
end
|
44
83
|
|
84
|
+
table
|
85
|
+
end
|
86
|
+
|
87
|
+
def run_single_input
|
88
|
+
display_table @input
|
89
|
+
|
90
|
+
escaped_input = escape_input @input
|
91
|
+
table = results_for escaped_input
|
92
|
+
|
45
93
|
# We don't *need* to pretty format the table so precisely, but why not?
|
46
94
|
# The smallest this can be is 6 because of the length of the "Engine"
|
47
95
|
# and "Result" headers.
|
@@ -63,5 +111,35 @@ module MDHost
|
|
63
111
|
|
64
112
|
Clipboard.copy(output)
|
65
113
|
end
|
114
|
+
|
115
|
+
def format(format_string, input)
|
116
|
+
format_string.sub(FORMAT_SPECIFIER, input)
|
117
|
+
end
|
118
|
+
|
119
|
+
def run_format
|
120
|
+
output = +<<~TABLE
|
121
|
+
|Input|JavaScriptCore|SpiderMonkey|V8
|
122
|
+
|-----|--------------|------------|--
|
123
|
+
TABLE
|
124
|
+
|
125
|
+
ARGV.each do |input|
|
126
|
+
formatted_input = format(@format_string, input)
|
127
|
+
|
128
|
+
puts formatted_input
|
129
|
+
display_table formatted_input
|
130
|
+
|
131
|
+
escaped_input = escape_input formatted_input
|
132
|
+
results = results_for escaped_input
|
133
|
+
|
134
|
+
display_input = @options.table_format ? format(@options.table_format, input)
|
135
|
+
: formatted_input
|
136
|
+
|
137
|
+
output << <<~ROW
|
138
|
+
|`#{display_input}`|#{results[:JavaScriptCore]}|#{results[:SpiderMonkey]}|#{results[:V8]}
|
139
|
+
ROW
|
140
|
+
end
|
141
|
+
|
142
|
+
Clipboard.copy(output)
|
143
|
+
end
|
66
144
|
end
|
67
145
|
end
|
data/mdhost.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mdhost
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.3'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vinny Diehl
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-11-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: clipboard
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: optimist
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.1'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.1'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rubocop
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|