peas-cli 0.3.0 → 0.3.1
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 +4 -4
- data/VERSION +1 -1
- data/lib/peas/api.rb +20 -22
- data/lib/peas/commands/app.rb +37 -0
- data/peas-cli.gemspec +3 -3
- data/spec/cli_spec.rb +15 -0
- data/spec/spec_helper.rb +23 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b404da416dc6ebddcb8f1f8c73a637dcbdfb760
|
4
|
+
data.tar.gz: 0810ed5cc0f6344fa4bad08d270dc9e3013cb3b3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3fcfbebaa21f1c45765a97cb7a5527838a7256353d3f5143b0946f3190305ad109f473e72343f3eb41c24dbd19c78652c97a7cb02199938eb4ba512a5608fb46
|
7
|
+
data.tar.gz: e99598b4321a28294efc9dc6e27eee3ffefd472432c58ca22ac160c62a66d80fd23aa79f1c15312dc302af9576f1bf8be9555f99a2ae4b10cbd707af1e389526
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.1
|
data/lib/peas/api.rb
CHANGED
@@ -15,11 +15,7 @@ class API
|
|
15
15
|
# Generic wrapper to the Peas API
|
16
16
|
def request(verb, method, params = nil)
|
17
17
|
response = self.class.send(verb, "#{method}", query: params).body
|
18
|
-
|
19
|
-
json = JSON.parse(response)
|
20
|
-
else
|
21
|
-
json = {}
|
22
|
-
end
|
18
|
+
json = response ? JSON.parse(response) : {}
|
23
19
|
# If there was an HTTP-level error
|
24
20
|
raise json['error'].color(:red) if json.key? 'error'
|
25
21
|
# Successful responses
|
@@ -27,22 +23,7 @@ class API
|
|
27
23
|
# Long-running jobs need to stream from the Switchboard server
|
28
24
|
API.stream_job json['job']
|
29
25
|
else
|
30
|
-
|
31
|
-
# Only check major and minor versions
|
32
|
-
version_mismatch = false
|
33
|
-
api_version = json['version'].split('.')
|
34
|
-
client_version = Peas::VERSION.split('.')
|
35
|
-
if api_version[0] != client_version[0]
|
36
|
-
version_mismatch = true
|
37
|
-
else
|
38
|
-
version_mismatch = true if api_version[1] != client_version[1]
|
39
|
-
end
|
40
|
-
if version_mismatch
|
41
|
-
Peas.warning_message "Your version of the CLI client is out of date " \
|
42
|
-
"(Client: #{Peas::VERSION}, API: #{json['version']}). " \
|
43
|
-
"Please update using `gem install peas-cli`."
|
44
|
-
end
|
45
|
-
# Normal API response
|
26
|
+
check_versions(json)
|
46
27
|
if block_given?
|
47
28
|
yield json['message']
|
48
29
|
else
|
@@ -52,6 +33,23 @@ class API
|
|
52
33
|
end
|
53
34
|
end
|
54
35
|
|
36
|
+
# Check CLI client is up to date.
|
37
|
+
def check_versions(json)
|
38
|
+
# Only check major and minor versions
|
39
|
+
version_mismatch = false
|
40
|
+
api_version = json['version'].split('.')
|
41
|
+
client_version = Peas::VERSION.split('.')
|
42
|
+
if api_version[0] != client_version[0]
|
43
|
+
version_mismatch = true
|
44
|
+
else
|
45
|
+
version_mismatch = true if api_version[1] != client_version[1]
|
46
|
+
end
|
47
|
+
return unless version_mismatch
|
48
|
+
Peas.warning_message "Your version of the CLI client is out of date " \
|
49
|
+
"(Client: #{Peas::VERSION}, API: #{json['version']}). " \
|
50
|
+
"Please update using `gem install peas-cli`."
|
51
|
+
end
|
52
|
+
|
55
53
|
def self.switchboard_connection
|
56
54
|
TCPSocket.new Peas.host, Peas::SWITCHBOARD_PORT
|
57
55
|
end
|
@@ -75,7 +73,7 @@ class API
|
|
75
73
|
socket = API.switchboard_connection
|
76
74
|
socket.puts switchboard_command
|
77
75
|
begin
|
78
|
-
while line = socket.gets
|
76
|
+
while (line = socket.gets)
|
79
77
|
if block_given?
|
80
78
|
yield JSON.parse line
|
81
79
|
else
|
data/lib/peas/commands/app.rb
CHANGED
@@ -59,3 +59,40 @@ command :scale do |c|
|
|
59
59
|
)
|
60
60
|
end
|
61
61
|
end
|
62
|
+
|
63
|
+
desc 'Run one-off commands'
|
64
|
+
long_desc <<-EOF
|
65
|
+
For example: peas run rake db:migrate
|
66
|
+
EOF
|
67
|
+
command :run do |c|
|
68
|
+
c.action do |_global_options, _options, args|
|
69
|
+
exit_now!("Please provide a command to run", 1) if args.length == 0
|
70
|
+
socket = API.switchboard_connection
|
71
|
+
socket.puts "tty.#{Git.name_from_remote}"
|
72
|
+
tty_command = args.join ' '
|
73
|
+
socket.puts tty_command
|
74
|
+
|
75
|
+
threads = []
|
76
|
+
|
77
|
+
# Copy STDIN to socket
|
78
|
+
threads << Thread.start do
|
79
|
+
STDIN.raw do |stdin|
|
80
|
+
IO.copy_stream stdin, socket
|
81
|
+
end
|
82
|
+
socket.close_write
|
83
|
+
end
|
84
|
+
|
85
|
+
# Write response to STDOUT
|
86
|
+
threads << Thread.start do
|
87
|
+
begin
|
88
|
+
while (chunk = socket.readpartial(512))
|
89
|
+
print chunk
|
90
|
+
end
|
91
|
+
rescue EOFError
|
92
|
+
end
|
93
|
+
threads.first.kill
|
94
|
+
end
|
95
|
+
|
96
|
+
threads.each(&:join)
|
97
|
+
end
|
98
|
+
end
|
data/peas-cli.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: peas-cli 0.3.
|
5
|
+
# stub: peas-cli 0.3.1 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "peas-cli"
|
9
|
-
s.version = "0.3.
|
9
|
+
s.version = "0.3.1"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Tom Buckley-Houston"]
|
14
|
-
s.date = "2014-
|
14
|
+
s.date = "2014-11-01"
|
15
15
|
s.description = "Peas is an open source Heroku-style PaaS written in Ruby and using Docker"
|
16
16
|
s.email = "tom@tombh.co.uk"
|
17
17
|
s.executables = ["peas"]
|
data/spec/cli_spec.rb
CHANGED
@@ -90,6 +90,21 @@ describe 'Peas CLI' do
|
|
90
90
|
expect(output).to eq "scaling\n"
|
91
91
|
end
|
92
92
|
|
93
|
+
describe 'Running one-off commands', :with_echo_server do
|
94
|
+
it 'should run one-off commands direct from the CLI' do
|
95
|
+
output = cli %w(run FINAL COMMAND)
|
96
|
+
expect(output).to eq "tty.test-test\nFINAL COMMAND\n"
|
97
|
+
end
|
98
|
+
it 'should run one-off with input from STDIN' do
|
99
|
+
io = StringIO.new 'FINAL COMMAND'
|
100
|
+
allow(STDIN).to receive(:raw) do |&block|
|
101
|
+
block.call io
|
102
|
+
end
|
103
|
+
output = cli %w(run WITH STDIN)
|
104
|
+
expect(output).to eq "tty.test-test\nWITH STDIN\nFINAL COMMAND\n"
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
93
108
|
describe 'Config ENV vars' do
|
94
109
|
it 'should set config for an app' do
|
95
110
|
stub_request(:put, TEST_DOMAIN + '/app/test-test/config?vars=%7B%22FOO%22:%22BAR%22%7D')
|
data/spec/spec_helper.rb
CHANGED
@@ -24,6 +24,29 @@ RSpec.configure do |config|
|
|
24
24
|
expect(@socket).to receive(:puts).with('subscribe.job_progress.123')
|
25
25
|
allow(TCPSocket).to receive(:new).and_return(@socket)
|
26
26
|
end
|
27
|
+
|
28
|
+
config.before(:each, :with_echo_server) do
|
29
|
+
@server = TCPServer.new 'vcap.me', SWITCHBOARD_TEST_PORT
|
30
|
+
Thread.new do
|
31
|
+
@connection = @server.accept
|
32
|
+
begin
|
33
|
+
Timeout.timeout(2) do
|
34
|
+
while (line = @connection.gets)
|
35
|
+
@connection.puts line
|
36
|
+
@connection.close if line.strip == 'FINAL COMMAND'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
rescue Timeout::Error
|
40
|
+
ensure
|
41
|
+
@connection.close
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
config.after(:each, :with_echo_server) do
|
47
|
+
@server.close rescue nil
|
48
|
+
end
|
49
|
+
|
27
50
|
end
|
28
51
|
|
29
52
|
# Execute a block that triggers STDOUT and test output
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: peas-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Buckley-Houston
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-11-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gli
|