summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormo <mo.khan@gmail.com>2018-06-13 15:44:11 -0600
committermo <mo.khan@gmail.com>2018-06-13 15:44:11 -0600
commitba175991cf05cc310586606788c2466acdac0ef1 (patch)
tree1b50580010deaa92c26364fe2780fc4653b5f96d
parentc34b96d44226af2fdf99ecb8dcfc4103506e033c (diff)
use thor.
-rw-r--r--README.md10
-rw-r--r--lib/trunk.rb2
-rw-r--r--lib/trunk/cli.rb77
-rw-r--r--trunk.gemspec1
4 files changed, 12 insertions, 78 deletions
diff --git a/README.md b/README.md
index f6f4c73..4fa58e6 100644
--- a/README.md
+++ b/README.md
@@ -25,14 +25,8 @@ Or install it yourself as:
TODO: Write usage instructions here
```bash
-$ trunk add --title=title --username=username --password=password
-$ trunk add <title> <username> - # read password from stdin
-$ trunk add
-$ title:>
-$ username:>
-$ password:>
-
-
+$ trunk add key password
+$ trunk add key - # read password from stdin
$ trunk show title
```
diff --git a/lib/trunk.rb b/lib/trunk.rb
index b902fcb..95c35c7 100644
--- a/lib/trunk.rb
+++ b/lib/trunk.rb
@@ -1,4 +1,4 @@
-require 'optparse'
+require 'thor'
require "trunk/cli"
require "trunk/storage"
diff --git a/lib/trunk/cli.rb b/lib/trunk/cli.rb
index 21d1c8c..a107ae4 100644
--- a/lib/trunk/cli.rb
+++ b/lib/trunk/cli.rb
@@ -1,77 +1,16 @@
module Trunk
- class AddCommand
- def matches?(command)
- "add" == command
+ class CLI < Thor
+ desc "add NAME PASSWORD", "add a key and password"
+ def add(key, password)
end
- def run(arguments)
- OptionParser.new do |parser|
- parser.banner = "Usage: trunk add [options]"
- parser.on_tail("-h", "--help", "print help") do
- puts parser
- end
- end.parse!(arguments)
-
- print "title:> "
- title = STDIN.gets
- print "username:> "
- username = STDIN.gets
- print "password:> "
- password = STDIN.gets
-
- puts [title, username, password].inspect
- end
- end
-
- class DefaultCommand
- def run(arguments)
- parser = OptionParser.new
- parser.banner = "Usage: trunk [options]"
- parser.on("-v", "--[no-]verbose", "run verbosely") do |v|
- end
- parser.on("--version", "show version") do |v|
- puts Trunk::VERSION
- end
- parser.on_tail("-h", "--help", "print help") do
- puts parser
- end
- parser.parse!(arguments)
- end
- end
-
- class CLI
- attr_reader :parser, :commands
-
- def initialize
- @commands = []
- @commands.push(AddCommand.new)
- end
-
- def command_for(arguments)
- if arguments.empty? || arguments[0]&.start_with?("-")
- DefaultCommand.new
- else
- commands.find { |x| x.matches?(arguments[0]) }
- end
- end
-
- def run(arguments)
- parser.banner = "Usage: trunk [options]"
- parser.on("-v", "--[no-]verbose", "run verbosely") do |v|
- options[:verbose] = v
- end
- parser.on("--version", "show version") do |v|
- puts Trunk::VERSION
- end
- parser.on_tail("-h", "--help", "print help") do
- puts parser
- end
- parser.parse!(arguments)
+ desc "show NAME", "print the password associated with a key"
+ def show(key)
end
- def self.start(arguments)
- cli = new
- cli.command_for(arguments).run(arguments)
+ desc "version", "print the version"
+ def version
+ say Trunk::VERSION
end
end
end
diff --git a/trunk.gemspec b/trunk.gemspec
index eec8131..bce1f40 100644
--- a/trunk.gemspec
+++ b/trunk.gemspec
@@ -21,6 +21,7 @@ Gem::Specification.new do |spec|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ["lib"]
+ spec.add_dependency "thor", "~> 0.20"
spec.add_development_dependency "bundler", "~> 1.16"
spec.add_development_dependency "rake", "~> 10.0"
spec.add_development_dependency "rspec", "~> 3.0"