mdhost 0.1.1 → 0.2

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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/lib/mdhost.rb +83 -15
  4. data/mdhost.gemspec +1 -0
  5. metadata +16 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 22a9a1e6e40bfc450770d17f2893839890787d5ac895c3b4b1e5647f8d1212b7
4
- data.tar.gz: bc24e087846ae318ec4ab344e8018cf65a3da55460da3e976faf8e79005e2b52
3
+ metadata.gz: 5777cc6b150eb2b2d4fd99a8aa09b92d213b1c256bbebe84cb2e518f70c9a557
4
+ data.tar.gz: 749f2a4656b9ab982676021c0a023172353244eda49923b5b51de42c197556f5
5
5
  SHA512:
6
- metadata.gz: fb3d3b221e7a34a7103957ff446035bcc53a2b2d21d0ffd2510dfb640ccc0832754f65eaecf54d63abf5045bf6454f3ee17bf2f947cb40f63e8dbfbb33ecbee9
7
- data.tar.gz: 233f4d030ab19dd31cfa74d85a48570def4154162b66d7d56daf50067c94208b1f7c0272059088093392beca7977b752e6d3f2005bbdef1fd94a18b23af42229
6
+ metadata.gz: 02f255490e30db071012c1a29ab94d10cb252396d5b5d64f064ffed44666263b80e0625fbe2c709399f10f450832a1a51a63e192205e5bba99190a5e522d4651
7
+ data.tar.gz: b7bbb2a5feaae8386e8d85d423177d21fe7ee4700f63e747f3cab772811a8063decdf4e8adf4e1a577ab83bc354de3cc93a2e2b2a1245e4cd6d92d11e68b76cb
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2
data/lib/mdhost.rb CHANGED
@@ -1,34 +1,66 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "clipboard"
4
+ require "optimist"
4
5
 
5
- VERSION = File.read(File.expand_path("../VERSION", __dir__)).strip.freeze
6
+ FORMAT_SPECIFIER = '#{}'
6
7
 
7
8
  module MDHost
8
9
  class CLI
9
10
  def initialize
10
- if ARGV.empty? || %w[--version -v].include?(ARGV.first)
11
- puts "mdhost version #{VERSION}"
12
- exit 0
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
+
29
+ educate_on_error
13
30
  end
14
31
 
15
- @input = ARGV.first
32
+ if ARGV.empty?
33
+ Optimist::educate
34
+ end
16
35
  end
17
36
 
18
37
  def run
19
- # Display table
20
- system("eshost", "-h", "JavaScriptCore,SpiderMonkey,V8", "-te", @input)
21
-
22
- # Pretty escape the input (we'll be using it in the markdown so we want
23
- # it to look clean)
24
- escaped_input = if @input.include?("'") && @input.include?('"')
25
- "\"#{@input.gsub('"', '\"')}\""
26
- elsif @input.include?('"')
27
- "'#{@input}'"
38
+ if (@format_string = @options.format)
39
+ Optimist::educate unless @format_string.include?(FORMAT_SPECIFIER)
40
+ run_format
28
41
  else
29
- "\"#{@input}\""
42
+ @input = ARGV.first
43
+ run_single_input
30
44
  end
45
+ end
31
46
 
47
+ # Pretty escape the input (we might be using it in the markdown so
48
+ # we want it to look clean)
49
+ def escape_input(input)
50
+ if input.include?("'") && input.include?('"')
51
+ "\"#{input.gsub('"', '\"')}\""
52
+ elsif input.include?('"')
53
+ "'#{input}'"
54
+ else
55
+ "\"#{input}\""
56
+ end
57
+ end
58
+
59
+ def display_table(input)
60
+ system("eshost", "-h", "JavaScriptCore,SpiderMonkey,V8", "-te", input)
61
+ end
62
+
63
+ def results_for(escaped_input)
32
64
  result = `eshost -e #{escaped_input}`.split(/\n+/)
33
65
 
34
66
  # We can't just #each_slice by 2, because sometimes an engine acts up and
@@ -42,6 +74,18 @@ module MDHost
42
74
  end
43
75
  end
44
76
 
77
+ table
78
+ end
79
+
80
+ def run_single_input
81
+ display_table @input
82
+
83
+ escaped_input = escape_input @input
84
+
85
+ result = `eshost -e #{escaped_input}`.split(/\n+/)
86
+
87
+ table = results_for escaped_input
88
+
45
89
  # We don't *need* to pretty format the table so precisely, but why not?
46
90
  # The smallest this can be is 6 because of the length of the "Engine"
47
91
  # and "Result" headers.
@@ -63,5 +107,29 @@ module MDHost
63
107
 
64
108
  Clipboard.copy(output)
65
109
  end
110
+
111
+ def run_format
112
+ inputs = ARGV.map { |s| @format_string.sub(FORMAT_SPECIFIER, s) }
113
+ inputs.each do |input|
114
+ puts input
115
+ display_table input
116
+ end
117
+
118
+ output = +<<~TABLE
119
+ |Input|JavaScriptCore|SpiderMonkey|V8
120
+ |-----|--------------|------------|--
121
+ TABLE
122
+
123
+ inputs.each do |input|
124
+ escaped_input = escape_input input
125
+ results = results_for escaped_input
126
+
127
+ output << <<~ROW
128
+ |`#{input}`|#{results[:JavaScriptCore]}|#{results[:SpiderMonkey]}|#{results[:V8]}
129
+ ROW
130
+ end
131
+
132
+ Clipboard.copy(output)
133
+ end
66
134
  end
67
135
  end
data/mdhost.gemspec CHANGED
@@ -20,6 +20,7 @@ Gem::Specification.new do |gem|
20
20
  gem.files = `git ls-files -z`.split "\x0"
21
21
 
22
22
  gem.add_dependency "clipboard", "~> 1.1"
23
+ gem.add_dependency "optimist", "~> 3.1"
23
24
 
24
25
  gem.add_development_dependency "rubocop", "~> 1.54"
25
26
  end
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.1.1
4
+ version: '0.2'
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-10-12 00:00:00.000000000 Z
11
+ date: 2023-11-24 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