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.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +4 -0
  3. data/VERSION +1 -1
  4. data/lib/mdhost.rb +93 -15
  5. data/mdhost.gemspec +1 -0
  6. 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: dbad6d4cf0eee94afaf0fb0d3b4b4de4daaefce726b93d6286f7d53b078c4d23
4
+ data.tar.gz: 2b2c6e7f473c8dc01e786ef247d44ab49b73e9bfc0d17d6ad420c5e5735ad8b9
5
5
  SHA512:
6
- metadata.gz: fb3d3b221e7a34a7103957ff446035bcc53a2b2d21d0ffd2510dfb640ccc0832754f65eaecf54d63abf5045bf6454f3ee17bf2f947cb40f63e8dbfbb33ecbee9
7
- data.tar.gz: 233f4d030ab19dd31cfa74d85a48570def4154162b66d7d56daf50067c94208b1f7c0272059088093392beca7977b752e6d3f2005bbdef1fd94a18b23af42229
6
+ metadata.gz: d8db2ff43540427438950d1b1b3a1977b1774f86e44a9bad1cd1336d742dd44dd7c02de0d560a267e06e436ff9e5b02aaa4764467c9b71634d740f4b71cc15ec
7
+ data.tar.gz: 2a98c530ee577254a2e9c59f67e64e898fbbd258e3478a4519c19584ba2d77eb98e828c3037769063bee90a8a07b204bfdb0b85eb5771628ae0d21fca3e28c27
data/.rubocop.yml CHANGED
@@ -29,6 +29,10 @@ Layout/SpaceAroundEqualsInParameterDefault:
29
29
  Layout/TrailingWhitespace:
30
30
  AllowInHeredoc: false
31
31
 
32
+ Lint/InterpolationCheck:
33
+ Exclude:
34
+ - lib/mdhost.rb
35
+
32
36
  Lint/NonDeterministicRequireOrder:
33
37
  Enabled: false
34
38
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
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
- 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
+ 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
- @input = ARGV.first
33
+ if ARGV.empty?
34
+ Optimist.educate
35
+ end
16
36
  end
17
37
 
18
38
  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}'"
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
- "\"#{@input}\""
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
@@ -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.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-10-12 00:00:00.000000000 Z
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