magellan-cli 0.3.4 → 0.4.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: 825dac1a4d4361a1c521db2201e45592cab0359b
4
- data.tar.gz: 87893d4ac9dc1125bebc04160ce9c579a9928aef
3
+ metadata.gz: 9f81ab633b90549d1474807b9924f28eb0d87fed
4
+ data.tar.gz: 34fd0c8d234687f1b0b3cce29cd11b48a0431992
5
5
  SHA512:
6
- metadata.gz: f080a73494a60a47dcbe21bf0c7a39380a4d5c0b2bf0b957a987fefc4fc88ce9f380bf3ab81a900931b5465900e4c2f5f7ef4978d14032a82610ad5647a72c1c
7
- data.tar.gz: c6d8e64cea99a1ca67bdf15c16b7f471e473fa36541a2a02c9d3379011897f267211f899e67ba186ef5904473e002056c2347b2cccca0ac1a8393e2da00406cc
6
+ metadata.gz: 26e60decb0ff48f362516b2750719d48285bb721a163f23b88bb8f6164d1e3f6262c55e9178da54cbcff89e46f59a71a78f7fea73e3560d857802405932db76f
7
+ data.tar.gz: fc4bb095493fd8c09f8dbc8896a9f8fa62f4b60144864c3c63feb8b5b13412fe3ed795a0f8c1c5469dabeea97a0c70522875e915a17f6f0e78fbebc117ded255
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- magellan-cli (0.3.4)
4
+ magellan-cli (0.4.0)
5
5
  activesupport (~> 4.1.4)
6
6
  groovenauts-thor
7
7
  httpclient (~> 2.5)
@@ -22,11 +22,11 @@ module Magellan
22
22
  super(given_args, config)
23
23
  rescue Magellan::Cli::Error => e
24
24
  log_error(e.message)
25
- exit(1)
25
+ block_given? ? yield(e) : exit(1)
26
26
  rescue => e
27
27
  log_error("[#{e.class}] #{e.message}")
28
28
  log_verbose(" " << e.backtrace.join("\n "), ARGV.include?("-V") || ARGV.include?("--verbose"))
29
- exit(1)
29
+ block_given? ? yield(e) : exit(1)
30
30
  end
31
31
  end
32
32
 
@@ -56,6 +56,11 @@ en:
56
56
  async: "-A async mode. release_now returns soon"
57
57
  interval: "-i polling interval(seconds)"
58
58
  timeout: "-t timeout(seconds)"
59
+ cloudsql:
60
+ cmd_create:
61
+ async: "-A async mode. release_now returns soon"
62
+ interval: "-i polling interval(seconds)"
63
+ timeout: "-t timeout(seconds)"
59
64
  team:
60
65
  cmd:
61
66
  create: "Create a new %{resource_name} with NAME and ROLE"
@@ -56,6 +56,11 @@ ja:
56
56
  async: "-A 非同期モード。リリースの終了を待たずにコマンドを終了します"
57
57
  interval: "-i 状態を取得する間隔を秒で指定します"
58
58
  timeout: "-t タイムアウトを秒で指定します"
59
+ cloudsql:
60
+ cmd_create:
61
+ async: "-A 非同期モード。リリースの終了を待たずにコマンドを終了します"
62
+ interval: "-i 状態を取得する間隔を秒で指定します"
63
+ timeout: "-t タイムアウトを秒で指定します"
59
64
  team:
60
65
  cmd:
61
66
  create: "NAMEとROLEを指定して%{resource_name}を登録します"
@@ -99,11 +99,12 @@ module Magellan
99
99
 
100
100
  def list
101
101
  res1 = query_list
102
+ Magellan::Cli.last_result = res1
102
103
  show_list(res1)
103
104
  end
104
105
 
105
106
  def show_list(res1)
106
- return $stdout.puts("Total: 0") if res1.empty?
107
+ return $stdout.puts("Total: 0") if res1.nil? or res1.empty?
107
108
 
108
109
  t = Text::Table.new
109
110
  original_fields =
@@ -129,8 +130,10 @@ module Magellan
129
130
  $stdout.puts(t.to_s << "\nTotal: #{res1.length}")
130
131
  end
131
132
 
132
- def show(id)
133
+ def show(id = nil)
134
+ id ||= load_selection!(self.class.parameter_name)["id"]
133
135
  r = get_json("/admin/#{self.class.resource_key}/#{id}.json")
136
+ Magellan::Cli.last_result = r
134
137
  t = Text::Table.new
135
138
  t.head = ["field", "value"]
136
139
 
@@ -215,8 +218,8 @@ module Magellan
215
218
  super
216
219
  end
217
220
 
218
- desc "show ID", "#{I18n.t(:show, scope: [:resources_common, :cmd], res_name: res_name)}"
219
- def show(id)
221
+ desc "show [ID]", "#{I18n.t(:show, scope: [:resources_common, :cmd], res_name: res_name)}"
222
+ def show(id = nil)
220
223
  super(id)
221
224
  end
222
225
 
@@ -13,6 +13,9 @@ module Magellan
13
13
  self.hidden_fields = %w[cloudsql_instance_id].map(&:freeze).freeze
14
14
 
15
15
  desc "create NAME", I18n.t(:create, scope: [:resources_common, :cmd], resource_name: "#{resource_name} database")
16
+ option :A, type: :boolean, default: false, desc: I18n.t(:async, scope: [:cloudsql, :cmd_create])
17
+ option :i, type: :numeric, default: 10, desc: I18n.t(:interval, scope: [:cloudsql, :cmd_create])
18
+ option :t, type: :numeric, default: 600, desc: I18n.t(:timeout, scope: [:cloudsql, :cmd_create])
16
19
  def create(name)
17
20
  o = load_selection!(Stage)
18
21
  params = {
@@ -21,9 +24,22 @@ module Magellan
21
24
  "name" => name,
22
25
  }
23
26
  }
24
- post_json("/admin/#{resource_key}/new.json", params)
27
+ res0 = post_json("/admin/#{resource_key}/new.json", params)
25
28
  select(name)
29
+
30
+ return res0 if options["A"]
31
+
32
+ id = load_selection!(parameter_name)["id"]
33
+ interval = options["i"]
34
+ Timeout.timeout(options["t"]) do
35
+ loop do
36
+ sleep(interval)
37
+ res1 = get_json("/admin/#{resource_key}/#{id}.json")
38
+ return res1 if res1["available"]
39
+ end
40
+ end
26
41
  end
42
+
27
43
  end
28
44
  end
29
45
  end
@@ -0,0 +1,17 @@
1
+ require 'magellan/cli'
2
+
3
+ require 'shellwords'
4
+
5
+ def cli(args, options = {})
6
+ args = Shellwords.split(args) if args.is_a?(String)
7
+ args << "-V" if ARGV.include?("-V")
8
+ $PROGRAM_NAME, backup = "magellan-cli", $PROGRAM_NAME
9
+ puts "[CLI] `#{$PROGRAM_NAME} #{args.join(' ')}`"
10
+ begin
11
+ Magellan::Cli::Command.start(args) do |e|
12
+ exit(1) unless e.message =~ options[:allow]
13
+ end
14
+ ensure
15
+ $PROGRAM_NAME = backup
16
+ end
17
+ end
@@ -1,5 +1,5 @@
1
1
  module Magellan
2
2
  module Cli
3
- VERSION = "0.3.4"
3
+ VERSION = "0.4.0"
4
4
  end
5
5
  end
data/lib/magellan/cli.rb CHANGED
@@ -22,5 +22,10 @@ module Magellan
22
22
  }.freeze
23
23
 
24
24
  autoload :ReferenceGenerator, "magellan/cli/reference_generator"
25
+
26
+ class << self
27
+ attr_accessor :last_result
28
+ end
29
+
25
30
  end
26
31
  end
@@ -0,0 +1,28 @@
1
+ # -*- coding: utf-8 -*-
2
+ require 'spec_helper'
3
+ require 'magellan/cli/script'
4
+
5
+ describe Magellan::Cli do
6
+ describe "cli" do
7
+ it "pass args to Magellan::Cli::Command.start" do
8
+ expect(Magellan::Cli::Command).to receive(:start).with(%w[foo bar])
9
+ cli %w[foo bar]
10
+ end
11
+
12
+ it "parse args" do
13
+ expect(Magellan::Cli::Command).to receive(:start).with(%w[foo bar])
14
+ cli "foo bar"
15
+ end
16
+
17
+ it "parse args with space in quotation" do
18
+ expect(Magellan::Cli::Command).to receive(:start).with(["foo bar"])
19
+ cli '"foo bar"'
20
+ end
21
+
22
+ it "parse args with space escaped" do
23
+ expect(Magellan::Cli::Command).to receive(:start).with(["foo bar"])
24
+ cli 'foo\ bar'
25
+ end
26
+ end
27
+
28
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: magellan-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - akm2000
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-11 00:00:00.000000000 Z
11
+ date: 2015-01-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient
@@ -180,6 +180,7 @@ files:
180
180
  - lib/magellan/cli/resources/transaction_router.rb
181
181
  - lib/magellan/cli/resources/worker.rb
182
182
  - lib/magellan/cli/sample_launch_options.json
183
+ - lib/magellan/cli/script.rb
183
184
  - lib/magellan/cli/ssl.rb
184
185
  - lib/magellan/cli/version.rb
185
186
  - magellan-cli.gemspec
@@ -191,6 +192,7 @@ files:
191
192
  - spec/magellan/cli/resources/organization_spec.rb
192
193
  - spec/magellan/cli/resources/project_spec.rb
193
194
  - spec/magellan/cli/resources/team_spec.rb
195
+ - spec/magellan/cli/script_spec.rb
194
196
  - spec/magellan/cli_spec.rb
195
197
  - spec/spec_helper.rb
196
198
  homepage: ''
@@ -226,5 +228,6 @@ test_files:
226
228
  - spec/magellan/cli/resources/organization_spec.rb
227
229
  - spec/magellan/cli/resources/project_spec.rb
228
230
  - spec/magellan/cli/resources/team_spec.rb
231
+ - spec/magellan/cli/script_spec.rb
229
232
  - spec/magellan/cli_spec.rb
230
233
  - spec/spec_helper.rb