sshelper 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +1 -1
- data/bin/sshelper +7 -4
- data/lib/sshelper.rb +23 -9
- data/lib/sshelper/version.rb +1 -1
- data/resources/template.yml +9 -0
- metadata +3 -2
data/README.md
CHANGED
data/bin/sshelper
CHANGED
@@ -15,15 +15,18 @@ global = OptionParser.new do |opts|
|
|
15
15
|
puts "Labels:"
|
16
16
|
Sshelper.prepare!
|
17
17
|
Sshelper.configuration.each do |key, value|
|
18
|
-
puts "\t#{key.to_s}: #{value.description}"
|
18
|
+
puts "\t#{key.to_s.yellow}: #{value.description.blue if value.member? 'description'}"
|
19
19
|
end
|
20
20
|
puts "\n\n"
|
21
21
|
exit!
|
22
22
|
end
|
23
23
|
|
24
|
-
opts.on("-t", "--template", "
|
25
|
-
|
26
|
-
|
24
|
+
opts.on("-t", "--template [TYPE]", "Generate a template in your home folder (~/.sshelper.{yml|json}). For type choose either YAML/YML or JSON.") do |type|
|
25
|
+
ext = "json"
|
26
|
+
ext = "yml" if type.downcase =~ /ya?ml/
|
27
|
+
|
28
|
+
template = IO.read(File.expand_path("../../resources/template.#{ext}", __FILE__))
|
29
|
+
File.open(File.expand_path("~/.sshelper.#{ext}"), "w") { |f| f.write template }
|
27
30
|
exit!
|
28
31
|
end
|
29
32
|
end
|
data/lib/sshelper.rb
CHANGED
@@ -3,18 +3,32 @@ require "sshelper/hash"
|
|
3
3
|
require "sshelper/string"
|
4
4
|
require 'rye'
|
5
5
|
require "json"
|
6
|
+
require "yaml"
|
6
7
|
require "fileutils"
|
7
8
|
|
8
9
|
module Sshelper
|
9
10
|
@config
|
10
11
|
|
11
12
|
def self.prepare!
|
12
|
-
|
13
|
+
@config ||= {}
|
14
|
+
if File.exists? File.expand_path("~/.sshelper.json") then
|
15
|
+
begin
|
16
|
+
@config.merge! JSON.parse IO.read(File.expand_path("~/.sshelper.json"))
|
17
|
+
rescue
|
18
|
+
puts "An error occurred while parsing your JSON configuration."
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
if File.exists? File.expand_path("~/.sshelper.yml") then
|
23
|
+
begin
|
24
|
+
@config.merge! YAML.load_file File.expand_path("~/.sshelper.yml")
|
25
|
+
rescue
|
26
|
+
puts "An error occurred while parsing your yaml configuration."
|
27
|
+
end
|
28
|
+
end
|
13
29
|
|
14
|
-
|
15
|
-
|
16
|
-
rescue
|
17
|
-
puts "An error occurred while parsing your configuration file."
|
30
|
+
if @config.empty? then
|
31
|
+
puts "Your configuration is empty, make sure you have a ~/.sshelper.json and/or a ~/.sshelper.yml config file"
|
18
32
|
end
|
19
33
|
end
|
20
34
|
|
@@ -22,17 +36,17 @@ module Sshelper
|
|
22
36
|
return if label.nil?
|
23
37
|
labels = @config.map { |key, value| key }
|
24
38
|
if not labels.include? label then
|
25
|
-
puts "Could not find that label."
|
39
|
+
puts "Could not find that label.".yellow
|
26
40
|
return
|
27
41
|
end
|
28
42
|
|
29
43
|
if not @config[label].include? "servers" or not @config[label].include? "commands" then
|
30
|
-
puts "The configuration file does not contain a 'servers' array or a 'commands' array"
|
44
|
+
puts "The configuration file does not contain a 'servers' array or a 'commands' array".yellow
|
31
45
|
return
|
32
46
|
end
|
33
47
|
|
34
48
|
if not @config[label].servers.is_a? Array or not @config[label].commands.is_a? Array then
|
35
|
-
puts "The servers and commands block need to be arrays."
|
49
|
+
puts "The servers and commands block need to be arrays.".yellow
|
36
50
|
return
|
37
51
|
end
|
38
52
|
|
@@ -45,7 +59,7 @@ module Sshelper
|
|
45
59
|
@config[label].commands.each do |command|
|
46
60
|
puts "\nExecuting: #{command}".red
|
47
61
|
puts '#### OUTPUT ####'.blue
|
48
|
-
if command.start_with? "cd" then
|
62
|
+
if command.start_with? "cd " then
|
49
63
|
rbox.cd command.split(' ', 2).last
|
50
64
|
else
|
51
65
|
puts "#{rbox.execute(command).stdout.map{ |k| "~> #{k}" }.join("\n") }"
|
data/lib/sshelper/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sshelper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-08-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -96,6 +96,7 @@ files:
|
|
96
96
|
- lib/sshelper/string.rb
|
97
97
|
- lib/sshelper/version.rb
|
98
98
|
- resources/template.json
|
99
|
+
- resources/template.yml
|
99
100
|
- spec/spec_helper.rb
|
100
101
|
- spec/sshelper_spec.rb
|
101
102
|
- sshelper.gemspec
|