summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormokha <mokha@cisco.com>2018-05-30 15:49:15 -0600
committermokha <mokha@cisco.com>2018-05-30 15:49:15 -0600
commit1d28a1c61210365be2cf551fe25d0b793edc0f67 (patch)
tree9dcf8fc0dec51330f2ad9a42851a9f89c33385bc
parent815ea5c74a68c18799435a5486a2d2b55c250e33 (diff)
hack on some ideas.
-rw-r--r--README.md12
-rw-r--r--lib/locker/cli.rb58
2 files changed, 66 insertions, 4 deletions
diff --git a/README.md b/README.md
index 0a2c420..a574b72 100644
--- a/README.md
+++ b/README.md
@@ -24,6 +24,18 @@ Or install it yourself as:
TODO: Write usage instructions here
+```bash
+$ locker add --title=title --username=username --password=password
+$ locker add <title> <username> - # read password from stdin
+$ locker add
+$ title:>
+$ username:>
+$ password:>
+
+
+$ locker show title
+```
+
## Development
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
diff --git a/lib/locker/cli.rb b/lib/locker/cli.rb
index b2b5a64..1b3cd43 100644
--- a/lib/locker/cli.rb
+++ b/lib/locker/cli.rb
@@ -1,9 +1,58 @@
module Locker
+ class AddCommand
+ def matches?(command)
+ "add" == command
+ end
+
+ def run(arguments)
+ OptionParser.new do |parser|
+ parser.banner = "Usage: locker 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: locker [options]"
+ parser.on("-v", "--[no-]verbose", "run verbosely") do |v|
+ end
+ parser.on("--version", "show version") do |v|
+ puts Locker::VERSION
+ end
+ parser.on_tail("-h", "--help", "print help") do
+ puts parser
+ end
+ parser.parse!(arguments)
+ end
+ end
+
class CLI
- attr_reader :parser
+ attr_reader :parser, :commands
- def initialize(parser)
- @parser = parser
+ 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)
@@ -21,7 +70,8 @@ module Locker
end
def self.start(arguments)
- new(OptionParser.new).run(arguments)
+ cli = new
+ cli.command_for(arguments).run(arguments)
end
end
end