Class: Taskmeister::Cli::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/taskmeister/cli/options.rb

Instance Method Summary collapse

Constructor Details

#initialize(stdout = STDOUT, kernel = Kernel) ⇒ Options

Returns a new instance of Options.



17
18
19
20
# File 'lib/taskmeister/cli/options.rb', line 17

def initialize(stdout = STDOUT, kernel = Kernel)
  @stdout = stdout
  @kernel = kernel
end

Instance Method Details

#parse(args) ⇒ Object



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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/taskmeister/cli/options.rb', line 22

def parse(args)
  options = default_options

  opt_parser = OptionParser.new do |opts|
    opts.program_name = "taskmeister"
    opts.banner = "Usage: taskmeister [options] TASK TEXT"

    opts.separator ""
    opts.separator "Specific options:"
    opts.separator "  If no options are specified TASK TEXT is added as a new task."
    opts.separator ""

    opts.on("-t", "--task-dir DIRECTORY",
            "The DIRECTORY where your task lists are stored. (Defaults to pwd)") do |dir|
      options.task_dir = Pathname.new(dir)
    end

    opts.on("-l", "--list NAME",
            "The task list to use.",
            "  Will use a list named after your current project directory if not supplied.",
            "  A project directory is found by walking up from the current directory and stopping if a .git or .hg directory is found.") do |list|
      options.list = Pathname.new(list)
    end

    opts.on("-d", "--done TASK_ID",
            "Finish a task") do |task_id|
      options.command = Commands::DONE
      options.task_id = task_id
    end

    opts.on("-s", "--show TASK_ID",
            "Show a task list item and its notes") do |task_id|
      options.command = Commands::SHOW
      options.task_id = task_id
    end

    opts.on("-e", "--edit [TASK_ID]",
            "Edit task list in Vim",
            "  Will search for a specific task if TASK_ID is provided") do |task_id|
      options.command = Commands::EDIT
      options.task_id = task_id
    end

    opts.on("-r", "--replace TASK_ID",
            "Replace a task description") do |task_id|
      options.command = Commands::REPLACE
      options.task_id = task_id
    end

    opts.separator ""
    opts.separator "Common options:"

    opts.on_tail("-h", "--help", "Show this message") do
      @stdout.puts opts
      @kernel.exit
    end

    opts.on_tail("--version", "Show version") do
      @stdout.puts Taskmeister::VERSION
      @kernel.exit
    end
  end

  task_text = opt_parser.parse!(args)

  options.task_text = task_text.join(" ") unless task_text.empty?

  # If there is task text and the default command hasn't been overwritten
  # by the user, make the command add
  if !task_text.empty? and options.command == Commands::LIST
    options.command = Commands::ADD
  end

  options
end