taketo 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +30 -4
- data/VERSION +1 -1
- data/features/commands.feature +0 -6
- data/features/config.feature +57 -0
- data/features/help.feature +6 -3
- data/lib/taketo/config_printer_visitor.rb +2 -1
- data/lib/taketo/constructs/command.rb +5 -1
- data/lib/taketo/constructs/server.rb +5 -1
- data/lib/taketo/dsl.rb +1 -0
- data/spec/lib/taketo/config_printer_visitor_spec.rb +10 -2
- data/spec/lib/taketo/constructs/command_spec.rb +5 -0
- data/spec/lib/taketo/constructs/server_spec.rb +21 -4
- data/spec/lib/taketo/dsl_spec.rb +4 -0
- metadata +4 -9
data/README.md
CHANGED
@@ -33,6 +33,7 @@ puts a config into ```~/.taketo.rc.rb```:
|
|
33
33
|
port 10001
|
34
34
|
user "app"
|
35
35
|
localtion "/var/app"
|
36
|
+
default_command "tmux attach"
|
36
37
|
env :TERM => "xterm-256color"
|
37
38
|
command :console do
|
38
39
|
execute "rails c"
|
@@ -44,7 +45,9 @@ puts a config into ```~/.taketo.rc.rb```:
|
|
44
45
|
```
|
45
46
|
|
46
47
|
Then execute ```taketo my_project:staging:server -c console``` to execute the "rails c" with corresponding environment variables set on desired server
|
47
|
-
or just ```taketo my_project:staging:server``` to
|
48
|
+
or just ```taketo my_project:staging:server``` to attach to tmux on the server
|
49
|
+
|
50
|
+
```default_command``` can be either name of defined server command, or explicit command string. Initially, default command is 'bash'.
|
48
51
|
|
49
52
|
To have a brief overview of the config run ```taketo [destination] --view```
|
50
53
|
|
@@ -105,7 +108,7 @@ You can use shared server configs to reduce duplication:
|
|
105
108
|
|
106
109
|
server :s2 do
|
107
110
|
host :s2 do
|
108
|
-
|
111
|
+
include_shared_server_configs(:my_staging, :some_other_shared_config => "qux")
|
109
112
|
end
|
110
113
|
end
|
111
114
|
end
|
@@ -113,9 +116,34 @@ You can use shared server configs to reduce duplication:
|
|
113
116
|
|
114
117
|
This will give you ```console``` commands available both on s1 and s2
|
115
118
|
|
119
|
+
Also it's possible to specify default server configuration for any scope (whole config, project or an environment):
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
default_server_config do
|
123
|
+
env :TERM => "xterm-256color"
|
124
|
+
end
|
125
|
+
|
126
|
+
project :my_project do
|
127
|
+
default_server_config do # will also include global default server config
|
128
|
+
location '/var/apps'
|
129
|
+
end
|
130
|
+
|
131
|
+
...
|
132
|
+
end
|
133
|
+
|
134
|
+
project :my_project2 do
|
135
|
+
...
|
136
|
+
end
|
137
|
+
```
|
138
|
+
|
139
|
+
Default configs are merged appropriately.
|
140
|
+
|
116
141
|
The Changelog:
|
117
142
|
--------------
|
118
143
|
|
144
|
+
### v0.0.9 (17.11.2012) ###
|
145
|
+
* Add default_command server config option
|
146
|
+
|
119
147
|
### v0.0.8 (17.11.2012) ###
|
120
148
|
* Add per-config, per-project and per-environment default server config support, i.e.
|
121
149
|
```ruby
|
@@ -175,8 +203,6 @@ The Changelog:
|
|
175
203
|
TO-DO:
|
176
204
|
------
|
177
205
|
|
178
|
-
* Shared server configs without arguments
|
179
|
-
* Global server defaults
|
180
206
|
* Override default commands per server
|
181
207
|
* Define servers outside projects and environments
|
182
208
|
* Export SSH config (i.e. for scp)
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.9
|
data/features/commands.feature
CHANGED
@@ -34,9 +34,3 @@ Feature:
|
|
34
34
|
ssh -t 1.2.3.4 "cd /var/apps/slots; RAILS_ENV=staging rails c"
|
35
35
|
"""
|
36
36
|
|
37
|
-
Scenario: Override default location specified for server
|
38
|
-
When I run taketo --dry-run --directory /var/www slots:staging
|
39
|
-
Then the output should contain
|
40
|
-
"""
|
41
|
-
ssh -t 1.2.3.4 "cd /var/www; RAILS_ENV=staging bash"
|
42
|
-
"""
|
data/features/config.feature
CHANGED
@@ -118,3 +118,60 @@ Feature: taketo config
|
|
118
118
|
ssh -t 2.3.4.5 "RAILS_ENV=staging bash"
|
119
119
|
"""
|
120
120
|
|
121
|
+
Scenario: Override default location specified for server
|
122
|
+
When I have the following config
|
123
|
+
"""
|
124
|
+
project :slots do
|
125
|
+
environment :staging do
|
126
|
+
server do
|
127
|
+
location '/var/foo'
|
128
|
+
host "1.2.3.4"
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
"""
|
133
|
+
When I run taketo --dry-run --directory /var/www slots:staging
|
134
|
+
Then the output should contain
|
135
|
+
"""
|
136
|
+
ssh -t 1.2.3.4 "cd /var/www; RAILS_ENV=staging bash"
|
137
|
+
"""
|
138
|
+
|
139
|
+
Scenario: Default server command
|
140
|
+
When I have the following config
|
141
|
+
"""
|
142
|
+
project :slots do
|
143
|
+
environment :staging do
|
144
|
+
server do
|
145
|
+
host "1.2.3.4"
|
146
|
+
|
147
|
+
default_command :tmux
|
148
|
+
|
149
|
+
command :tmux do
|
150
|
+
execute "tmux attach || tmux new-session"
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
end
|
155
|
+
"""
|
156
|
+
When I run taketo --dry-run slots:staging
|
157
|
+
Then the output should contain
|
158
|
+
"""
|
159
|
+
ssh -t 1.2.3.4 "RAILS_ENV=staging tmux attach || tmux new-session"
|
160
|
+
"""
|
161
|
+
When I have the following config
|
162
|
+
"""
|
163
|
+
project :slots do
|
164
|
+
environment :staging do
|
165
|
+
server do
|
166
|
+
host "1.2.3.4"
|
167
|
+
default_command "do_something"
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
"""
|
172
|
+
When I run taketo --dry-run slots:staging
|
173
|
+
Then the output should contain
|
174
|
+
"""
|
175
|
+
ssh -t 1.2.3.4 "RAILS_ENV=staging do_something"
|
176
|
+
"""
|
177
|
+
|
data/features/help.feature
CHANGED
@@ -21,8 +21,9 @@ Feature:
|
|
21
21
|
environment :qux do
|
22
22
|
server :bart do
|
23
23
|
host "2.3.4.5"
|
24
|
+
default_command :console
|
24
25
|
command :console do
|
25
|
-
execute "
|
26
|
+
execute "rails c"
|
26
27
|
end
|
27
28
|
command :killall do
|
28
29
|
execute "killall humans"
|
@@ -45,14 +46,16 @@ Feature:
|
|
45
46
|
Port: 5678
|
46
47
|
User: pivo
|
47
48
|
Default location: /var/apps/vodka
|
49
|
+
Default command: bash
|
48
50
|
Environment: RAILS_ENV=bar
|
49
|
-
(No commands)
|
50
51
|
|
51
52
|
Project: baz
|
52
53
|
Environment: qux
|
53
54
|
Server: bart
|
54
55
|
Host: 2.3.4.5
|
56
|
+
Default command: rails c
|
55
57
|
Environment: RAILS_ENV=qux
|
58
|
+
Commands:
|
56
59
|
console
|
57
60
|
killall - Kill ALL humans
|
58
61
|
|
@@ -67,7 +70,7 @@ Feature:
|
|
67
70
|
Port: 5678
|
68
71
|
User: pivo
|
69
72
|
Default location: /var/apps/vodka
|
73
|
+
Default command: bash
|
70
74
|
Environment: RAILS_ENV=bar
|
71
|
-
(No commands)
|
72
75
|
|
73
76
|
"""
|
@@ -40,8 +40,9 @@ module Taketo
|
|
40
40
|
put "Port: #{server.port}" if server.port
|
41
41
|
put "User: #{server.username}" if server.username
|
42
42
|
put "Default location: #{server.default_location}" if server.default_location
|
43
|
+
put "Default command: #{server.default_command}"
|
43
44
|
put "Environment: " + server.environment_variables.map { |n, v| "#{n}=#{v}" }.join(" ")
|
44
|
-
|
45
|
+
put "Commands:" if server.has_commands?
|
45
46
|
end
|
46
47
|
end
|
47
48
|
end
|
@@ -13,13 +13,17 @@ module Taketo
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def self.explicit_command(command_string)
|
16
|
-
new(:explicit_command).tap { |cmd| cmd.command = command_string }
|
16
|
+
new(:explicit_command).tap { |cmd| cmd.command = command_string.to_s }
|
17
17
|
end
|
18
18
|
|
19
19
|
def render(server, options = {})
|
20
20
|
%Q[#{location(server, options)} #{environment_variables(server)} #{command}].strip.squeeze(" ")
|
21
21
|
end
|
22
22
|
|
23
|
+
def to_s
|
24
|
+
command.to_s
|
25
|
+
end
|
26
|
+
|
23
27
|
private
|
24
28
|
|
25
29
|
def location(server, options = {})
|
@@ -26,7 +26,11 @@ module Taketo
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def default_command
|
29
|
-
defined?
|
29
|
+
if defined? @default_command
|
30
|
+
find_command(@default_command) || Command.explicit_command(@default_command)
|
31
|
+
else
|
32
|
+
Command.default
|
33
|
+
end
|
30
34
|
end
|
31
35
|
end
|
32
36
|
end
|
data/lib/taketo/dsl.rb
CHANGED
@@ -68,6 +68,7 @@ module Taketo
|
|
68
68
|
define_method_in_scope(:global_alias,:server) { |alias_name| current_scope_object.global_alias = alias_name }
|
69
69
|
define_method_in_scope(:env, :server) { |env| current_scope_object.env(env) }
|
70
70
|
define_method_in_scope(:identity_file, :server) { |identity_file| current_scope_object.identity_file = identity_file }
|
71
|
+
define_method_in_scope(:default_command, :server) { |command| current_scope_object.default_command = command }
|
71
72
|
define_method_in_scope(:execute, :command) { |command| current_scope_object.command = command }
|
72
73
|
define_method_in_scope(:desc, :command) { |description| current_scope_object.description = description }
|
73
74
|
|
@@ -29,6 +29,7 @@ describe "ConfigPrinterVisitor" do
|
|
29
29
|
:port => 8000,
|
30
30
|
:username => "bob",
|
31
31
|
:default_location => "/var/app",
|
32
|
+
:default_command => "tmux",
|
32
33
|
:environment_variables => { :FOO => "bar", :BOO => "baz" })
|
33
34
|
end
|
34
35
|
|
@@ -41,13 +42,20 @@ describe "ConfigPrinterVisitor" do
|
|
41
42
|
Port: 8000
|
42
43
|
User: bob
|
43
44
|
Default location: /var/app
|
45
|
+
Default command: tmux
|
44
46
|
Environment: (FOO=bar BOO=baz|BOO=baz FOO=bar)])
|
45
47
|
end
|
46
48
|
|
47
|
-
it "renders
|
49
|
+
it "does not renders commands section header if there are no commands defined" do
|
48
50
|
server.stub(:has_commands? => false)
|
49
51
|
printer.visit_server(server)
|
50
|
-
expect(printer.result).
|
52
|
+
expect(printer.result).not_to match(/commands/i)
|
53
|
+
end
|
54
|
+
|
55
|
+
it "renders commands if defined" do
|
56
|
+
server.stub(:has_commands? => true)
|
57
|
+
printer.visit_server(server)
|
58
|
+
expect(printer.result).to include("Commands:")
|
51
59
|
end
|
52
60
|
end
|
53
61
|
|
@@ -38,5 +38,10 @@ describe "Command" do
|
|
38
38
|
expect(Taketo::Constructs::Command.explicit_command("qq").command).to eq("qq")
|
39
39
|
end
|
40
40
|
end
|
41
|
+
|
42
|
+
specify "#to_s returns just command" do
|
43
|
+
command.command = "hello_there"
|
44
|
+
expect(command.to_s).to eq("hello_there")
|
45
|
+
end
|
41
46
|
end
|
42
47
|
|
@@ -15,7 +15,6 @@ describe "Server" do
|
|
15
15
|
it { should have_accessor(:port) }
|
16
16
|
it { should have_accessor(:username) }
|
17
17
|
it { should have_accessor(:default_location) }
|
18
|
-
it { should have_accessor(:default_command) }
|
19
18
|
it { should have_accessor(:global_alias) }
|
20
19
|
it { should have_accessor(:identity_file) }
|
21
20
|
|
@@ -25,9 +24,27 @@ describe "Server" do
|
|
25
24
|
end
|
26
25
|
end
|
27
26
|
|
28
|
-
|
29
|
-
Taketo::Constructs::Command.
|
30
|
-
|
27
|
+
describe "#default_command" do
|
28
|
+
before(:each) { stub_const("Taketo::Constructs::Command", Class.new) }
|
29
|
+
|
30
|
+
it "returns Command.default if nothing defined" do
|
31
|
+
Taketo::Constructs::Command.should_receive(:default).and_return(:qux)
|
32
|
+
expect(server.default_command).to eq(:qux)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "returns existing defined command if default command name is set" do
|
36
|
+
command = stub(:Command, :name => :foo)
|
37
|
+
server.commands << command
|
38
|
+
server.default_command = :foo
|
39
|
+
expect(server.default_command).to eq(command)
|
40
|
+
end
|
41
|
+
|
42
|
+
it "returns explicit command if default command not found by name" do
|
43
|
+
command = stub(:Command)
|
44
|
+
Taketo::Constructs::Command.should_receive(:explicit_command).with("tmux attach || tmux new-session").and_return(command)
|
45
|
+
server.default_command = "tmux attach || tmux new-session"
|
46
|
+
expect(server.default_command).to eq(command)
|
47
|
+
end
|
31
48
|
end
|
32
49
|
|
33
50
|
describe "#parent=" do
|
data/spec/lib/taketo/dsl_spec.rb
CHANGED
@@ -219,6 +219,10 @@ describe "DSL" do
|
|
219
219
|
it_behaves_like "a scoped method", :identity_file, :server, :identity_file=, "/home/gor/.ssh/qqq"
|
220
220
|
end
|
221
221
|
|
222
|
+
describe "#default_command" do
|
223
|
+
it_behaves_like "a scoped method", :default_command, :server, :default_command=, :tmux
|
224
|
+
end
|
225
|
+
|
222
226
|
describe "#command" do
|
223
227
|
it_behaves_like "a scope", :command, :server
|
224
228
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: taketo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.9
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -75,14 +75,9 @@ dependencies:
|
|
75
75
|
- - ~>
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0.6'
|
78
|
-
description: ! "
|
79
|
-
for web-developers
|
80
|
-
|
81
|
-
do\n host \"192.168.1.1\"\n location \"/var/www/prj1\"\n env
|
82
|
-
:TERM => \"xterm-256color\"\n end\n end\n end\n\n put it in ~/.taketo.rc.rb
|
83
|
-
(or wherever you want using --config)\n and `taketo my_project` effectively becomes:\n
|
84
|
-
\ `ssh -t 192.168.1.1 \"cd /var/www/prj1; TERM=xterm-256color RAILS_ENV=staging
|
85
|
-
bash\"`\n\n see http://github.com/v-yarotsky/taketo for additional instructions\n"
|
78
|
+
description: ! " Taketo is an utility to aid quick access to often used servers
|
79
|
+
for web-developers.\n Taketo uses a config written in ruby using light DSL.\n
|
80
|
+
\ See http://github.com/v-yarotsky/taketo for additional instructions\n"
|
86
81
|
email: vladimir.yarotksy@gmail.com
|
87
82
|
executables:
|
88
83
|
- taketo
|