mysqlconn 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 33b059c109f934635f30660baa41c0734217bdb7
4
- data.tar.gz: ab5e09aa4ee8da4bb4617ce11f45e17ca5647b98
3
+ metadata.gz: aca85e60949af842fe4c095cd5c540f1b230f7bc
4
+ data.tar.gz: bb4a79207e02965279ed63aa5dd8b74cb3387cdb
5
5
  SHA512:
6
- metadata.gz: 0ff5c4184351c935e866d1da7771e20d04a1295f2ab987896a0f8eff7fef1dfd3c11832aff0f1f456927c4807f87b9b24ece5b96905caffcb70abc9c084bab03
7
- data.tar.gz: 10a6e080b10c399ea47928203f2016c44ba990f4e6e1537b38631d4b9ff33c07d75ac432b390ff1f80af289af16f70c5e69a8b42137982866ec2f5b219f5874d
6
+ metadata.gz: c73d10528455315983f07334d4486b93eb26b49c0551df8920c0cc5480471d36e91a3692596e675a3a9767fe0036afb1f977d36f4d0794e41957abb4d499c516
7
+ data.tar.gz: 26736110e42e5ea6d1ed7149e4241fd4ec5b5842a90ae9b1ab1132646609af302262a7c57921cfe5b73628ecb13d866eca7f3722a58c6a640e0d4c52bf827435
data/README.md CHANGED
@@ -1,6 +1,10 @@
1
1
  mysqlconn - The mysql connection assistant
2
2
  ------------------------------------------
3
3
 
4
+ Store mysql connection credentials in a simple, secure configuration file. Many destinations can then be used with
5
+ the *db_key* you specify. You can also run script files against the names you select. The mysql prompt is set
6
+ for safety.
7
+
4
8
  ### Instructions
5
9
 
6
10
  Install:
@@ -11,6 +15,7 @@ Create `~/.db_connection_alias.yml`
11
15
 
12
16
  db_key:
13
17
  host: hostname
18
+ port: port # Optional
14
19
  user: username # Optional
15
20
  password: password # Optional
16
21
  # password: '' # Optional, prompt for password
@@ -28,15 +33,32 @@ Connect:
28
33
 
29
34
  `mysqlconn db_key [additional options]`
30
35
 
36
+ Look at that beautiful prompt:
37
+
38
+ mysqluser@db_key [database]> select now();
39
+ +---------------------+
40
+ | now() |
41
+ +---------------------+
42
+ | 2014-04-15 11:09:33 |
43
+ +---------------------+
44
+ 1 row in set (0.02 sec)
45
+
46
+ mysqluser@db_key [database]>
47
+
31
48
  Pipe:
32
49
 
33
50
  `mysqlconn db_key < script.sql > output`
34
51
 
35
52
  etc..
36
53
 
54
+ To mysqldump:
55
+
56
+ `mysqldumpconn db_key [additional options]`
57
+
58
+
37
59
  ### Autocomplete
38
60
 
39
- Add to bash.completion.d
61
+ Add to bash.completion.d or wherever:
40
62
 
41
63
  _mysqlconn() {
42
64
  local cur=${COMP_WORDS[COMP_CWORD]}
data/README.md~ ADDED
@@ -0,0 +1,64 @@
1
+ mysqlconn - The mysql connection assistant
2
+ ------------------------------------------
3
+
4
+ Store mysql connection credentials in a simple, secure configuration file. Many destinations can then be used with
5
+ the *db_key* you specify. You can also run script files against the names you select. The mysql prompt is set
6
+ for safety.
7
+
8
+ ### Instructions
9
+
10
+ Install:
11
+
12
+ `gem install mysqlconn`
13
+
14
+ Create `~/.db_connection_alias.yml`
15
+
16
+ db_key:
17
+ host: hostname
18
+ user: username # Optional
19
+ password: password # Optional
20
+ # password: '' # Optional, prompt for password
21
+ database: database # Optional
22
+ db_key2:
23
+ ...
24
+
25
+ Protect configuration file:
26
+
27
+ `chmod 600 ~/.db_connection_alias.yml`
28
+
29
+ ### Usage
30
+
31
+ Connect:
32
+
33
+ `mysqlconn db_key [additional options]`
34
+
35
+ Look at that beautiful prompt:
36
+ mysqluser@db_key [database]> select now();
37
+ +---------------------+
38
+ | now() |
39
+ +---------------------+
40
+ | 2014-04-15 11:09:33 |
41
+ +---------------------+
42
+ 1 row in set (0.02 sec)
43
+
44
+ mysqluser@db_key [database]>
45
+
46
+ Pipe:
47
+
48
+ `mysqlconn db_key < script.sql > output`
49
+
50
+ etc..
51
+
52
+ ### Autocomplete
53
+
54
+ Add to bash.completion.d or wherever:
55
+
56
+ _mysqlconn() {
57
+ local cur=${COMP_WORDS[COMP_CWORD]}
58
+ COMPREPLY=( $( compgen -W "$(mysqlconn -l)" -- $cur ) )
59
+ }
60
+ complete -F _mysqlconn mysqlconn
61
+
62
+ ### License
63
+
64
+ Apache 2.0 - go nuts
data/bin/mysqlconn CHANGED
@@ -1,43 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- # Copyright Neville Kadwa (2014)
3
+ require 'rubygems'
4
4
 
5
- require 'yaml'
6
- require 'fileutils'
5
+ require File.expand_path("../../lib/mysqlconn.rb", __FILE__)
7
6
 
8
- CONFIG_LOCATION=File.expand_path("~/.db_connection_alias.yml")
9
-
10
- db_key = ARGV.shift || raise('no db key provided. Usage mysqlconn db_key [mysql opts]*')
11
-
12
- config = begin
13
- File.open(CONFIG_LOCATION, 'r') do |f|
14
- YAML.load(f)
15
- end
16
- rescue Errno::ENOENT => e
17
- raise("No config found. Please follow instructions for creating #{CONFIG_LOCATION}")
18
- end
19
- raise("Config file is world readable. Exiting...") if File.stat(CONFIG_LOCATION).world_readable?
20
-
21
- if db_key == '-l'
22
- filter = /.*#{ARGV.shift||'.*'}.*/
23
- config.keys.each do |k|
24
- puts k if filter =~ k
25
- end
26
- exit(0)
27
- end
28
-
29
- db = config[db_key] || raise("No #{db_key} found")
30
-
31
- db['host'] || raise("No #{db_key}.host found")
32
-
33
- command = "mysql -h #{db['host']} --prompt=\"\\u@#{db_key} [\\d]> \""
34
-
35
- command << " -u #{db['user']}" if db['user']
36
- command << " -p#{db['password']}" if db['password']
37
- command << " -D #{db['database']}" if db['database']
38
- unless ARGV.empty?
39
- command << " "
40
- command << ARGV.map{|s| "'#{s}'"}.join(' ')
41
- end
42
-
43
- exec(command)
7
+ MysqlConn.new(MysqlConn::MODE_MYSQL).run(ARGV)
data/bin/mysqlconn~ ADDED
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # Copyright Neville Kadwa (2014)
4
+
5
+ require 'yaml'
6
+ require 'fileutils'
7
+
8
+ CONFIG_LOCATION=File.expand_path("~/.db_connection_alias.yml")
9
+
10
+ db_key = ARGV.shift || raise('no db key provided. Usage mysqlconn db_key [mysql opts]*')
11
+
12
+ config = begin
13
+ File.open(CONFIG_LOCATION, 'r') do |f|
14
+ YAML.load(f)
15
+ end
16
+ rescue Errno::ENOENT => e
17
+ raise("No config found. Please follow instructions for creating #{CONFIG_LOCATION}")
18
+ end
19
+ raise("Config file is world readable. Exiting...") if File.stat(CONFIG_LOCATION).world_readable?
20
+
21
+ if db_key == '-l'
22
+ filter = /.*#{ARGV.shift||'.*'}.*/
23
+ config.keys.each do |k|
24
+ puts k if filter =~ k
25
+ end
26
+ exit(0)
27
+ end
28
+
29
+ db = config[db_key] || raise("No #{db_key} found")
30
+
31
+ db['host'] || raise("No #{db_key}.host found")
32
+
33
+ command = "mysql -h #{db['host']} --prompt=\"\\u@#{db_key} [\\d]> \""
34
+
35
+ command << " -u #{db['user']}" if db['user']
36
+ command << " -p#{db['password']}" if db['password']
37
+ command << " -D #{db['database']}" if db['database']
38
+ unless ARGV.empty?
39
+ command << " "
40
+ command << ARGV.map{|s| "'#{s}'"}.join(' ')
41
+ end
42
+
43
+ exec(command)
data/bin/mysqldumpconn ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+
5
+ require File.expand_path("../../lib/mysqlconn.rb", __FILE__)
6
+
7
+ MysqlConn.new(MysqlConn::MODE_MYSQLDUMP).run(ARGV)
data/lib/mysqlconn.rb ADDED
@@ -0,0 +1,96 @@
1
+ require 'yaml'
2
+ require 'fileutils'
3
+ require 'set'
4
+
5
+ # Copyright Neville Kadwa (2014)
6
+
7
+ class MysqlConn
8
+
9
+ MODE_MYSQL = :MYSQL
10
+ MODE_MYSQLDUMP = :MYSQLDUMP
11
+ CONFIG_LOCATION=File.expand_path("~/.db_connection_alias.yml")
12
+
13
+ attr_reader :mode
14
+ attr_reader :verbose
15
+ attr_reader :db_key
16
+
17
+ def initialize(mode)
18
+ @mode = mode
19
+ @verbose = false
20
+ end
21
+
22
+ def mode_command
23
+ case mode
24
+ when :MYSQL
25
+ "mysql"
26
+ when :MYSQLDUMP
27
+ "mysqldump"
28
+ else
29
+ raise "Unknown mode: #{mode}"
30
+ end
31
+ end
32
+
33
+ def mode_default_args(args)
34
+ case mode
35
+ when :MYSQL
36
+ "--prompt=\"\\u@#{db_key} [\\d]> \""
37
+ when :MYSQLDUMP
38
+ ""
39
+ else
40
+ raise "Unknown mode: #{mode}"
41
+ end
42
+ end
43
+
44
+ def run(args)
45
+
46
+ @db_key = args.shift || raise('no db key provided. Usage mysqlconn db_key [mysql opts]*')
47
+
48
+ config = begin
49
+ File.open(CONFIG_LOCATION, 'r') do |f|
50
+ YAML.load(f)
51
+ end
52
+ rescue Errno::ENOENT => e
53
+ raise("No config found. Please follow instructions for creating #{CONFIG_LOCATION}")
54
+ end
55
+ raise("Config file is world readable. Exiting...") if File.stat(CONFIG_LOCATION).world_readable?
56
+
57
+ if db_key == '-v'
58
+ @verbose = true
59
+ @db_key = args.shift
60
+ end
61
+ if db_key == '-l'
62
+ filter = /.*#{args.shift||'.*'}.*/
63
+ config.keys.each do |k|
64
+ puts k if filter =~ k
65
+ end
66
+ exit(0)
67
+ end
68
+
69
+ db = config[db_key] || raise("No #{db_key} found")
70
+
71
+ db['host'] || raise("No #{db_key}.host found")
72
+
73
+ command = "#{mode_command} -h #{db['host']} #{mode_default_args(args)}"
74
+
75
+ command << " -P #{db['port']}" if db['port']
76
+ command << " -u #{db['user']}" if db['user']
77
+ command << " -p#{db['password']}" if db['password']
78
+ if db['database'] && mode == :MYSQL
79
+ case mode
80
+ when :MYSQL
81
+ command << " -D #{db['database']}"
82
+ when :MYSQLDUMP
83
+ command << " #{db['database']}"
84
+ end
85
+ end
86
+ unless args.empty?
87
+ command << " "
88
+ command << args.map{|s| "'#{s}'"}.join(' ')
89
+ end
90
+
91
+ STDERR.puts command if verbose
92
+ exec(command)
93
+
94
+ end
95
+
96
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mysqlconn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Neville Kadwa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-13 00:00:00.000000000 Z
11
+ date: 2014-04-29 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Save your various database credentials to a configuration file and zip
14
14
  around easily
@@ -16,11 +16,17 @@ email:
16
16
  - neville@kadwa.com
17
17
  executables:
18
18
  - mysqlconn
19
+ - mysqlconn~
20
+ - mysqldumpconn
19
21
  extensions: []
20
22
  extra_rdoc_files: []
21
23
  files:
22
24
  - README.md
25
+ - README.md~
23
26
  - bin/mysqlconn
27
+ - bin/mysqlconn~
28
+ - bin/mysqldumpconn
29
+ - lib/mysqlconn.rb
24
30
  homepage: http://github.com/kadwanev/mysqlconn
25
31
  licenses:
26
32
  - Apache-2.0
@@ -46,3 +52,4 @@ signing_key:
46
52
  specification_version: 4
47
53
  summary: mysql command line configuration assistant
48
54
  test_files: []
55
+ has_rdoc: