peas-cli 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Rakefile +2 -2
- data/VERSION +1 -1
- data/bin/peas +4 -4
- data/lib/peas/api.rb +10 -11
- data/lib/peas/commands/admin.rb +7 -7
- data/lib/peas/commands/app.rb +10 -10
- data/lib/peas/commands/config.rb +9 -9
- data/lib/peas/commands/logs.rb +1 -1
- data/lib/peas/config.rb +5 -7
- data/lib/peas/git.rb +2 -2
- data/lib/peas.rb +0 -1
- data/peas-cli.gemspec +3 -3
- data/spec/cli_spec.rb +3 -3
- data/spec/spec_helper.rb +3 -3
- 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: c59d042fdf3940b53dedbb2f1fd06669a1f4b918
|
4
|
+
data.tar.gz: 025894d8b31e701527b681d6a6a6ac5da0bc6feb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 06c07b2f78e215dcee1c1ee0d276912dc53492cf44316143e1119996ce4a3f7ff05ac08d8e882f8f22878d75819ada585b9d6c79f6fde2180863fb6f04daece2
|
7
|
+
data.tar.gz: 76662c09241e651b1217a76b043bde13a63bb4295ef8cd01377aa04cf334f80c8376ed02087920309497d186aee1cc074e860a0ad757e02443d965339e08c770
|
data/Rakefile
CHANGED
@@ -19,8 +19,8 @@ Jeweler::Tasks.new do |gem|
|
|
19
19
|
gem.homepage = "http://github.com/tombh/peas"
|
20
20
|
gem.license = "GPL v2"
|
21
21
|
gem.version = Peas::VERSION
|
22
|
-
gem.summary =
|
23
|
-
gem.description =
|
22
|
+
gem.summary = "CLI client for Peas"
|
23
|
+
gem.description = "Peas is an open source Heroku-style PaaS written in Ruby and using Docker"
|
24
24
|
gem.email = "tom@tombh.co.uk"
|
25
25
|
gem.authors = ["Tom Buckley-Houston"]
|
26
26
|
gem.files.include 'VERSION'
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/bin/peas
CHANGED
@@ -17,7 +17,7 @@ version Peas::VERSION
|
|
17
17
|
# Load all the commands
|
18
18
|
Dir["#{root_path}/lib/peas/commands/**/*.rb"].each { |f| load f }
|
19
19
|
|
20
|
-
pre do |
|
20
|
+
pre do |_global, _command, _options, _args|
|
21
21
|
# Pre logic here
|
22
22
|
# Return true to proceed; false to abort and not call the
|
23
23
|
# chosen command
|
@@ -26,7 +26,7 @@ pre do |global, command, options, args|
|
|
26
26
|
true
|
27
27
|
end
|
28
28
|
|
29
|
-
post do |
|
29
|
+
post do |_global, _command, _options, _args|
|
30
30
|
# Post logic here
|
31
31
|
# Use skips_post before a command to skip this
|
32
32
|
# block on that command only
|
@@ -36,7 +36,7 @@ on_error do |exception|
|
|
36
36
|
# Show a custom error message with backtrace if it's not a GLI error
|
37
37
|
if exception.class.to_s.split('::').first != 'GLI'
|
38
38
|
if exception.class == Errno::ECONNREFUSED
|
39
|
-
Peas.error_message "Couldn't connect to the Peas API. The current endpoint is '#{Peas.api_domain}', make "
|
39
|
+
Peas.error_message "Couldn't connect to the Peas API. The current endpoint is '#{Peas.api_domain}', make " \
|
40
40
|
"sure it is up and accessible."
|
41
41
|
else
|
42
42
|
Peas.error_message "Unexpected error: #{exception.class}"
|
@@ -48,7 +48,7 @@ on_error do |exception|
|
|
48
48
|
end
|
49
49
|
|
50
50
|
# Exit 0 if sent SIGINT
|
51
|
-
trap('INT'){
|
51
|
+
trap('INT') {
|
52
52
|
exit!
|
53
53
|
}
|
54
54
|
|
data/lib/peas/api.rb
CHANGED
@@ -13,17 +13,17 @@ class API
|
|
13
13
|
end
|
14
14
|
|
15
15
|
# Generic wrapper to the Peas API
|
16
|
-
def request
|
17
|
-
response = self.class.send(verb, "#{method}",
|
16
|
+
def request(verb, method, params = nil)
|
17
|
+
response = self.class.send(verb, "#{method}", query: params).body
|
18
18
|
if response
|
19
19
|
json = JSON.parse(response)
|
20
20
|
else
|
21
21
|
json = {}
|
22
22
|
end
|
23
23
|
# If there was an HTTP-level error
|
24
|
-
raise json['error'].color(:red) if json.
|
24
|
+
raise json['error'].color(:red) if json.key? 'error'
|
25
25
|
# Successful responses
|
26
|
-
if json.
|
26
|
+
if json.key? 'job'
|
27
27
|
# Long-running jobs need to stream from the Switchboard server
|
28
28
|
API.stream_job json['job']
|
29
29
|
else
|
@@ -40,8 +40,8 @@ class API
|
|
40
40
|
end
|
41
41
|
end
|
42
42
|
if version_mismatch
|
43
|
-
Peas.warning_message "Your version of the CLI client is out of date "
|
44
|
-
"(Client: #{Peas::VERSION}, API: #{json['version']}). "
|
43
|
+
Peas.warning_message "Your version of the CLI client is out of date " \
|
44
|
+
"(Client: #{Peas::VERSION}, API: #{json['version']}). " \
|
45
45
|
"Please update using `gem install peas-cli`."
|
46
46
|
end
|
47
47
|
# Normal API response
|
@@ -54,9 +54,9 @@ class API
|
|
54
54
|
end
|
55
55
|
|
56
56
|
# Stream the output of a Switchboard job
|
57
|
-
def self.stream_job
|
57
|
+
def self.stream_job(job)
|
58
58
|
API.stream_output "subscribe.job_progress.#{job}" do |line|
|
59
|
-
if line.
|
59
|
+
if line.key? 'status'
|
60
60
|
if line['status'] == 'failed'
|
61
61
|
raise line['body']
|
62
62
|
elsif line['status'] == 'complete'
|
@@ -68,7 +68,7 @@ class API
|
|
68
68
|
end
|
69
69
|
|
70
70
|
# Stream data from the Switchboard server
|
71
|
-
def self.stream_output
|
71
|
+
def self.stream_output(switchboard_command)
|
72
72
|
socket = API.switchboard_connection
|
73
73
|
socket.puts switchboard_command
|
74
74
|
begin
|
@@ -82,5 +82,4 @@ class API
|
|
82
82
|
rescue Interrupt, Errno::ECONNRESET
|
83
83
|
end
|
84
84
|
end
|
85
|
-
|
86
|
-
end
|
85
|
+
end
|
data/lib/peas/commands/admin.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
desc 'Set Peas global settings'
|
2
2
|
command :settings do |c|
|
3
3
|
c.flag 'domain',
|
4
|
-
|
5
|
-
|
6
|
-
c.action do |
|
4
|
+
type: String,
|
5
|
+
desc: 'The FQDN for the Peas server'
|
6
|
+
c.action do |_global_options, options, _args|
|
7
7
|
if options['domain']
|
8
|
-
|
8
|
+
unless options['domain'].start_with? 'http://'
|
9
9
|
options['domain'] = "http://#{options['domain']}"
|
10
10
|
end
|
11
11
|
end
|
@@ -17,7 +17,7 @@ command :settings do |c|
|
|
17
17
|
end
|
18
18
|
# Merge existing settings with current settings
|
19
19
|
content = Peas.config.merge(deduped).to_json
|
20
|
-
File.open(Peas.config_file, 'w+'){|f| f.write(content) }
|
20
|
+
File.open(Peas.config_file, 'w+') { |f| f.write(content) }
|
21
21
|
# Save the settings on the server as well
|
22
22
|
@api = API.new # Refresh settings from file
|
23
23
|
@api.request :put, '/admin/settings', options
|
@@ -26,8 +26,8 @@ command :settings do |c|
|
|
26
26
|
end
|
27
27
|
desc 'Display the current settings'
|
28
28
|
c.command :display do |c|
|
29
|
-
c.action do |
|
29
|
+
c.action do |_global_options, _options, _args|
|
30
30
|
puts JSON.pretty_generate(Peas.config)
|
31
31
|
end
|
32
32
|
end
|
33
|
-
end
|
33
|
+
end
|
data/lib/peas/commands/app.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
desc 'Create an app'
|
2
2
|
command :create do |c|
|
3
|
-
c.action do |
|
4
|
-
@api.request :post, "/app/#{Git.first_sha}",
|
5
|
-
|
6
|
-
|
3
|
+
c.action do |_global_options, _options, _args|
|
4
|
+
@api.request :post, "/app/#{Git.first_sha}",
|
5
|
+
remote: Git.remote
|
6
|
+
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
10
|
desc 'Deploy an app'
|
11
11
|
command :deploy do |c|
|
12
|
-
c.action do |
|
12
|
+
c.action do |_global_options, _options, _args|
|
13
13
|
@api.request :get, "/app/#{Git.first_sha}/deploy"
|
14
14
|
end
|
15
15
|
end
|
@@ -19,7 +19,7 @@ long_desc <<-EOF
|
|
19
19
|
For example: peas scale web=3 worker=2
|
20
20
|
EOF
|
21
21
|
command :scale do |c|
|
22
|
-
c.action do |
|
22
|
+
c.action do |_global_options, _options, args|
|
23
23
|
if args.length == 0
|
24
24
|
exit_now! "Please provide scaling arguments in the form: web=3 worker=2"
|
25
25
|
end
|
@@ -30,8 +30,8 @@ command :scale do |c|
|
|
30
30
|
quantity = parts[1]
|
31
31
|
scaling_hash[process_type] = quantity
|
32
32
|
end
|
33
|
-
@api.request :put, "/app/#{Git.first_sha}/scale",
|
34
|
-
|
35
|
-
|
33
|
+
@api.request :put, "/app/#{Git.first_sha}/scale",
|
34
|
+
scaling_hash: scaling_hash.to_json
|
35
|
+
|
36
36
|
end
|
37
|
-
end
|
37
|
+
end
|
data/lib/peas/commands/config.rb
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
desc 'Add, remove and list config for an app'
|
2
2
|
command :config do |c|
|
3
3
|
c.default_desc 'List all config'
|
4
|
-
c.action do |
|
4
|
+
c.action do |_global_options, _options, _args|
|
5
5
|
@api.request :get, "/app/#{Git.first_sha}/config"
|
6
6
|
end
|
7
7
|
|
8
8
|
c.desc 'Delete config by keys'
|
9
9
|
c.command :rm do |sc|
|
10
|
-
sc.action do |
|
11
|
-
@api.request :delete, "/app/#{Git.first_sha}/config",
|
12
|
-
|
13
|
-
|
10
|
+
sc.action do |_global_options, _options, args|
|
11
|
+
@api.request :delete, "/app/#{Git.first_sha}/config",
|
12
|
+
keys: args.to_json
|
13
|
+
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
17
|
c.desc 'Set config for an app'
|
18
18
|
c.command :set do |sc|
|
19
|
-
sc.action do |
|
19
|
+
sc.action do |_global_options, _options, args|
|
20
20
|
if args.length == 0
|
21
21
|
exit_now! "Please provide config in the form: FOO=BAR ENV=production"
|
22
22
|
end
|
@@ -27,9 +27,9 @@ command :config do |c|
|
|
27
27
|
value = parts[1]
|
28
28
|
vars[key] = value
|
29
29
|
end
|
30
|
-
@api.request :put, "/app/#{Git.first_sha}/config",
|
31
|
-
|
32
|
-
|
30
|
+
@api.request :put, "/app/#{Git.first_sha}/config",
|
31
|
+
vars: vars.to_json
|
32
|
+
|
33
33
|
end
|
34
34
|
end
|
35
35
|
end
|
data/lib/peas/commands/logs.rb
CHANGED
data/lib/peas/config.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
module Peas
|
2
|
-
|
3
2
|
# The port for Peas' Switchboard socket server
|
4
3
|
SWITCHBOARD_PORT = ENV['SWITCHBOARD_PORT'] || 9345
|
5
4
|
|
@@ -18,9 +17,9 @@ module Peas
|
|
18
17
|
# Hierarchy of sources for the Peas API domain
|
19
18
|
def self.api_domain
|
20
19
|
domain = if ENV['PEAS_API_ENDPOINT']
|
21
|
-
|
20
|
+
ENV['PEAS_API_ENDPOINT']
|
22
21
|
elsif Peas.config['domain']
|
23
|
-
|
22
|
+
Peas.config['domain']
|
24
23
|
else
|
25
24
|
'localhost:4000'
|
26
25
|
end
|
@@ -35,12 +34,11 @@ module Peas
|
|
35
34
|
URI.parse(Peas.api_domain).host
|
36
35
|
end
|
37
36
|
|
38
|
-
def self.error_message
|
37
|
+
def self.error_message(string)
|
39
38
|
puts string.color(:red)
|
40
39
|
end
|
41
40
|
|
42
|
-
def self.warning_message
|
41
|
+
def self.warning_message(string)
|
43
42
|
puts string.color(:magenta)
|
44
43
|
end
|
45
|
-
|
46
|
-
end
|
44
|
+
end
|
data/lib/peas/git.rb
CHANGED
data/lib/peas.rb
CHANGED
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.1.
|
5
|
+
# stub: peas-cli 0.1.3 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "peas-cli"
|
9
|
-
s.version = "0.1.
|
9
|
+
s.version = "0.1.3"
|
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-07-
|
14
|
+
s.date = "2014-07-11"
|
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
@@ -7,7 +7,7 @@ describe 'Peas CLI' do
|
|
7
7
|
allow(Git).to receive(:first_sha).and_return('fakesha')
|
8
8
|
allow_any_instance_of(API).to receive(:sleep).and_return(nil)
|
9
9
|
allow(Peas).to receive(:config_file).and_return('/tmp/.peas')
|
10
|
-
File.delete '/tmp/.peas' if File.
|
10
|
+
File.delete '/tmp/.peas' if File.exist? '/tmp/.peas'
|
11
11
|
end
|
12
12
|
|
13
13
|
describe 'Settings' do
|
@@ -17,11 +17,11 @@ describe 'Peas CLI' do
|
|
17
17
|
output = cli %w(settings --domain=new-domain.com:4000)
|
18
18
|
expect(output).to eq "\nNew settings:\n{\n \"domain\": \"http://new-domain.com:4000\"\n}\n"
|
19
19
|
config = JSON.parse File.open('/tmp/.peas').read
|
20
|
-
expect(config).to eq(
|
20
|
+
expect(config).to eq("domain" => "http://new-domain.com:4000")
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'should use the domain setting' do
|
24
|
-
File.open('/tmp/.peas', 'w'){|f| f.write('{"domain":"test.com"}') }
|
24
|
+
File.open('/tmp/.peas', 'w') { |f| f.write('{"domain":"test.com"}') }
|
25
25
|
stub_request(:get, /test.com/)
|
26
26
|
.to_return(body: response_mock(nil))
|
27
27
|
cli %w(deploy)
|
data/spec/spec_helper.rb
CHANGED
@@ -9,7 +9,7 @@ ENV['GLI_ENV'] = 'test'
|
|
9
9
|
ROOT = File.join(File.expand_path(File.dirname(__FILE__)), '..')
|
10
10
|
$LOAD_PATH.unshift(File.join(ROOT, 'lib'))
|
11
11
|
TEST_DOMAIN = 'http://localhost:4000'
|
12
|
-
SWITCHBOARD_TEST_PORT =
|
12
|
+
SWITCHBOARD_TEST_PORT = 79_345
|
13
13
|
|
14
14
|
RSpec.configure do |config|
|
15
15
|
config.mock_with :rspec
|
@@ -38,7 +38,7 @@ end
|
|
38
38
|
|
39
39
|
# Form a response as the API would. Useful as you only need to provide a string without any JSON
|
40
40
|
# formatting
|
41
|
-
def response_mock
|
41
|
+
def response_mock(response, key = :message)
|
42
42
|
{
|
43
43
|
'version' => Peas::VERSION,
|
44
44
|
key => response
|
@@ -48,7 +48,7 @@ end
|
|
48
48
|
# Clever little function to simulate CLI requests.
|
49
49
|
# Usage: cli(['create', '--flag', '--switch']).
|
50
50
|
# Output is suppressed, captured and returned.
|
51
|
-
def cli
|
51
|
+
def cli(args)
|
52
52
|
stub_const "ARGV", args
|
53
53
|
capture_stdout do
|
54
54
|
ENV['GLI_DEBUG'] = 'true'
|
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.1.
|
4
|
+
version: 0.1.3
|
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-07-
|
11
|
+
date: 2014-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gli
|