lib/timetrap/cli.rb in timetrap-1.6.1 vs lib/timetrap/cli.rb in timetrap-1.7.0

- old
+ new

@@ -21,11 +21,12 @@ -e, --end <date:qs> Include entries that start on this date or earlier * backend - Open an sqlite shell to the database. usage: t backend - * configure - Write out a config file. print path to config file. + * configure - Write out a YAML config file. Print path to config file. The + file may contain ERB. usage: t configure Currently supported options are: round_in_seconds: The duration of time to use for rounding with the -r flag database_file: The file path of the sqlite database @@ -36,12 +37,15 @@ SHEET to display all sheets. usage: t display [--ids] [--start DATE] [--end DATE] [--format FMT] [SHEET | all] -v, --ids Print database ids (for use with edit) -s, --start <date:qs> Include entries that start on this date or later -e, --end <date:qs> Include entries that start on this date or earlier - -f, --format <format> The output format. Currently supports ical, csv, and - text (default). + -f, --format <format> The output format. Valid built-in formats are + ical, csv, json, ids, and text (default). + Documentation on defining custom formats can be + found in the README included in this + distribution. * edit - Alter an entry's note, start, or end time. Defaults to the active entry. usage: t edit [--id ID] [--start TIME] [--end TIME] [--append] [NOTES] -i, --id <id:i> Alter entry with id <id> instead of the running entry -s, --start <time:qs> Change the start time to <time> @@ -104,11 +108,11 @@ args.parse arguments end def invoke args['-h'] ? puts(USAGE) : invoke_command_if_valid - rescue => e + rescue StandardError, LoadError => e raise e if args['--debug'] warn e.message exit 1 unless defined? TEST_MODE end @@ -238,24 +242,14 @@ warn "can't find #{victim} to kill", 'sheets:', *sheets end end def display - begin - fmt_klass = if args['-f'] - Timetrap::Formatters.const_get("#{args['-f'].classify}") - else - Timetrap::Formatters::Text - end - rescue - warn "Invalid format #{args['-f'].inspect} specified." - return - end entries = selected_entries.order(:start).all if entries == [] warn "No entries were selected to display." else - puts fmt_klass.new(entries).output + puts load_formatter(args['-f'] || Config['default_formatter']).new(entries).output end end def sheet sheet = unused_args