mycmd 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +9 -0
- data/LICENSE.txt +22 -0
- data/README.md +61 -0
- data/Rakefile +1 -0
- data/bin/mycmd +11 -0
- data/lib/mycmd.rb +8 -0
- data/lib/mycmd/cli.rb +36 -0
- data/lib/mycmd/clis/config_commands.rb +27 -0
- data/lib/mycmd/clis/setting_commands.rb +14 -0
- data/lib/mycmd/configuration.rb +79 -0
- data/lib/mycmd/printer.rb +34 -0
- data/lib/mycmd/version.rb +3 -0
- data/mycmd.gemspec +27 -0
- data/spec/mycmd/cli_spec.rb +4 -0
- data/spec/spec_helper.rb +19 -0
- metadata +133 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ec8662beb4d966823e1d6594a2f6cba96923377e
|
4
|
+
data.tar.gz: b1a044c5b653bdb725fc8cdc9a8f17ac3c9ba7a7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 9556025211eafb296bfd0fff9933bdcfb54aa3efa9756726842f12850e19db7a31f356e44dca98866140afa706237468e4f00be07e20f6b1de7a3390622a6826
|
7
|
+
data.tar.gz: 4f9691a71d9c26ba2efe35e776b8257392fe371d12049c899dc105f11bd24c02426b498da6cfc86cab4458776952c6f4c1c9f207a08007fe061883dc893b7ad0
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 i2bskn
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
# Mycmd
|
2
|
+
|
3
|
+
MySQL command line tool.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'mycmd'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install mycmd
|
18
|
+
|
19
|
+
Create settings file:
|
20
|
+
|
21
|
+
$ touch ~/.mycmd.yml
|
22
|
+
$ mycmd config edit
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
Start sql shell:
|
27
|
+
|
28
|
+
$ mycmd console
|
29
|
+
mysql>
|
30
|
+
|
31
|
+
Execute sql:
|
32
|
+
|
33
|
+
$ mycmd query "SELECT * FROM somedb.sometable"
|
34
|
+
|
35
|
+
#### Config Commands
|
36
|
+
|
37
|
+
Print current config file path:
|
38
|
+
|
39
|
+
$ mycmd config which
|
40
|
+
|
41
|
+
Print current config:
|
42
|
+
|
43
|
+
$ mycmd config cat
|
44
|
+
|
45
|
+
Edit config file:
|
46
|
+
|
47
|
+
$ mycmd config edit
|
48
|
+
|
49
|
+
#### Setting Commands
|
50
|
+
|
51
|
+
Search settings:
|
52
|
+
|
53
|
+
$ mycmd setting search innodb_buffer_pool_size
|
54
|
+
|
55
|
+
## Contributing
|
56
|
+
|
57
|
+
1. Fork it
|
58
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
59
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
60
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
61
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/mycmd
ADDED
data/lib/mycmd.rb
ADDED
data/lib/mycmd/cli.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require "mycmd/clis/config_commands"
|
4
|
+
require "mycmd/clis/setting_commands"
|
5
|
+
|
6
|
+
module Mycmd
|
7
|
+
class CLI < Thor
|
8
|
+
default_command :console
|
9
|
+
register(ConfigCommands, "config", "config [COMMAND]", "commands for config")
|
10
|
+
register(SettingCommands, "setting", "setting [COMMAND]", "commands for setting")
|
11
|
+
|
12
|
+
desc "console", "console will start sql shell."
|
13
|
+
def console
|
14
|
+
raise "mysql not found" unless system("which mysql > /dev/null")
|
15
|
+
conf = Configuration.new
|
16
|
+
cmd = conf.to_hash.inject(["mysql"]) do |c,(k,v)|
|
17
|
+
case k
|
18
|
+
when :host then c << "-h#{v}"
|
19
|
+
when :port then c << "-P#{v}"
|
20
|
+
when :username then c << "-u#{v}"
|
21
|
+
when :password then c << "-p#{v}"
|
22
|
+
when :database then c << v
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
system(cmd.join(" "))
|
27
|
+
end
|
28
|
+
|
29
|
+
desc 'query "[SQL]"', "query will execute sql."
|
30
|
+
def query(sql)
|
31
|
+
client = Configuration.connect
|
32
|
+
printer = Printer.new(client.query(sql), true)
|
33
|
+
printer.print
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module Mycmd
|
4
|
+
class ConfigCommands < Thor
|
5
|
+
namespace :config
|
6
|
+
|
7
|
+
desc "which", "which will find config file"
|
8
|
+
def which
|
9
|
+
conf = Configuration.config_find
|
10
|
+
puts conf.nil? ? "config not found" : conf
|
11
|
+
end
|
12
|
+
|
13
|
+
desc "cat", "cat will print configuration"
|
14
|
+
def cat
|
15
|
+
conf = Configuration.config_find
|
16
|
+
raise "config not found" if conf.nil?
|
17
|
+
open(conf, "r").each {|line| puts line}
|
18
|
+
end
|
19
|
+
|
20
|
+
desc "edit", "edit will edit configuration"
|
21
|
+
def edit
|
22
|
+
conf = Configuration.config_find
|
23
|
+
raise "config not found" if conf.nil?
|
24
|
+
system("#{ENV['EDITOR']} #{conf}")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module Mycmd
|
4
|
+
class SettingCommands < Thor
|
5
|
+
namespace :setting
|
6
|
+
|
7
|
+
desc "search innodb_buffer_pool_size", "search will print settings"
|
8
|
+
def search(keyword)
|
9
|
+
client = Configuration.connect
|
10
|
+
printer = Printer.new(client.query("SHOW GLOBAL VARIABLES LIKE \"%#{keyword}%\""))
|
11
|
+
printer.print
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module Mycmd
|
4
|
+
class Configuration
|
5
|
+
CONFIG_FILE = ".mycmd.yml"
|
6
|
+
|
7
|
+
VALID_OPTIONS_KEYS = [
|
8
|
+
:host,
|
9
|
+
:username,
|
10
|
+
:password,
|
11
|
+
:port,
|
12
|
+
:database,
|
13
|
+
:socket,
|
14
|
+
:flags,
|
15
|
+
:encoding,
|
16
|
+
:read_timeout,
|
17
|
+
:write_timeout,
|
18
|
+
:connect_timeout,
|
19
|
+
:reconnect,
|
20
|
+
:local_infile,
|
21
|
+
].freeze
|
22
|
+
|
23
|
+
attr_accessor *VALID_OPTIONS_KEYS
|
24
|
+
attr_reader :path
|
25
|
+
|
26
|
+
def initialize
|
27
|
+
reset
|
28
|
+
end
|
29
|
+
|
30
|
+
def merge(params)
|
31
|
+
params.each do |k,v|
|
32
|
+
self.send("#{k.to_s}=", v)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_hash
|
37
|
+
VALID_OPTIONS_KEYS.inject({}) do |c,k|
|
38
|
+
c.store(k.to_sym, self.send(k.to_s)) unless self.send(k.to_s).nil?
|
39
|
+
c
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def connect
|
44
|
+
Mysql2::Client.new(to_hash)
|
45
|
+
end
|
46
|
+
|
47
|
+
def reset
|
48
|
+
@path = Configuration.config_find
|
49
|
+
if @path
|
50
|
+
merge YAML.load_file(@path)
|
51
|
+
else
|
52
|
+
self.host = "localhost"
|
53
|
+
self.port = 3306
|
54
|
+
self.username = "root"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class << self
|
59
|
+
def connect
|
60
|
+
conf = Configuration.new
|
61
|
+
conf.connect
|
62
|
+
end
|
63
|
+
|
64
|
+
def config_find(path = File.expand_path("."))
|
65
|
+
file = File.join(path, CONFIG_FILE)
|
66
|
+
if File.exists?(file)
|
67
|
+
file
|
68
|
+
else
|
69
|
+
if path == "/"
|
70
|
+
file = File.join(ENV["HOME"], CONFIG_FILE)
|
71
|
+
File.exists?(file) ? file : nil
|
72
|
+
else
|
73
|
+
config_find(File.expand_path("..", path))
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module Mycmd
|
4
|
+
class Printer
|
5
|
+
def initialize(result, header=false)
|
6
|
+
@result = result
|
7
|
+
@header = header
|
8
|
+
end
|
9
|
+
|
10
|
+
def print
|
11
|
+
if @result.respond_to? :each
|
12
|
+
set_width
|
13
|
+
print_line(@result.fields) if @header
|
14
|
+
@result.each(as: :array) do |row|
|
15
|
+
print_line(row)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
def set_width
|
22
|
+
@width = @result.fields.map{|f| f.size}
|
23
|
+
@result.each(as: :array) do |row|
|
24
|
+
row.each_with_index do |v,i|
|
25
|
+
@width[i] = v.to_s.size if @width[i] < v.to_s.size
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def print_line(line_array)
|
31
|
+
puts line_array.map.with_index {|f,i| f.to_s.ljust(@width[i], " ")}.join("\t")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/mycmd.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'mycmd/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "mycmd"
|
8
|
+
spec.version = Mycmd::VERSION
|
9
|
+
spec.authors = ["i2bskn"]
|
10
|
+
spec.email = ["i2bskn@gmail.com"]
|
11
|
+
spec.description = %q{MySQL command line tool}
|
12
|
+
spec.summary = %q{MySQL command line tool}
|
13
|
+
spec.homepage = "https://github.com/i2bskn/mycmd"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "thor"
|
22
|
+
spec.add_dependency "mysql2"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
25
|
+
spec.add_development_dependency "rake"
|
26
|
+
spec.add_development_dependency "rspec"
|
27
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# require "simplecov"
|
2
|
+
# require "coveralls"
|
3
|
+
# Coveralls.wear!
|
4
|
+
|
5
|
+
# SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
6
|
+
# SimpleCov::Formatter::HTMLFormatter,
|
7
|
+
# Coveralls::SimpleCov::Formatter
|
8
|
+
# ]
|
9
|
+
|
10
|
+
# SimpleCov.start do
|
11
|
+
# add_filter "spec"
|
12
|
+
# add_filter ".bundle"
|
13
|
+
# end
|
14
|
+
|
15
|
+
require "mycmd"
|
16
|
+
|
17
|
+
RSpec.configure do |config|
|
18
|
+
config.order = "random"
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mycmd
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- i2bskn
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-08-20 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mysql2
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
description: MySQL command line tool
|
84
|
+
email:
|
85
|
+
- i2bskn@gmail.com
|
86
|
+
executables:
|
87
|
+
- mycmd
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- .gitignore
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- bin/mycmd
|
97
|
+
- lib/mycmd.rb
|
98
|
+
- lib/mycmd/cli.rb
|
99
|
+
- lib/mycmd/clis/config_commands.rb
|
100
|
+
- lib/mycmd/clis/setting_commands.rb
|
101
|
+
- lib/mycmd/configuration.rb
|
102
|
+
- lib/mycmd/printer.rb
|
103
|
+
- lib/mycmd/version.rb
|
104
|
+
- mycmd.gemspec
|
105
|
+
- spec/mycmd/cli_spec.rb
|
106
|
+
- spec/spec_helper.rb
|
107
|
+
homepage: https://github.com/i2bskn/mycmd
|
108
|
+
licenses:
|
109
|
+
- MIT
|
110
|
+
metadata: {}
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options: []
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - '>='
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
requirements: []
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 2.0.0
|
128
|
+
signing_key:
|
129
|
+
specification_version: 4
|
130
|
+
summary: MySQL command line tool
|
131
|
+
test_files:
|
132
|
+
- spec/mycmd/cli_spec.rb
|
133
|
+
- spec/spec_helper.rb
|