sshelper 0.1.1 → 0.1.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.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Sshelper
1
+ # SSHelper
2
2
 
3
3
  This gem is supposed to make your life easier if you have to do a lot of repetitive tasks over SSH. If you are sick
4
4
  of doing the constant ```ssh user@example.org```, ```cd /opt/path/to/something```, ```./start.sh```
@@ -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", "Place a template configuration at ~/.sshelper.json") do
25
- template = IO.read(File.expand_path('../../resources/template.json', __FILE__))
26
- File.open(File.expand_path("~/.sshelper.json"), "w") { |f| f.write template }
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
@@ -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
- raise "Needs configuration file" unless File.exists? File.expand_path("~/.sshelper.json")
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
- begin
15
- @config ||= JSON.parse IO.read(File.expand_path("~/.sshelper.json"))
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") }"
@@ -1,3 +1,3 @@
1
1
  module Sshelper
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -0,0 +1,9 @@
1
+ my_label1:
2
+ description: Some description
3
+ servers:
4
+ - host: my.host.com
5
+ port: 22
6
+ user: my_user
7
+ commands:
8
+ - cd /opt
9
+ - ls -l
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.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-07-31 00:00:00.000000000 Z
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