acm 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +9 -9
- data/.travis.yml +4 -4
- data/Gemfile +4 -4
- data/LICENSE.txt +22 -22
- data/README.md +90 -82
- data/Rakefile +1 -1
- data/acm.gemspec +33 -33
- data/bin/console +14 -14
- data/bin/setup +7 -7
- data/exe/acm +151 -138
- data/lib/acm.rb +5 -5
- data/lib/acm/version.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: a1d783f18685313b4daa32039178794fae4f7f1b
|
4
|
+
data.tar.gz: 55a78e334626b6cdc19680db9e1b1e556a419a5f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f3e60c0f9242bcd9092bbca83204718cb5dd99f82b7b246aea03bd9d0da6baab4cf510422206a39e4eb97326affd3d191637aed8eef103e1c4a604344a23d1b3
|
7
|
+
data.tar.gz: f45ab544ad198a9a803e62fd2acd23b9760b098978519b945ecb276a5f7943f1737b2d7c4eea7faec06d091f9ac8653cc186495264849937f2f2d2ce1ab6b4c9
|
data/.gitignore
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
/.bundle/
|
2
|
-
/.yardoc
|
3
|
-
/Gemfile.lock
|
4
|
-
/_yardoc/
|
5
|
-
/coverage/
|
6
|
-
/doc/
|
7
|
-
/pkg/
|
8
|
-
/spec/reports/
|
9
|
-
/tmp/
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/Gemfile.lock
|
4
|
+
/_yardoc/
|
5
|
+
/coverage/
|
6
|
+
/doc/
|
7
|
+
/pkg/
|
8
|
+
/spec/reports/
|
9
|
+
/tmp/
|
data/.travis.yml
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
language: ruby
|
2
|
-
rvm:
|
3
|
-
- 2.1.7
|
4
|
-
before_install: gem install bundler -v 1.10.6
|
1
|
+
language: ruby
|
2
|
+
rvm:
|
3
|
+
- 2.1.7
|
4
|
+
before_install: gem install bundler -v 1.10.6
|
data/Gemfile
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
source 'https://rubygems.org'
|
2
|
-
|
3
|
-
# Specify your gem's dependencies in acm.gemspec
|
4
|
-
gemspec
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in acm.gemspec
|
4
|
+
gemspec
|
data/LICENSE.txt
CHANGED
@@ -1,22 +1,22 @@
|
|
1
|
-
Copyright (c) 2015 takatoh
|
2
|
-
|
3
|
-
MIT License
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
-
a copy of this software and associated documentation files (the
|
7
|
-
"Software"), to deal in the Software without restriction, including
|
8
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
-
permit persons to whom the Software is furnished to do so, subject to
|
11
|
-
the following conditions:
|
12
|
-
|
13
|
-
The above copyright notice and this permission notice shall be
|
14
|
-
included in all copies or substantial portions of the Software.
|
15
|
-
|
16
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
1
|
+
Copyright (c) 2015 takatoh
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
CHANGED
@@ -1,82 +1,90 @@
|
|
1
|
-
# acm
|
2
|
-
|
3
|
-
A simple account manager. This is NOT secure, excuse me ;p.
|
4
|
-
|
5
|
-
|
6
|
-
## Installation
|
7
|
-
|
8
|
-
Install it yourself as:
|
9
|
-
|
10
|
-
> gem install acm
|
11
|
-
|
12
|
-
## Usage
|
13
|
-
|
14
|
-
At first, init database:
|
15
|
-
|
16
|
-
> acm init
|
17
|
-
|
18
|
-
The database file is saved as "ENV['ACMDB']" or "ENV['HOME']/.accounts", in YAML.
|
19
|
-
Set location of database file to environment variable 'ACMDB', if you want.
|
20
|
-
|
21
|
-
Add account:
|
22
|
-
|
23
|
-
> acm add takatoh.m@gmail.com
|
24
|
-
(acm) Key? email
|
25
|
-
(acm) Value? takatoh.m@gmail.com
|
26
|
-
(acm) Key? password
|
27
|
-
(acm) Value? xxxxxxxx
|
28
|
-
(acm) Key? # Enter to exit.
|
29
|
-
|
30
|
-
Then added account to database.
|
31
|
-
|
32
|
-
List account(s):
|
33
|
-
|
34
|
-
> acm list
|
35
|
-
takatoh.m@gmail.com
|
36
|
-
|
37
|
-
Show details:
|
38
|
-
|
39
|
-
> acm show takatoh.m@gmail.com
|
40
|
-
Account: takatoh.m@gmail.com
|
41
|
-
email: takatoh.m@gmail.com
|
42
|
-
password: xxxxxxxx
|
43
|
-
|
44
|
-
Update value of key:
|
45
|
-
|
46
|
-
> acm update takatoh.m@gmail.com password yyyyyyyy
|
47
|
-
|
48
|
-
> acm show takatoh.m@gmail.com
|
49
|
-
Account: takatoh.m@gmail.com
|
50
|
-
email: takatoh.m@gmail.com
|
51
|
-
password: yyyyyyyy
|
52
|
-
|
53
|
-
Remove key and value:
|
54
|
-
|
55
|
-
> acm remove-key takatoh.m@gmail.com password
|
56
|
-
|
57
|
-
> acm show takatoh.m@gmail.com
|
58
|
-
Account: takatoh.m@gmail.com
|
59
|
-
email: takatoh.m@gmail.com
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
> acm
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
1
|
+
# acm
|
2
|
+
|
3
|
+
A simple account manager. This is NOT secure, excuse me ;p.
|
4
|
+
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
Install it yourself as:
|
9
|
+
|
10
|
+
> gem install acm
|
11
|
+
|
12
|
+
## Usage
|
13
|
+
|
14
|
+
At first, init database:
|
15
|
+
|
16
|
+
> acm init
|
17
|
+
|
18
|
+
The database file is saved as "ENV['ACMDB']" or "ENV['HOME']/.accounts", in YAML.
|
19
|
+
Set location of database file to environment variable 'ACMDB', if you want.
|
20
|
+
|
21
|
+
Add account:
|
22
|
+
|
23
|
+
> acm add takatoh.m@gmail.com
|
24
|
+
(acm) Key? email
|
25
|
+
(acm) Value? takatoh.m@gmail.com
|
26
|
+
(acm) Key? password
|
27
|
+
(acm) Value? xxxxxxxx
|
28
|
+
(acm) Key? # Enter to exit.
|
29
|
+
|
30
|
+
Then added account to database.
|
31
|
+
|
32
|
+
List account(s):
|
33
|
+
|
34
|
+
> acm list
|
35
|
+
takatoh.m@gmail.com
|
36
|
+
|
37
|
+
Show details:
|
38
|
+
|
39
|
+
> acm show takatoh.m@gmail.com
|
40
|
+
Account: takatoh.m@gmail.com
|
41
|
+
email: takatoh.m@gmail.com
|
42
|
+
password: xxxxxxxx
|
43
|
+
|
44
|
+
Update value of key:
|
45
|
+
|
46
|
+
> acm update takatoh.m@gmail.com password yyyyyyyy
|
47
|
+
|
48
|
+
> acm show takatoh.m@gmail.com
|
49
|
+
Account: takatoh.m@gmail.com
|
50
|
+
email: takatoh.m@gmail.com
|
51
|
+
password: yyyyyyyy
|
52
|
+
|
53
|
+
Remove key and value:
|
54
|
+
|
55
|
+
> acm remove-key takatoh.m@gmail.com password
|
56
|
+
|
57
|
+
> acm show takatoh.m@gmail.com
|
58
|
+
Account: takatoh.m@gmail.com
|
59
|
+
email: takatoh.m@gmail.com
|
60
|
+
|
61
|
+
Rename account:
|
62
|
+
|
63
|
+
> acm rename-account takatoh.m@gmail.com Gmail
|
64
|
+
|
65
|
+
> acm show Gmail
|
66
|
+
Account: Gmail
|
67
|
+
email: takatoh.m@gmail.com
|
68
|
+
|
69
|
+
And remove account:
|
70
|
+
|
71
|
+
> acm remove-account takatoh.m@gmail.com
|
72
|
+
Account: takatoh.m@gmail.com
|
73
|
+
email: takatoh.m@gmail.com
|
74
|
+
|
75
|
+
Are you sure?(y/n) y # Enter 'y' to remove.
|
76
|
+
|
77
|
+
> acm show takatoh.m@gmail.com
|
78
|
+
No such account: takatoh.m@gmail.com
|
79
|
+
|
80
|
+
|
81
|
+
## Development
|
82
|
+
|
83
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake false` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
84
|
+
|
85
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
86
|
+
|
87
|
+
## Contributing
|
88
|
+
|
89
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/takatoh/acm.
|
90
|
+
|
data/Rakefile
CHANGED
@@ -1 +1 @@
|
|
1
|
-
require "bundler/gem_tasks"
|
1
|
+
require "bundler/gem_tasks"
|
data/acm.gemspec
CHANGED
@@ -1,33 +1,33 @@
|
|
1
|
-
# coding: utf-8
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'acm/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |spec|
|
7
|
-
spec.name = "acm"
|
8
|
-
spec.version = Acm::VERSION
|
9
|
-
spec.authors = ["takatoh"]
|
10
|
-
spec.email = ["takatoh.m@gmail.com"]
|
11
|
-
|
12
|
-
spec.summary = %q{A simple account manager (NOT SECURE ;p).}
|
13
|
-
spec.description = %q{}
|
14
|
-
spec.homepage = "https://github.com/takatoh/acm"
|
15
|
-
spec.license = "MIT"
|
16
|
-
|
17
|
-
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
-
# delete this section to allow pushing this gem to any host.
|
19
|
-
# if spec.respond_to?(:metadata)
|
20
|
-
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
-
# else
|
22
|
-
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
-
# end
|
24
|
-
|
25
|
-
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
-
spec.bindir = "exe"
|
27
|
-
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
-
spec.require_paths = ["lib"]
|
29
|
-
|
30
|
-
spec.add_development_dependency "bundler", "~> 1.10"
|
31
|
-
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
-
spec.add_runtime_dependency "thor"
|
33
|
-
end
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'acm/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "acm"
|
8
|
+
spec.version = Acm::VERSION
|
9
|
+
spec.authors = ["takatoh"]
|
10
|
+
spec.email = ["takatoh.m@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{A simple account manager (NOT SECURE ;p).}
|
13
|
+
spec.description = %q{}
|
14
|
+
spec.homepage = "https://github.com/takatoh/acm"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
# if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
# else
|
22
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
# end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
31
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
32
|
+
spec.add_runtime_dependency "thor"
|
33
|
+
end
|
data/bin/console
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
require "bundler/setup"
|
4
|
-
require "acm"
|
5
|
-
|
6
|
-
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
-
# with your gem easier. You can also use a different console, if you like.
|
8
|
-
|
9
|
-
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
-
# require "pry"
|
11
|
-
# Pry.start
|
12
|
-
|
13
|
-
require "irb"
|
14
|
-
IRB.start
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "acm"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
CHANGED
@@ -1,7 +1,7 @@
|
|
1
|
-
#!/bin/bash
|
2
|
-
set -euo pipefail
|
3
|
-
IFS=$'\n\t'
|
4
|
-
|
5
|
-
bundle install
|
6
|
-
|
7
|
-
# Do any other automated setup that you need to do here
|
1
|
+
#!/bin/bash
|
2
|
+
set -euo pipefail
|
3
|
+
IFS=$'\n\t'
|
4
|
+
|
5
|
+
bundle install
|
6
|
+
|
7
|
+
# Do any other automated setup that you need to do here
|
data/exe/acm
CHANGED
@@ -1,138 +1,151 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# -*- encoding: utf-8 -*-
|
3
|
-
|
4
|
-
require 'acm'
|
5
|
-
require 'thor'
|
6
|
-
require 'yaml'
|
7
|
-
|
8
|
-
|
9
|
-
class MyCLI < Thor
|
10
|
-
|
11
|
-
DB_FILE = ENV['ACMDB'] || "#{ENV['HOME']}/.accounts"
|
12
|
-
|
13
|
-
desc "init", "Init database"
|
14
|
-
def init
|
15
|
-
if File.exist?(DB_FILE)
|
16
|
-
puts "Database file is already exist."
|
17
|
-
else
|
18
|
-
save_db([])
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
desc "add ACCOUNT", "Add ACCOUNT"
|
23
|
-
def add(account)
|
24
|
-
db = load_db
|
25
|
-
ac = lookup(account, db)
|
26
|
-
if ac
|
27
|
-
puts "Account #{account} is already exist."
|
28
|
-
exit 0
|
29
|
-
end
|
30
|
-
details = {}
|
31
|
-
ac = {
|
32
|
-
"account" => account,
|
33
|
-
"details" => details
|
34
|
-
}
|
35
|
-
while true
|
36
|
-
print "(acm) Key? "
|
37
|
-
key = STDIN.gets.chomp.strip
|
38
|
-
break if key.empty?
|
39
|
-
print "(acm) Value? "
|
40
|
-
value = STDIN.gets.chomp.strip
|
41
|
-
details[key] = value
|
42
|
-
end
|
43
|
-
db << ac
|
44
|
-
save_db(db)
|
45
|
-
end
|
46
|
-
|
47
|
-
desc "list", "List accounts"
|
48
|
-
def list
|
49
|
-
db = load_db
|
50
|
-
db.map{|a| a['account'] }.sort.each{|a| puts a }
|
51
|
-
end
|
52
|
-
|
53
|
-
desc "show ACCOUNT", "Show details of ACCOUNT"
|
54
|
-
def show(target)
|
55
|
-
db = load_db
|
56
|
-
account = lookup(target.encode("utf-8"), db)
|
57
|
-
if account
|
58
|
-
puts "Account: #{account['account']}"
|
59
|
-
account['details'].each do |key, val|
|
60
|
-
puts " #{key}: #{val}"
|
61
|
-
end
|
62
|
-
else
|
63
|
-
puts "No such account: #{target}"
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
desc "update ACCOUNT KEY VALUE", "Update value of KEY in ACCOUNT"
|
68
|
-
def update(target, key, value)
|
69
|
-
db = load_db
|
70
|
-
account = lookup(target.encode("utf-8"), db)
|
71
|
-
if account
|
72
|
-
account['details'][key] = value
|
73
|
-
save_db(db)
|
74
|
-
else
|
75
|
-
puts "No such account: #{target}"
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
desc "remove-key ACCOUNT KEY", "Remove KEY and value in ACCOUNT"
|
80
|
-
def remove_key(target, key)
|
81
|
-
db = load_db
|
82
|
-
account = lookup(target.encode("utf-8"), db)
|
83
|
-
if account
|
84
|
-
account['details'].delete(key)
|
85
|
-
save_db(db)
|
86
|
-
else
|
87
|
-
puts "No such account: #{target}"
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
desc "remove-account ACCOUNT", "Remove ACCOUNT"
|
92
|
-
def remove_account(target)
|
93
|
-
db = load_db
|
94
|
-
account = lookup(target.encode("utf-8"), db)
|
95
|
-
if account
|
96
|
-
puts "Account: #{target}"
|
97
|
-
account['details'].each do |k, v|
|
98
|
-
puts " #{k}: #{v}"
|
99
|
-
end
|
100
|
-
print "\nAre you sure?(y/n) "
|
101
|
-
if STDIN.gets.chomp.downcase == "y"
|
102
|
-
db.reject!{|a| a['account'] == target.encode("utf-8") }
|
103
|
-
save_db(db)
|
104
|
-
end
|
105
|
-
else
|
106
|
-
puts "No such account: #{target}"
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
desc "
|
111
|
-
def
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
def
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# -*- encoding: utf-8 -*-
|
3
|
+
|
4
|
+
require 'acm'
|
5
|
+
require 'thor'
|
6
|
+
require 'yaml'
|
7
|
+
|
8
|
+
|
9
|
+
class MyCLI < Thor
|
10
|
+
|
11
|
+
DB_FILE = ENV['ACMDB'] || "#{ENV['HOME']}/.accounts"
|
12
|
+
|
13
|
+
desc "init", "Init database"
|
14
|
+
def init
|
15
|
+
if File.exist?(DB_FILE)
|
16
|
+
puts "Database file is already exist."
|
17
|
+
else
|
18
|
+
save_db([])
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
desc "add ACCOUNT", "Add ACCOUNT"
|
23
|
+
def add(account)
|
24
|
+
db = load_db
|
25
|
+
ac = lookup(account, db)
|
26
|
+
if ac
|
27
|
+
puts "Account #{account} is already exist."
|
28
|
+
exit 0
|
29
|
+
end
|
30
|
+
details = {}
|
31
|
+
ac = {
|
32
|
+
"account" => account,
|
33
|
+
"details" => details
|
34
|
+
}
|
35
|
+
while true
|
36
|
+
print "(acm) Key? "
|
37
|
+
key = STDIN.gets.chomp.strip
|
38
|
+
break if key.empty?
|
39
|
+
print "(acm) Value? "
|
40
|
+
value = STDIN.gets.chomp.strip
|
41
|
+
details[key] = value
|
42
|
+
end
|
43
|
+
db << ac
|
44
|
+
save_db(db)
|
45
|
+
end
|
46
|
+
|
47
|
+
desc "list", "List accounts"
|
48
|
+
def list
|
49
|
+
db = load_db
|
50
|
+
db.map{|a| a['account'] }.sort.each{|a| puts a }
|
51
|
+
end
|
52
|
+
|
53
|
+
desc "show ACCOUNT", "Show details of ACCOUNT"
|
54
|
+
def show(target)
|
55
|
+
db = load_db
|
56
|
+
account = lookup(target.encode("utf-8"), db)
|
57
|
+
if account
|
58
|
+
puts "Account: #{account['account']}"
|
59
|
+
account['details'].each do |key, val|
|
60
|
+
puts " #{key}: #{val}"
|
61
|
+
end
|
62
|
+
else
|
63
|
+
puts "No such account: #{target}"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
desc "update ACCOUNT KEY VALUE", "Update value of KEY in ACCOUNT"
|
68
|
+
def update(target, key, value)
|
69
|
+
db = load_db
|
70
|
+
account = lookup(target.encode("utf-8"), db)
|
71
|
+
if account
|
72
|
+
account['details'][key] = value
|
73
|
+
save_db(db)
|
74
|
+
else
|
75
|
+
puts "No such account: #{target}"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
desc "remove-key ACCOUNT KEY", "Remove KEY and value in ACCOUNT"
|
80
|
+
def remove_key(target, key)
|
81
|
+
db = load_db
|
82
|
+
account = lookup(target.encode("utf-8"), db)
|
83
|
+
if account
|
84
|
+
account['details'].delete(key)
|
85
|
+
save_db(db)
|
86
|
+
else
|
87
|
+
puts "No such account: #{target}"
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
desc "remove-account ACCOUNT", "Remove ACCOUNT"
|
92
|
+
def remove_account(target)
|
93
|
+
db = load_db
|
94
|
+
account = lookup(target.encode("utf-8"), db)
|
95
|
+
if account
|
96
|
+
puts "Account: #{target}"
|
97
|
+
account['details'].each do |k, v|
|
98
|
+
puts " #{k}: #{v}"
|
99
|
+
end
|
100
|
+
print "\nAre you sure?(y/n) "
|
101
|
+
if STDIN.gets.chomp.downcase == "y"
|
102
|
+
db.reject!{|a| a['account'] == target.encode("utf-8") }
|
103
|
+
save_db(db)
|
104
|
+
end
|
105
|
+
else
|
106
|
+
puts "No such account: #{target}"
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
desc "rename-account OLD NEW", "Rename ACCOUNT"
|
111
|
+
def rename_account(old, new)
|
112
|
+
db = load_db
|
113
|
+
account = lookup(old.encode("utf-8"), db)
|
114
|
+
if account
|
115
|
+
puts "Account: #{old} -> #{new}"
|
116
|
+
account['account'] = new.encode("utf-8")
|
117
|
+
save_db(db)
|
118
|
+
else
|
119
|
+
puts "No such account: #{old}"
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
desc "version", "Show version and exit"
|
124
|
+
def version
|
125
|
+
puts "v#{Acm::VERSION}"
|
126
|
+
end
|
127
|
+
|
128
|
+
|
129
|
+
private
|
130
|
+
|
131
|
+
def load_db
|
132
|
+
begin
|
133
|
+
YAML.load_file(DB_FILE)
|
134
|
+
rescue
|
135
|
+
puts "Error: Not found database file."
|
136
|
+
exit(1)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
def lookup(target, db)
|
141
|
+
db.find{|a| a['account'] == target }
|
142
|
+
end
|
143
|
+
|
144
|
+
def save_db(db)
|
145
|
+
File.open(DB_FILE, "w"){|f| f.puts db.to_yaml }
|
146
|
+
end
|
147
|
+
|
148
|
+
end # of class MyCLI
|
149
|
+
|
150
|
+
|
151
|
+
MyCLI.start(ARGV)
|
data/lib/acm.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require "acm/version"
|
2
|
-
|
3
|
-
module Acm
|
4
|
-
# Your code goes here...
|
5
|
-
end
|
1
|
+
require "acm/version"
|
2
|
+
|
3
|
+
module Acm
|
4
|
+
# Your code goes here...
|
5
|
+
end
|
data/lib/acm/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module Acm
|
2
|
-
VERSION = "0.4.
|
3
|
-
end
|
1
|
+
module Acm
|
2
|
+
VERSION = "0.4.2"
|
3
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- takatoh
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|