From b922e26e51e92eaeee4798a0dd9ca527075032e5 Mon Sep 17 00:00:00 2001 From: Leah Neukirchen Date: Mon, 16 Oct 2017 16:49:07 +0200 Subject: use OptionParser --- notyet | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/notyet b/notyet index aacb9d6..f6deca0 100755 --- a/notyet +++ b/notyet @@ -1,11 +1,12 @@ #!/usr/bin/env ruby -# notyet [-a] [-c] [-e] [-f FILE] [FILTER] - a todo tracker +# notyet [-ace] [-f FILE] [FILTERS...] - a todo tracker # # notyet is in the public domain. # To the extent possible under law, Leah Neukirchen # has waived all copyright and related or neighboring rights to this work. # http://creativecommons.org/publicdomain/zero/1.0/ +require 'optionparser' require 'date' TODAY = Date.today @@ -180,17 +181,15 @@ files = [] filter = [] $show_all = $edit = false count_only = false -ARGV.each_with_index { |arg, i| - case arg - when "-a"; $show_all = true - when "-c"; count_only = true - when "-f"; files << ARGV.delete_at(i+1) - when "-e"; $edit = true - when /^-/; abort "Usage: notyet XXX" - else filter << arg - end -} +opt_parser = OptionParser.new { |opts| + opts.banner = "Usage: notyet [-ace] [-f FILE] [FILTERS...]" + opts.summary_width = 9 + opts.on("-a", "show all tasks (default: open tasks only)") { $show_all = true } + opts.on("-c", "only show total count") { count_only = true } + opts.on("-f FILE", "read tasks from FILE (default ~/.notyet)") { |f| files << f } + opts.on("-e", "edit tasks in vim") { $edit = true } +}.parse! ARGV files = [File.expand_path("~/.notyet")] if files.empty? @@ -209,7 +208,7 @@ files.each { |file| t.splat t.propagate t.sort -t.filter(filter) +t.filter(ARGV) if count_only puts "#{t.count("xX")}/#{t.count("-xX")}" -- cgit 1.4.1