snatchdb 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/bin/snatch CHANGED
@@ -39,6 +39,22 @@ optparse = OptionParser.new do |opts|
39
39
  File.open(file, 'w') { |f| f.write(SAMPLE_SCHEMA) }
40
40
  puts "File #{file} has been created. Edit and snatch!" ; exit
41
41
  end
42
+
43
+ opts.on('-l', '--list', 'List all available config files') do
44
+ files = Dir[File.join(Snatch.root, '*.yml')]
45
+
46
+ unless files.empty?
47
+ puts "Configuration files:"
48
+ files.each do |path|
49
+ puts " - #{File.basename(path, '.yml')}" if Snatch.valid_config?(path)
50
+ end
51
+ puts "TIP: Just type 'snatch NAME' and i will download that database."
52
+ else
53
+ puts "No available configs are available."
54
+ end
55
+
56
+ exit
57
+ end
42
58
  end
43
59
 
44
60
  begin
@@ -68,6 +84,6 @@ rescue OptionParser::InvalidOption, OptionParser::MissingArgument
68
84
  exit
69
85
  rescue Interrupt
70
86
  puts "Interrupted."
71
- rescue StandardError, Snatch::CredentialsError, Snatch::NoDatabaseError => ex
87
+ rescue StandardError, Snatch::CredentialsError, Snatch::NoServiceError, Snatch::NoDatabaseError => ex
72
88
  puts "ERROR: #{ex.message}"
73
89
  end
@@ -15,4 +15,14 @@ module Snatch
15
15
  s = Snatch::Session.new(config)
16
16
  s.run!
17
17
  end
18
+
19
+ # Returns true if snatch config is valid
20
+ def self.valid_config?(path)
21
+ data = YAML.load_file(path)
22
+ if data.kind_of?(Hash)
23
+ (data.keys & ['host']).size == 1
24
+ else
25
+ false
26
+ end
27
+ end
18
28
  end
@@ -1,6 +1,7 @@
1
1
  module Snatch
2
2
  class CredentialsError < Exception ; end
3
- class NoDatabaseError < Exception ; end
3
+ class NoDatabaseError < Exception ; end
4
+ class NoServiceError < Exception ; end
4
5
 
5
6
  class Session
6
7
  attr_reader :config, :filename
@@ -42,6 +43,9 @@ module Snatch
42
43
 
43
44
  # Check configuration options
44
45
  def test
46
+ raise NoServiceError, "No mysql found." unless @ssh.exec!("which mysql") =~ /mysql/i
47
+ raise NoServiceError, "No mysqldump found." unless @ssh.exec!("which mysqldump") =~ /mysqldump/i
48
+
45
49
  resp = @ssh.exec!("mysql --execute='SHOW DATABASES;' --user=#{@config[:db_user]} --password=#{@config[:db_password]}")
46
50
  if resp =~ /ERROR 1045/
47
51
  raise CredentialsError, 'Invalid MySQL user or password'
@@ -1,3 +1,3 @@
1
1
  module Snatch
2
- VERSION = '1.0.1'
2
+ VERSION = '1.0.2'
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: snatchdb
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 1.0.1
5
+ version: 1.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Dan Sosedoff
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-06-14 00:00:00 -05:00
13
+ date: 2011-06-23 00:00:00 -05:00
14
14
  default_executable: snatch
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency