Class: Nin::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/nin/command.rb

Constant Summary collapse

COMMANDS_WITH_ARGS =
%w(a e c ac d)

Instance Method Summary collapse

Constructor Details

#initialize(command, args) ⇒ Command

Returns a new instance of Command.



5
6
7
8
9
10
11
# File 'lib/nin/command.rb', line 5

def initialize(command, args)
  @command = command
  @args    = args
  @todo    = Todo.new(YamlStore.new, collect_options)

  validate_args
end

Instance Method Details

#callObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/nin/command.rb', line 13

def call
  case @command
  when 'l', 'list'
    @todo.list
  when 'a', 'add'
    desc, date, tags = Parser.new(@args.join(' ')).call
    @todo.add(desc, date, tags)
  when 'e', 'edit'
    desc, date, tags = Parser.new(@args[1..-1].join(' ')).call
    @todo.edit(@args[0].to_i, desc, date, tags)
  when 'p', 'prioritize'
    @todo.prioritize(@args[0].to_i, @args[1].to_i)
  when 'c', 'complete'
    @todo.complete(*@args)
  when 'ac', 'archive'
    @todo.archive(*@args)
  when 'd', 'delete'
    @todo.delete(*@args)
  when 'gc', 'garbage'
    @todo.delete_archived
  when 's', 'analyze'
    @todo.analyze
  when 'i', 'repl'
    run_interactive_mode
  when 'o', 'open'
    system("`echo $EDITOR` #{@todo.store.file}")
  else
    puts "NAME:\n\tnin - a simple, full-featured command line todo app"
    puts "\nUSAGE:\n\tnin COMMAND [arguments...]"
    puts "\nCOMMANDS:"
    puts "\tl  | list          [a]        List all unarchived todos. Pass optional argument `a` to list all todos"
    puts "\ta  | add           desc       Add a todo. Prepend due date by a @. Prepend each tag by a \\#"
    puts "\te  | edit          id desc    Edit a todo. Prepend due date by a @. Prepend each tag by a \\#"
    puts "\tp  | prioritize    id step    Prioritize a todo by either a positive or negative step within its date group"
    puts "\tc  | complete      id(s)      Un/complete todo(s)"
    puts "\tac | archive       id(s)      Un/archive todo(s)"
    puts "\td  | delete        id(s)      Delete todo(s)"
    puts "\tgc | garbage                  Delete all archived todos. Resets item ids as a side effect"
    puts "\ts  | analyze                  Analyze tasks and print statistics"
    puts "\ti  | repl                     Open nin in REPL mode"
    puts "\to  | open                     Open todo file in $EDITOR"
  end
end