mycmd 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.coveralls.yml +1 -0
- data/.travis.yml +10 -0
- data/README.md +22 -1
- data/Rakefile +8 -0
- data/bin/mycmd +0 -5
- data/lib/mycmd/cli.rb +10 -2
- data/lib/mycmd/clis/{setting_commands.rb → settings_commands.rb} +2 -2
- data/lib/mycmd/configuration.rb +9 -3
- data/lib/mycmd/version.rb +1 -1
- data/spec/mycmd/configuration_spec.rb +114 -0
- data/spec/spec_helper.rb +11 -11
- metadata +7 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf1b833907aa455e71b88d4fd93f821274103a13
|
4
|
+
data.tar.gz: 1dc6c7315cd5d5f157c5bb2b1bfaf5ab6106d9d9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a7eb2b0c883a5207ab4466b251c5e4fd01026126e98a4865ef6ff2069be2ac8b8ea7dd87c8ce4cd4a9c74b79a40e8e368e95ebd275e25493419b4465ddaaf7d4
|
7
|
+
data.tar.gz: 1fdda7ab25c75dcb20b47498328475dc9b1eb0a8ff3e778fa266baf28915cb8409aaab6dd3ee9f276a52b256864e02558ae17f97b82f547e0b5165d7440b6a84
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
repo_token: DCRCxDWuGTexjBU06uzLipNo1sphCZ6si
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Mycmd
|
2
2
|
|
3
|
+
[](http://badge.fury.io/rb/mycmd)
|
4
|
+
[](https://travis-ci.org/i2bskn/mycmd)
|
5
|
+
[](https://coveralls.io/r/i2bskn/mycmd)
|
6
|
+
[](https://codeclimate.com/github/i2bskn/mycmd)
|
7
|
+
|
3
8
|
MySQL command line tool.
|
4
9
|
|
5
10
|
## Installation
|
@@ -16,11 +21,26 @@ Or install it yourself as:
|
|
16
21
|
|
17
22
|
$ gem install mycmd
|
18
23
|
|
24
|
+
## Settings
|
25
|
+
|
19
26
|
Create settings file:
|
20
27
|
|
21
28
|
$ touch ~/.mycmd.yml
|
22
29
|
$ mycmd config edit
|
23
30
|
|
31
|
+
Setting is the same as the argument of `Mysql2::Client.new`.
|
32
|
+
|
33
|
+
Sample settings:
|
34
|
+
|
35
|
+
```
|
36
|
+
host: localhost
|
37
|
+
port: 3306
|
38
|
+
username: root
|
39
|
+
password: secret
|
40
|
+
tasks:
|
41
|
+
slow: SELECT start_time, db, query_time, rows_sent, sql_text FROM mysql.slow_log WHERE db != 'mysql' ORDER BY start_time DESC LIMIT 30
|
42
|
+
```
|
43
|
+
|
24
44
|
## Usage
|
25
45
|
|
26
46
|
Start sql shell:
|
@@ -31,6 +51,7 @@ Start sql shell:
|
|
31
51
|
Execute sql:
|
32
52
|
|
33
53
|
$ mycmd query "SELECT * FROM somedb.sometable"
|
54
|
+
$ mycmd tasks slow
|
34
55
|
|
35
56
|
#### Config Commands
|
36
57
|
|
@@ -50,7 +71,7 @@ Edit config file:
|
|
50
71
|
|
51
72
|
Search settings:
|
52
73
|
|
53
|
-
$ mycmd
|
74
|
+
$ mycmd settings search innodb_buffer_pool_size
|
54
75
|
|
55
76
|
## Contributing
|
56
77
|
|
data/Rakefile
CHANGED
data/bin/mycmd
CHANGED
data/lib/mycmd/cli.rb
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
# coding: utf-8
|
2
2
|
|
3
3
|
require "mycmd/clis/config_commands"
|
4
|
-
require "mycmd/clis/
|
4
|
+
require "mycmd/clis/settings_commands"
|
5
5
|
|
6
6
|
module Mycmd
|
7
7
|
class CLI < Thor
|
8
8
|
default_command :console
|
9
9
|
register(ConfigCommands, "config", "config [COMMAND]", "commands for config")
|
10
|
-
register(
|
10
|
+
register(SettingsCommands, "settings", "settings [COMMAND]", "commands for settings")
|
11
11
|
|
12
12
|
desc "console", "console will start sql shell."
|
13
13
|
def console
|
@@ -32,5 +32,13 @@ module Mycmd
|
|
32
32
|
printer = Printer.new(client.query(sql), true)
|
33
33
|
printer.print
|
34
34
|
end
|
35
|
+
|
36
|
+
desc 'tasks [TASK NAME]', "tasks will execute register sql."
|
37
|
+
def tasks(task)
|
38
|
+
config = Configuration.new
|
39
|
+
client = config.connect
|
40
|
+
printer = Printer.new(client.query(config.tasks[task.to_s]), true)
|
41
|
+
printer.print
|
42
|
+
end
|
35
43
|
end
|
36
44
|
end
|
data/lib/mycmd/configuration.rb
CHANGED
@@ -21,6 +21,7 @@ module Mycmd
|
|
21
21
|
].freeze
|
22
22
|
|
23
23
|
attr_accessor *VALID_OPTIONS_KEYS
|
24
|
+
attr_accessor :tasks
|
24
25
|
attr_reader :path
|
25
26
|
|
26
27
|
def initialize
|
@@ -28,6 +29,7 @@ module Mycmd
|
|
28
29
|
end
|
29
30
|
|
30
31
|
def merge(params)
|
32
|
+
default
|
31
33
|
params.each do |k,v|
|
32
34
|
self.send("#{k.to_s}=", v)
|
33
35
|
end
|
@@ -49,12 +51,16 @@ module Mycmd
|
|
49
51
|
if @path
|
50
52
|
merge YAML.load_file(@path)
|
51
53
|
else
|
52
|
-
|
53
|
-
self.port = 3306
|
54
|
-
self.username = "root"
|
54
|
+
default
|
55
55
|
end
|
56
56
|
end
|
57
57
|
|
58
|
+
def default
|
59
|
+
self.host = "localhost"
|
60
|
+
self.port = 3306
|
61
|
+
self.username = "root"
|
62
|
+
end
|
63
|
+
|
58
64
|
class << self
|
59
65
|
def connect
|
60
66
|
conf = Configuration.new
|
data/lib/mycmd/version.rb
CHANGED
@@ -0,0 +1,114 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Mycmd::Configuration do
|
4
|
+
let(:home_dir) {"/Users/i2bskn"}
|
5
|
+
let(:conf_file) {File.join(home_dir, ".mycmd.yml")}
|
6
|
+
let(:config) do
|
7
|
+
Mycmd::Configuration.any_instance.stub(:reset).and_return(true)
|
8
|
+
Mycmd::Configuration.new
|
9
|
+
end
|
10
|
+
|
11
|
+
describe "#initialize" do
|
12
|
+
it "should call #reset" do
|
13
|
+
Mycmd::Configuration.any_instance.should_receive(:reset)
|
14
|
+
expect{
|
15
|
+
Mycmd::Configuration.new
|
16
|
+
}.not_to raise_error
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#merge" do
|
21
|
+
it "should call #default" do
|
22
|
+
Mycmd::Configuration.any_instance.should_receive(:default)
|
23
|
+
config.merge(host: "localhost")
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should set specified params" do
|
27
|
+
config.merge(host: "somehost")
|
28
|
+
expect(config.host).to eq("somehost")
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should generate exception if unknown params" do
|
32
|
+
expect {
|
33
|
+
config.merge(unknown: "unknown")
|
34
|
+
}.to raise_error
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe "#to_hash" do
|
39
|
+
it "returns config hash" do
|
40
|
+
config.default
|
41
|
+
expect(config.to_hash.is_a? Hash).to be_true
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#connect" do
|
46
|
+
before {Mysql2::Client.should_receive(:new)}
|
47
|
+
|
48
|
+
it "should create Mysql2::Client object" do
|
49
|
+
expect {
|
50
|
+
config.connect
|
51
|
+
}.not_to raise_error
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "#reset" do
|
56
|
+
it "should load yaml file" do
|
57
|
+
Mycmd::Configuration.should_receive(:config_find).and_return(conf_file)
|
58
|
+
Mycmd::Configuration.any_instance.should_receive(:merge)
|
59
|
+
YAML.should_receive(:load_file).with(conf_file)
|
60
|
+
expect {
|
61
|
+
Mycmd::Configuration.new
|
62
|
+
}.not_to raise_error
|
63
|
+
end
|
64
|
+
|
65
|
+
it "should call #default if config not found" do
|
66
|
+
Mycmd::Configuration.should_receive(:config_find).and_return(nil)
|
67
|
+
Mycmd::Configuration.any_instance.should_receive(:default)
|
68
|
+
expect {
|
69
|
+
Mycmd::Configuration.new
|
70
|
+
}.not_to raise_error
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe "#default" do
|
75
|
+
before {config.default}
|
76
|
+
|
77
|
+
it "should set default value to host" do
|
78
|
+
expect(config.host).to eq("localhost")
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should set default value to port" do
|
82
|
+
expect(config.port).to eq(3306)
|
83
|
+
end
|
84
|
+
|
85
|
+
it "should set default value to username" do
|
86
|
+
expect(config.username).to eq("root")
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
describe ".connect" do
|
91
|
+
it "should call #connect" do
|
92
|
+
mock = double("configuration mock")
|
93
|
+
mock.should_receive(:connect)
|
94
|
+
Mycmd::Configuration.should_receive(:new).and_return(mock)
|
95
|
+
expect {
|
96
|
+
Mycmd::Configuration.connect
|
97
|
+
}.not_to raise_error
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
describe ".config_find" do
|
102
|
+
let(:path) {Mycmd::Configuration.config_find(home_dir)}
|
103
|
+
|
104
|
+
it "returns config path" do
|
105
|
+
File.should_receive(:exists?).and_return(true)
|
106
|
+
expect(path).to eq(conf_file)
|
107
|
+
end
|
108
|
+
|
109
|
+
it "returns nil if config not found" do
|
110
|
+
File.should_receive(:exists?).at_least(2).and_return(false)
|
111
|
+
expect(path).to be_nil
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
require "simplecov"
|
2
|
+
require "coveralls"
|
3
|
+
Coveralls.wear!
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
6
|
+
SimpleCov::Formatter::HTMLFormatter,
|
7
|
+
Coveralls::SimpleCov::Formatter
|
8
|
+
]
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
10
|
+
SimpleCov.start do
|
11
|
+
add_filter "spec"
|
12
|
+
add_filter ".bundle"
|
13
|
+
end
|
14
14
|
|
15
15
|
require "mycmd"
|
16
16
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mycmd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- i2bskn
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -88,7 +88,9 @@ executables:
|
|
88
88
|
extensions: []
|
89
89
|
extra_rdoc_files: []
|
90
90
|
files:
|
91
|
+
- .coveralls.yml
|
91
92
|
- .gitignore
|
93
|
+
- .travis.yml
|
92
94
|
- Gemfile
|
93
95
|
- LICENSE.txt
|
94
96
|
- README.md
|
@@ -97,12 +99,13 @@ files:
|
|
97
99
|
- lib/mycmd.rb
|
98
100
|
- lib/mycmd/cli.rb
|
99
101
|
- lib/mycmd/clis/config_commands.rb
|
100
|
-
- lib/mycmd/clis/
|
102
|
+
- lib/mycmd/clis/settings_commands.rb
|
101
103
|
- lib/mycmd/configuration.rb
|
102
104
|
- lib/mycmd/printer.rb
|
103
105
|
- lib/mycmd/version.rb
|
104
106
|
- mycmd.gemspec
|
105
107
|
- spec/mycmd/cli_spec.rb
|
108
|
+
- spec/mycmd/configuration_spec.rb
|
106
109
|
- spec/spec_helper.rb
|
107
110
|
homepage: https://github.com/i2bskn/mycmd
|
108
111
|
licenses:
|
@@ -130,4 +133,5 @@ specification_version: 4
|
|
130
133
|
summary: MySQL command line tool
|
131
134
|
test_files:
|
132
135
|
- spec/mycmd/cli_spec.rb
|
136
|
+
- spec/mycmd/configuration_spec.rb
|
133
137
|
- spec/spec_helper.rb
|