mycmd 0.0.1 → 0.0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ec8662beb4d966823e1d6594a2f6cba96923377e
4
- data.tar.gz: b1a044c5b653bdb725fc8cdc9a8f17ac3c9ba7a7
3
+ metadata.gz: bf1b833907aa455e71b88d4fd93f821274103a13
4
+ data.tar.gz: 1dc6c7315cd5d5f157c5bb2b1bfaf5ab6106d9d9
5
5
  SHA512:
6
- metadata.gz: 9556025211eafb296bfd0fff9933bdcfb54aa3efa9756726842f12850e19db7a31f356e44dca98866140afa706237468e4f00be07e20f6b1de7a3390622a6826
7
- data.tar.gz: 4f9691a71d9c26ba2efe35e776b8257392fe371d12049c899dc105f11bd24c02426b498da6cfc86cab4458776952c6f4c1c9f207a08007fe061883dc893b7ad0
6
+ metadata.gz: a7eb2b0c883a5207ab4466b251c5e4fd01026126e98a4865ef6ff2069be2ac8b8ea7dd87c8ce4cd4a9c74b79a40e8e368e95ebd275e25493419b4465ddaaf7d4
7
+ data.tar.gz: 1fdda7ab25c75dcb20b47498328475dc9b1eb0a8ff3e778fa266baf28915cb8409aaab6dd3ee9f276a52b256864e02558ae17f97b82f547e0b5165d7440b6a84
data/.coveralls.yml ADDED
@@ -0,0 +1 @@
1
+ repo_token: DCRCxDWuGTexjBU06uzLipNo1sphCZ6si
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ gemfile:
6
+ - Gemfile
7
+ script: bundle exec rake spec
8
+ notifications:
9
+ mails:
10
+ - i2bskn@gmail.com
data/README.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Mycmd
2
2
 
3
+ [![Gem Version](https://badge.fury.io/rb/mycmd.png)](http://badge.fury.io/rb/mycmd)
4
+ [![Build Status](https://travis-ci.org/i2bskn/mycmd.png?branch=master)](https://travis-ci.org/i2bskn/mycmd)
5
+ [![Coverage Status](https://coveralls.io/repos/i2bskn/mycmd/badge.png)](https://coveralls.io/r/i2bskn/mycmd)
6
+ [![Code Climate](https://codeclimate.com/github/i2bskn/mycmd.png)](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 setting search innodb_buffer_pool_size
74
+ $ mycmd settings search innodb_buffer_pool_size
54
75
 
55
76
  ## Contributing
56
77
 
data/Rakefile CHANGED
@@ -1 +1,9 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ desc "Run all specs"
5
+ RSpec::Core::RakeTask.new(:spec) do |t|
6
+ t.rspec_opts = ["-c", "-fs"]
7
+ end
8
+
9
+ task :default => :spec
data/bin/mycmd CHANGED
@@ -1,11 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  # coding: utf-8
3
3
 
4
- # Temporary code until the first release
5
- $:.unshift(File.expand_path("../../lib", __FILE__))
6
- require "bundler/setup"
7
- # /Temp
8
-
9
4
  require "mycmd"
10
5
 
11
6
  Mycmd::CLI.start
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/setting_commands"
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(SettingCommands, "setting", "setting [COMMAND]", "commands for setting")
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
@@ -1,8 +1,8 @@
1
1
  # coding: utf-8
2
2
 
3
3
  module Mycmd
4
- class SettingCommands < Thor
5
- namespace :setting
4
+ class SettingsCommands < Thor
5
+ namespace :settings
6
6
 
7
7
  desc "search innodb_buffer_pool_size", "search will print settings"
8
8
  def search(keyword)
@@ -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
- self.host = "localhost"
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
@@ -1,3 +1,3 @@
1
1
  module Mycmd
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -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
- # require "simplecov"
2
- # require "coveralls"
3
- # Coveralls.wear!
1
+ require "simplecov"
2
+ require "coveralls"
3
+ Coveralls.wear!
4
4
 
5
- # SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
6
- # SimpleCov::Formatter::HTMLFormatter,
7
- # Coveralls::SimpleCov::Formatter
8
- # ]
5
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
6
+ SimpleCov::Formatter::HTMLFormatter,
7
+ Coveralls::SimpleCov::Formatter
8
+ ]
9
9
 
10
- # SimpleCov.start do
11
- # add_filter "spec"
12
- # add_filter ".bundle"
13
- # end
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.1
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-20 00:00:00.000000000 Z
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/setting_commands.rb
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