Class: Plan::CLI
- Inherits:
-
Object
- Object
- Plan::CLI
- Defined in:
- lib/plan/cli.rb
Constant Summary collapse
- COMMAND_GLOSSARY =
{ 'create' => 'create a new item', 'list' => 'list items', 'finish' => 'mark an item finished', 'unfinish' => 'mark an item unfinished', 'cleanup' => 'remove finished items from view', 'help' => 'display a list of commands' }
Class Method Summary collapse
-
.cleanup(paths) ⇒ Object
Remove all finished items that are descendents.
-
.command(command, paths) ⇒ Object
decide what to do.
-
.create(paths) ⇒ Object
create a new todo.
-
.finish(paths) ⇒ Object
Mark a task or group of tasks as “finished”.
-
.help ⇒ Object
display a list of help.
-
.list(paths) ⇒ Object
list things at a certain depth.
- .run(args) ⇒ Object
-
.unfinish(paths) ⇒ Object
Mark a task or group of tasks as “unfinished”.
Class Method Details
.cleanup(paths) ⇒ Object
Remove all finished items that are descendents
54 55 56 57 58 59 60 |
# File 'lib/plan/cli.rb', line 54 def cleanup(paths) item = path_tree.descend(paths) item.cleanup save_path_tree # print what happened here print_depth item end |
.command(command, paths) ⇒ Object
decide what to do
21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/plan/cli.rb', line 21 def command(command, paths) # default is list return list([]) if command.nil? # choose other command case command when 'create' then create paths when 'list' then list paths when 'finish' then finish paths when 'unfinish' then unfinish paths when 'cleanup' then cleanup paths when 'help' then help else unknown_command(command) end end |
.create(paths) ⇒ Object
create a new todo
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/plan/cli.rb', line 98 def create(paths) if paths.empty? raise Plan::Advice.new('please provide something to create') end # descend to the right depth item = path_tree.descend(paths[0..-2]) # and then create if item.children.any? { |c| !c.hidden? && c.has_label?(paths[-1]) } raise Plan::Advice.new("duplicate entry at level: #{paths[-1]}") else item.children << Item.new(paths[-1]) save_path_tree # and say what happened print_depth item end end |
.finish(paths) ⇒ Object
Mark a task or group of tasks as “finished”
76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/plan/cli.rb', line 76 def finish(paths) if paths.empty? raise Plan::Advice.new('please drill down to a level to finish') end # descend and finish item = path_tree.descend(paths) item.finish! save_path_tree # print what happened here print_depth item end |
.help ⇒ Object
display a list of help
46 47 48 49 50 51 |
# File 'lib/plan/cli.rb', line 46 def help puts "plan #{Plan::VERSION} - john crepezzi - http://github.com/seejohnrun/plan" COMMAND_GLOSSARY.each do |cmd, description| puts "\e[0;33m#{cmd}\e[0m - #{description}" end end |
.list(paths) ⇒ Object
list things at a certain depth
89 90 91 92 93 94 95 |
# File 'lib/plan/cli.rb', line 89 def list(paths) item = path_tree.descend(paths) if item.visible_child_count == 0 raise Plan::Advice.new('no events here - create some with `plan create`') end print_depth item end |
.run(args) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/plan/cli.rb', line 10 def run(args) begin command args.first, args[1..-1] rescue Plan::Advice => e e.lines.each do |line| puts "\e[31m[uh-oh]\e[0m #{line}" end end end |
.unfinish(paths) ⇒ Object
Mark a task or group of tasks as “unfinished”
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/plan/cli.rb', line 63 def unfinish(paths) if paths.empty? raise Plan::Advice.new('please drill down to a level to unfinish') end # go to the right depth and unfinish item = path_tree.descend(paths) item.unfinish! save_path_tree # print what happened here print_depth item end |