lib/timetrap/cli.rb in timetrap-1.8.1 vs lib/timetrap/cli.rb in timetrap-1.8.2
- old
+ new
@@ -30,10 +30,11 @@
round_in_seconds: The duration of time to use for rounding with
the -r flag
database_file: The file path of the sqlite database
append_notes_delimiter: delimiter used when appending notes via
t edit --append
+ default_command: The default command to run when calling t.
* display - Display the current timesheet or a specific. Pass `all' as SHEET
to display all unarchived sheets or `full' to display archived and
unarchived sheets.
usage: t display [--ids] [--start DATE] [--end DATE] [--format FMT] [SHEET | all | full]
@@ -138,16 +139,23 @@
'format' => 'display'
}
end
def invoke_command_if_valid
+ if args.unused.empty? && Timetrap::Config['default_command']
+ self.args = Getopt::Declare.new(USAGE.dup, Timetrap::Config['default_command'])
+ end
command = args.unused.shift
set_global_options
case (valid = commands.select{|name| name =~ %r|^#{command}|}).size
when 1 then send valid[0]
else
handle_invalid_command(command)
end
+ end
+
+ def valid_command(command)
+ return commands.include?(command)
end
def handle_invalid_command(command)
if !command
puts USAGE