From 548a1e8fcc23ec51ff1a24e9d16345ce2d2b556e Mon Sep 17 00:00:00 2001 From: nishiki Date: Sun, 8 Sep 2013 17:56:10 +0200 Subject: [PATCH] add interactive mode --- lib/Cli.rb | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ mpw | 5 +++-- 2 files changed, 53 insertions(+), 2 deletions(-) diff --git a/lib/Cli.rb b/lib/Cli.rb index 44fe163..ee3721f 100644 --- a/lib/Cli.rb +++ b/lib/Cli.rb @@ -226,4 +226,54 @@ class Cli end end + # Interactive mode + def interactive() + while true + command = ask(" ").split(' ') + + case command[0] + when 'display', 'show', 'd', 's' + if !command[1].nil? && !command[1].empty? + display(command[1], command[2]) + end + when 'add', 'a' + cli.add() + when 'update', 'u' + if !command[1].nil? && !command[1].empty? + update(command[1]) + end + when 'remove', 'delete', 'r', 'd' + if !command[1].nil? && !command[1].empty? + remove(command[1]) + end + when 'help', 'h', '?' + puts '# Help' + puts '# --------------------' + puts '# Display an item:' + puts '# display SEARCH' + puts '# show SEARCH' + puts '# s SEARCH' + puts '# d SEARCH' + puts '# Add an new item:' + puts '# add' + puts '# a' + puts '# Update an item:' + puts '# update ID' + puts '# u ID' + puts '# Remove an item:' + puts '# remove ID' + puts '# delete ID' + puts '# r ID' + puts '# d ID' + puts '# Quit the program:' + puts '# quit' + puts '# exit' + puts '# q' + when 'quit', 'exit', 'q' + break + end + + end + + end end diff --git a/mpw b/mpw index fdb7f8f..2f26b56 100755 --- a/mpw +++ b/mpw @@ -97,9 +97,10 @@ elsif not options[:export].nil? # Add a new item elsif not options[:import].nil? cli.import(options[:import], options[:force]) -else - puts "For help add option -h or --help" +# Interactive mode +else + cli.interactive end exit 0