peas-cli 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c59d042fdf3940b53dedbb2f1fd06669a1f4b918
4
- data.tar.gz: 025894d8b31e701527b681d6a6a6ac5da0bc6feb
3
+ metadata.gz: 84c1f06f1534d59fff16068ac6709e3c92e8448d
4
+ data.tar.gz: c1f74d412a7eed2cbf4c44a8fe40d52f483bb2e6
5
5
  SHA512:
6
- metadata.gz: 06c07b2f78e215dcee1c1ee0d276912dc53492cf44316143e1119996ce4a3f7ff05ac08d8e882f8f22878d75819ada585b9d6c79f6fde2180863fb6f04daece2
7
- data.tar.gz: 76662c09241e651b1217a76b043bde13a63bb4295ef8cd01377aa04cf334f80c8376ed02087920309497d186aee1cc074e860a0ad757e02443d965339e08c770
6
+ metadata.gz: e04075dea2bbb31efee01e1f52c7b7f97ed1d980b26fd02f97523d47812ac993953dd44432b41120cdcdfae1b100016f0cc4d6c38472ddc8b18230d8abbf443e
7
+ data.tar.gz: f48ebe5a3b750face0bb48d4f56d97404647b89a0125218036103481ff146305705b98e1808a9e7ad14e77a989ae5d83d14a099545627e7edf5019ac56c4dcc8
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.2.0
data/lib/peas/api.rb CHANGED
@@ -35,9 +35,7 @@ class API
35
35
  if api_version[0] != client_version[0]
36
36
  version_mismatch = true
37
37
  else
38
- if api_version[1] != client_version[1]
39
- version_mismatch = true
40
- end
38
+ version_mismatch = true if api_version[1] != client_version[1]
41
39
  end
42
40
  if version_mismatch
43
41
  Peas.warning_message "Your version of the CLI client is out of date " \
@@ -45,7 +43,11 @@ class API
45
43
  "Please update using `gem install peas-cli`."
46
44
  end
47
45
  # Normal API response
48
- puts json['message']
46
+ if block_given?
47
+ yield json['message']
48
+ else
49
+ puts json['message']
50
+ end
49
51
  end
50
52
  end
51
53
 
@@ -1,33 +1,33 @@
1
- desc 'Set Peas global settings'
2
- command :settings do |c|
3
- c.flag 'domain',
4
- type: String,
5
- desc: 'The FQDN for the Peas server'
6
- c.action do |_global_options, options, _args|
7
- if options['domain']
8
- unless options['domain'].start_with? 'http://'
9
- options['domain'] = "http://#{options['domain']}"
10
- end
11
- end
12
- # Gli seems to provide a String and Symbol key for every option, so the options hash needs
13
- # de-duplicating
14
- deduped = {}
15
- options.each do |k, v|
16
- deduped[k] = v if k.is_a? String
1
+ def format_settings(hash)
2
+ puts "Available settings"
3
+ puts ''
4
+ hash.each do |type, settings|
5
+ puts "#{type.capitalize}:"
6
+ settings.each do |setting, value|
7
+ value = '[unset]' if value == ''
8
+ puts " #{setting} #{value}"
17
9
  end
18
- # Merge existing settings with current settings
19
- content = Peas.config.merge(deduped).to_json
20
- File.open(Peas.config_file, 'w+') { |f| f.write(content) }
21
- # Save the settings on the server as well
22
- @api = API.new # Refresh settings from file
23
- @api.request :put, '/admin/settings', options
24
- puts "New settings:"
25
- puts JSON.pretty_generate(Peas.config)
10
+ puts ''
26
11
  end
27
- desc 'Display the current settings'
28
- c.command :display do |c|
29
- c.action do |_global_options, _options, _args|
30
- puts JSON.pretty_generate(Peas.config)
12
+ end
13
+
14
+ desc "Admin commands"
15
+ command :admin do |admin|
16
+ admin.desc 'Set Peas global system settings'
17
+ admin.command :settings do |settings|
18
+ settings.action do |_global_options, _options, args|
19
+ if args.count > 1
20
+ if args.first == 'peas.domain'
21
+ domain = args[1]
22
+ domain = "http://#{domain}" unless domain.start_with? 'http://'
23
+ content = Peas.config.merge('domain' => domain).to_json
24
+ File.open(Peas.config_file, 'w+') { |f| f.write(content) }
25
+ @api = API.new # Refresh settings from file because there's a new domain URI
26
+ end
27
+ @api.request(:put, '/admin/settings', args[0] => args[1]) { |response| format_settings response }
28
+ else
29
+ @api.request(:get, '/admin/settings') { |response| format_settings response }
30
+ end
31
31
  end
32
32
  end
33
33
  end
data/lib/peas/config.rb CHANGED
@@ -16,15 +16,16 @@ module Peas
16
16
 
17
17
  # Hierarchy of sources for the Peas API domain
18
18
  def self.api_domain
19
- domain = if ENV['PEAS_API_ENDPOINT']
20
- ENV['PEAS_API_ENDPOINT']
19
+ domain =
20
+ if ENV['PEAS_API_ENDPOINT']
21
+ ENV['PEAS_API_ENDPOINT']
21
22
  elsif Peas.config['domain']
22
- Peas.config['domain']
23
+ Peas.config['domain']
23
24
  else
24
- 'localhost:4000'
25
+ 'vcap.me:4000'
25
26
  end
26
27
  unless domain[/\Ahttp:\/\//] || domain[/\Ahttps:\/\//]
27
- domain = "http://#{domain}"
28
+ "http://#{domain}"
28
29
  else
29
30
  domain
30
31
  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.1.3 ruby lib
5
+ # stub: peas-cli 0.2.0 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "peas-cli"
9
- s.version = "0.1.3"
9
+ s.version = "0.2.0"
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-11"
14
+ s.date = "2014-07-23"
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
@@ -11,21 +11,27 @@ describe 'Peas CLI' do
11
11
  end
12
12
 
13
13
  describe 'Settings' do
14
- it 'should set settings' do
15
- stub_request(:put, 'http://new-domain.com:4000/admin/settings?domain=new-domain.com:4000')
16
- .to_return(body: response_mock(nil))
17
- output = cli %w(settings --domain=new-domain.com:4000)
18
- expect(output).to eq "\nNew settings:\n{\n \"domain\": \"http://new-domain.com:4000\"\n}\n"
14
+ it 'should set and use the domain setting' do
15
+ stub_request(:put, 'http://new-domain.com:4000/admin/settings?peas.domain=new-domain.com:4000')
16
+ .to_return(body: response_mock({}))
17
+ cli %w(admin settings peas.domain new-domain.com:4000)
19
18
  config = JSON.parse File.open('/tmp/.peas').read
20
19
  expect(config).to eq("domain" => "http://new-domain.com:4000")
21
20
  end
22
21
 
23
- it 'should use the domain setting' do
24
- File.open('/tmp/.peas', 'w') { |f| f.write('{"domain":"test.com"}') }
25
- stub_request(:get, /test.com/)
26
- .to_return(body: response_mock(nil))
27
- cli %w(deploy)
22
+ it 'should set a normal setting' do
23
+ stub_request(:put, 'http://vcap.me:4000/admin/settings?mongodb.uri=mongodb://uri')
24
+ .to_return(body: response_mock(
25
+ defaults: {'peas.domain' => 'http://boss.com'},
26
+ services: {
27
+ 'mongodb.uri' => 'mongodb://uri',
28
+ 'postgres.uri' => 'xsgfd'
29
+ }
30
+ ))
31
+ output = cli %w(admin settings mongodb.uri mongodb://uri)
32
+ expect(output).to eq("Available settings\n\nDefaults:\n peas.domain http://boss.com\n\nServices:\n mongodb.uri mongodb://uri\n postgres.uri xsgfd\n\n")
28
33
  end
34
+
29
35
  end
30
36
 
31
37
  describe 'App methods' do
data/spec/spec_helper.rb CHANGED
@@ -8,7 +8,7 @@ require 'lib/peas'
8
8
  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
- TEST_DOMAIN = 'http://localhost:4000'
11
+ TEST_DOMAIN = 'http://vcap.me:4000'
12
12
  SWITCHBOARD_TEST_PORT = 79_345
13
13
 
14
14
  RSpec.configure do |config|
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.3
4
+ version: 0.2.0
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 00:00:00.000000000 Z
11
+ date: 2014-07-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: gli