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
# File 'lib/nin/command.rb', line 13

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