magellan-cli 0.4.0 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/Gemfile.lock +11 -3
- data/lib/magellan/cli/command.rb +1 -0
- data/lib/magellan/cli/file_access.rb +25 -4
- data/lib/magellan/cli/locales/en.yml +15 -0
- data/lib/magellan/cli/locales/ja.yml +13 -0
- data/lib/magellan/cli/version.rb +1 -1
- data/spec/magellan/cli/file_access_spec.rb +30 -0
- data/spec/magellan/cli/login_spec.rb +1 -1
- data/spec/spec_helper.rb +10 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b8130a0c4a91225ff9bead118ba994a4be21351
|
4
|
+
data.tar.gz: eb512a27d356f8657a4e91664e4cbac15cb642a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0f7930935c96927195eafc9ec7a93eb6d1e27bd3af2eb7984fe44e8963812a1d25a9ad64baa979a74dc9c4416c3cdb71da83f558c26c90f4436fd535d5cc1e8a
|
7
|
+
data.tar.gz: d79d097a744166423b27833e4eaf92b5cec812d47d0e9f103c83525d32a822ba3791c6064b23cfaf976dec5d88d4ed27e297fb7342c5d3e951419fef18ac4658
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
magellan-cli (0.4.
|
4
|
+
magellan-cli (0.4.1)
|
5
5
|
activesupport (~> 4.1.4)
|
6
6
|
groovenauts-thor
|
7
7
|
httpclient (~> 2.5)
|
@@ -12,7 +12,7 @@ PATH
|
|
12
12
|
GEM
|
13
13
|
remote: https://rubygems.org/
|
14
14
|
specs:
|
15
|
-
activesupport (4.1.
|
15
|
+
activesupport (4.1.9)
|
16
16
|
i18n (~> 0.6, >= 0.6.9)
|
17
17
|
json (~> 1.7, >= 1.7.7)
|
18
18
|
minitest (~> 5.1)
|
@@ -28,13 +28,15 @@ GEM
|
|
28
28
|
debug_inspector (0.0.2)
|
29
29
|
debugger-linecache (1.2.0)
|
30
30
|
diff-lcs (1.2.5)
|
31
|
+
docile (1.1.5)
|
31
32
|
groovenauts-thor (0.19.1)
|
32
33
|
httpclient (2.6.0.1)
|
33
34
|
i18n (0.7.0)
|
34
35
|
json (1.8.2)
|
35
36
|
method_source (0.8.2)
|
36
37
|
mini_portile (0.6.2)
|
37
|
-
minitest (5.5.
|
38
|
+
minitest (5.5.1)
|
39
|
+
multi_json (1.10.1)
|
38
40
|
nokogiri (1.6.5)
|
39
41
|
mini_portile (~> 0.6.0)
|
40
42
|
pry (0.9.12.6)
|
@@ -60,6 +62,11 @@ GEM
|
|
60
62
|
rspec-mocks (3.0.4)
|
61
63
|
rspec-support (~> 3.0.0)
|
62
64
|
rspec-support (3.0.4)
|
65
|
+
simplecov (0.9.1)
|
66
|
+
docile (~> 1.1.0)
|
67
|
+
multi_json (~> 1.0)
|
68
|
+
simplecov-html (~> 0.8.0)
|
69
|
+
simplecov-html (0.8.0)
|
63
70
|
slop (3.5.0)
|
64
71
|
text-table (1.2.3)
|
65
72
|
thread_safe (0.3.4)
|
@@ -77,3 +84,4 @@ DEPENDENCIES
|
|
77
84
|
pry-stack_explorer
|
78
85
|
rake (~> 10.0)
|
79
86
|
rspec
|
87
|
+
simplecov
|
data/lib/magellan/cli/command.rb
CHANGED
@@ -11,6 +11,7 @@ module Magellan
|
|
11
11
|
class << self
|
12
12
|
# override Thor::Base.start method
|
13
13
|
def start(given_args = ARGV, config = {})
|
14
|
+
Magellan::Cli::FileAccess.ensure_config_dir
|
14
15
|
# class_options verbose and version are defined in Magellan::Cli::Base
|
15
16
|
if (ARGV == ["-v"] || ARGV == ["--version"])
|
16
17
|
log_info(File.basename($0) << " " << Magellan::Cli::VERSION)
|
@@ -1,5 +1,7 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
2
|
|
3
|
+
require "fileutils"
|
4
|
+
|
3
5
|
module Magellan
|
4
6
|
module Cli
|
5
7
|
module FileAccess
|
@@ -7,16 +9,31 @@ module Magellan
|
|
7
9
|
class NotSelected < StandardError
|
8
10
|
end
|
9
11
|
|
10
|
-
|
12
|
+
DEFAULT_SELECTION_FILENAME = File.expand_path("~/.config/magellan/magellan-cli")
|
11
13
|
|
12
14
|
module_function
|
13
15
|
|
16
|
+
def selection_filename
|
17
|
+
ENV["MAGELLAN_CLI_CONFIG_FILE"] || DEFAULT_SELECTION_FILENAME
|
18
|
+
end
|
19
|
+
|
14
20
|
def remove_selection_file
|
15
|
-
File.exist?(
|
21
|
+
File.exist?(selection_filename) && File.delete(selection_filename)
|
16
22
|
end
|
17
23
|
|
18
24
|
def load_selections
|
19
|
-
File.readable?(
|
25
|
+
File.readable?(selection_filename) ? YAML.load_file(selection_filename) : {}
|
26
|
+
end
|
27
|
+
|
28
|
+
# check if ~/.config/magellan directory exists.
|
29
|
+
def ensure_config_dir
|
30
|
+
return if ENV["MAGELLAN_CLI_CONFIG_FILE"]
|
31
|
+
default_dir = File.dirname(DEFAULT_SELECTION_FILENAME)
|
32
|
+
unless File.directory?(default_dir)
|
33
|
+
# This is notification message to be displayed at the first time magellan-cli invoked.
|
34
|
+
puts I18n.t(:config_file, scope: [:base, :notification])
|
35
|
+
FileUtils.mkdir_p(default_dir)
|
36
|
+
end
|
20
37
|
end
|
21
38
|
|
22
39
|
# @param [Class|String] obj Resource class or resource name
|
@@ -37,7 +54,11 @@ module Magellan
|
|
37
54
|
sel = load_selections
|
38
55
|
sel.update(hash) if hash
|
39
56
|
yield(sel) if block_given?
|
40
|
-
|
57
|
+
filepath = selection_filename
|
58
|
+
unless File.exist?(File.dirname(filepath))
|
59
|
+
FileUtils.mkdir_p(File.dirname(filepath))
|
60
|
+
end
|
61
|
+
open(filepath, "w") do |f|
|
41
62
|
f.chmod 0600
|
42
63
|
YAML.dump(sel, f)
|
43
64
|
end
|
@@ -1,5 +1,20 @@
|
|
1
1
|
en:
|
2
2
|
base:
|
3
|
+
notification:
|
4
|
+
config_file: |
|
5
|
+
******* magellan-cli configuration file ******
|
6
|
+
magellan-cli stores login information, resources selection information into
|
7
|
+
a configuration file. The file path of the configuration file is usually
|
8
|
+
${HOME}/.config/magellan/magellan-cli
|
9
|
+
You can specify your own configuration file path by setting environment variable
|
10
|
+
MAGELLAN_CLI_CONFIG_FILE.
|
11
|
+
|
12
|
+
!! migration from 0.4.0 and before !!
|
13
|
+
magellan-cli 0.4.0 and before saves configuration file into `.magellan-cli'
|
14
|
+
in current directory.
|
15
|
+
To migrate onfigurations from magellan-0.4.0 and before, move `.magellan-cli'
|
16
|
+
file in the working directory to ${HOME}/.config/magellan/magellan-cli or
|
17
|
+
${MAGELLAN_CLI_CONFIG_FILE}.
|
3
18
|
cmd:
|
4
19
|
help: "Describe available commands or one specific command"
|
5
20
|
command:
|
@@ -1,5 +1,18 @@
|
|
1
1
|
ja:
|
2
2
|
base:
|
3
|
+
notification:
|
4
|
+
config_file: |
|
5
|
+
******* magellan-cli の設定ファイル ******
|
6
|
+
magellan-cli はログイン情報、リソースの選択状態などの情報を設定ファイルに保存します。
|
7
|
+
設定ファイルのファイルパスは ${HOME}/.config/magellan/magellan-cli が用いられます。
|
8
|
+
設定ファイルのファイルパスは環境変数 MAGELLAN_CLI_CONFIG_FILE で指定可能です。
|
9
|
+
|
10
|
+
!! 0.4.0 からの移行について !!
|
11
|
+
magellan-cli 0.4.0 までは設定ファイルとしてカレントディレクトリに .magellan-cli ファイルを
|
12
|
+
作成していました。
|
13
|
+
0.4.0 以前のバージョンからの移行のためには、作業ディレクトリ内の .magellan-cli ファイルを
|
14
|
+
${HOME}/.config/magellan/magellan-cli もしくは環境変数 MAGELLAN_CLI_CONFIG_FILE で指定する
|
15
|
+
パスへ移動してください。
|
3
16
|
cmd:
|
4
17
|
help: "利用可能なコマンドの一覧か特定のコマンドの説明を表示します"
|
5
18
|
command:
|
data/lib/magellan/cli/version.rb
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe Magellan::Cli::FileAccess do
|
5
|
+
describe :ensure_config_dir do
|
6
|
+
before do
|
7
|
+
@stdout = StringIO.new
|
8
|
+
@stdout_orig, $stdout = $stdout, @stdout
|
9
|
+
expect(File).to receive(:directory?).with(File.expand_path("~/.config/magellan")).and_return(false)
|
10
|
+
expect(FileUtils).to receive(:mkdir_p).with(File.expand_path("~/.config/magellan"))
|
11
|
+
@magellan_cli_config_file_orig, ENV["MAGELLAN_CLI_CONFIG_FILE"] = ENV["MAGELLAN_CLI_CONFIG_FILE"], nil
|
12
|
+
end
|
13
|
+
after do
|
14
|
+
$stdout = @stdout_orig
|
15
|
+
ENV["MAGELLAN_CLI_CONFIG_FILE"] = @magellan_cli_config_file_orig
|
16
|
+
end
|
17
|
+
it "print notification message" do
|
18
|
+
Magellan::Cli::FileAccess.ensure_config_dir
|
19
|
+
[
|
20
|
+
%r{\.config/magellan/magellan-cli },
|
21
|
+
%r{configuration file}i,
|
22
|
+
%r{environment variable}i,
|
23
|
+
%r{MAGELLAN_CLI_CONFIG_FILE},
|
24
|
+
%r{migration}i,
|
25
|
+
].each do |re|
|
26
|
+
expect(@stdout.string).to match(re)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -10,7 +10,7 @@ describe Magellan::Cli::Login do
|
|
10
10
|
|
11
11
|
before do
|
12
12
|
allow(File).to receive(:readable?).and_return(true)
|
13
|
-
allow(YAML).to receive(:load_file).with("
|
13
|
+
allow(YAML).to receive(:load_file).with(ENV["MAGELLAN_CLI_CONFIG_FILE"]).and_return({"login" => {"email" => email, "password" => password} })
|
14
14
|
end
|
15
15
|
|
16
16
|
context :production do
|
data/spec/spec_helper.rb
CHANGED
@@ -1,2 +1,12 @@
|
|
1
|
+
require "pry"
|
2
|
+
|
3
|
+
if ENV["COVERAGE"] =~ /true|yes|on|1/i
|
4
|
+
require "simplecov"
|
5
|
+
SimpleCov.start :rails
|
6
|
+
end
|
7
|
+
|
1
8
|
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
2
9
|
require 'magellan/cli'
|
10
|
+
|
11
|
+
ENV["MAGELLAN_CLI_CONFIG_FILE"] = File.expand_path("../.magellan-cli", __FILE__)
|
12
|
+
I18n.locale = :en
|
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.4.
|
4
|
+
version: 0.4.1
|
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
|
+
date: 2015-01-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httpclient
|
@@ -186,6 +186,7 @@ files:
|
|
186
186
|
- magellan-cli.gemspec
|
187
187
|
- spec/magellan/cli/Magellan.yml
|
188
188
|
- spec/magellan/cli/command_spec.rb
|
189
|
+
- spec/magellan/cli/file_access_spec.rb
|
189
190
|
- spec/magellan/cli/login_page.html
|
190
191
|
- spec/magellan/cli/login_spec.rb
|
191
192
|
- spec/magellan/cli/resources/client_version_spec.rb
|
@@ -222,6 +223,7 @@ summary: commandline tools for magellanic cloud service.
|
|
222
223
|
test_files:
|
223
224
|
- spec/magellan/cli/Magellan.yml
|
224
225
|
- spec/magellan/cli/command_spec.rb
|
226
|
+
- spec/magellan/cli/file_access_spec.rb
|
225
227
|
- spec/magellan/cli/login_page.html
|
226
228
|
- spec/magellan/cli/login_spec.rb
|
227
229
|
- spec/magellan/cli/resources/client_version_spec.rb
|