rgversion 1.1.3 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/rgversion/application.rb +8 -2
- data/lib/rgversion/terminal.rb +40 -3
- data/lib/rgversion/version.rb +2 -2
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00cfb6d88a01bd4035fc2000dc3f3c9744c5e68b38ab8f0169524a32848e00f2
|
4
|
+
data.tar.gz: 90d9af0b08e23dba45bd18025cda7cf858efc5d1b4800fc6eda1879f711e445e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f757a76858f05e9bf37a5b82dfa781f5cb2fe8fc8448d3aa973ee66b741ddb8a3a97533ee446ddb2066808dcfd905983ebf109cbd908022afd125a668f3044b
|
7
|
+
data.tar.gz: 628937f24f440e1d06a354daabb7b057cb58f53fc74efa16a148ec4a4f378a09034605f7cbaf54140a7f730cfc9ab51747bbea777627cd0543e12c30c8362374
|
@@ -6,9 +6,9 @@ module Rgversion
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def run
|
9
|
-
terminal = Terminal.new(results)
|
9
|
+
terminal = Terminal.new(command, results)
|
10
10
|
terminal.report
|
11
|
-
terminal.copy_to_clipboard
|
11
|
+
terminal.copy_to_clipboard
|
12
12
|
rescue StandardError => ex
|
13
13
|
$stderr.puts ex.message
|
14
14
|
end
|
@@ -19,5 +19,11 @@ module Rgversion
|
|
19
19
|
spider = Spider.new(@gems, @selector)
|
20
20
|
spider.walk
|
21
21
|
end
|
22
|
+
|
23
|
+
def command
|
24
|
+
return :pbcopy if OS.mac?
|
25
|
+
return :xclip if OS.linux?
|
26
|
+
nil
|
27
|
+
end
|
22
28
|
end
|
23
29
|
end
|
data/lib/rgversion/terminal.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
module Rgversion
|
2
2
|
class Terminal
|
3
|
-
def initialize(results)
|
3
|
+
def initialize(command, results)
|
4
|
+
@command = command
|
4
5
|
@results = results
|
5
6
|
end
|
6
7
|
|
@@ -11,8 +12,12 @@ module Rgversion
|
|
11
12
|
|
12
13
|
def copy_to_clipboard
|
13
14
|
return if @output.blank?
|
14
|
-
|
15
|
-
|
15
|
+
if command_exists?
|
16
|
+
`echo "#{@output}" | #{clarified_command}`
|
17
|
+
puts "\nCopied to your clipboard!".green
|
18
|
+
else
|
19
|
+
render_instructions
|
20
|
+
end
|
16
21
|
end
|
17
22
|
|
18
23
|
private
|
@@ -28,5 +33,37 @@ module Rgversion
|
|
28
33
|
@output = @results[:gems].join("\n")
|
29
34
|
puts @output
|
30
35
|
end
|
36
|
+
|
37
|
+
def clarified_command
|
38
|
+
return "#{@command} -selection clipboard" if OS.linux?
|
39
|
+
@command
|
40
|
+
end
|
41
|
+
|
42
|
+
def command_exists?
|
43
|
+
return false if which(@command.to_s).nil?
|
44
|
+
true
|
45
|
+
end
|
46
|
+
|
47
|
+
# based on https://stackoverflow.com/a/5471032
|
48
|
+
# let's avoid find_executable from mkmf because in this case we need to supress logs
|
49
|
+
def which(cmd)
|
50
|
+
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
|
51
|
+
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
|
52
|
+
exts.each do |ext|
|
53
|
+
exe = File.join(path, "#{cmd}#{ext}")
|
54
|
+
return exe if File.executable?(exe) && !File.directory?(exe)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
nil
|
58
|
+
end
|
59
|
+
|
60
|
+
def render_instructions
|
61
|
+
if @command.nil?
|
62
|
+
puts "\nRgversion doesn't support copy to clipboard feature if your OS isn't macOS or Linux. You can manually copy output above."
|
63
|
+
else
|
64
|
+
puts "\nUnable to copy to clipboard because #{@command} is missed.\nTry the command below if you are on Ubuntu/Debian:"
|
65
|
+
puts "sudo apt-get install #{@command}"
|
66
|
+
end
|
67
|
+
end
|
31
68
|
end
|
32
69
|
end
|
data/lib/rgversion/version.rb
CHANGED