Skip to content

Commit 855be24

Browse files
committed
Allow both from and to dates to be optional
- `from` defaults to today - `to` defaults to `from` (i.e. only create for 1 day)
1 parent f5032e1 commit 855be24

1 file changed

Lines changed: 12 additions & 12 deletions

File tree

exe/fa

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,12 @@ module Freeagent
3838
end
3939
end
4040

41-
desc 'create USER PROJECT TASK FROM TO', "Create timeslips"
41+
desc 'create USER PROJECT TASK [FROM [TO]]', "Create timeslips"
4242
method_option :hours, aliases: '-h', type: :numeric, default: 8, desc: "Number of hours per day"
4343
method_option :weekends, aliases: '-w', type: :boolean, default: false, desc: "Create timeslips on Saturdays and Sundays"
44-
def create user, project, task, from, to
45-
from = Date::parse from
46-
to = Date::parse to
44+
def create user, project, task, from = nil, to = nil
45+
from = from.nil? ? Date::today : Date::parse(from)
46+
to = to.nil? ? from : Date::parse(to)
4747
user = match :user, api.users, user, :first_name, :last_name, :email
4848
project = match :project, api.projects, project, :name
4949
task = match :task, api.tasks(project), task, :name
@@ -56,12 +56,12 @@ module Freeagent
5656
api.batch_create_timeslips timeslips
5757
end
5858

59-
desc 'fill USER PROJECT TASK FROM TO', 'Fill remaining hours with new timeslips'
59+
desc 'fill USER PROJECT TASK [FROM [TO]]', 'Fill remaining hours with new timeslips'
6060
method_option :hours, aliases: '-h', type: :numeric, default: 8, desc: "Number of hours per day"
6161
method_option :weekends, aliases: '-w', type: :boolean, default: false, desc: "Create timeslips on Saturdays and Sundays"
62-
def fill user, project, task, from, to
63-
from = Date::parse from
64-
to = Date::parse to
62+
def fill user, project, task, from = nil, to = nil
63+
from = from.nil? ? Date::today : Date::parse(from)
64+
to = to.nil? ? from : Date::parse(to)
6565
user = match :user, api.users, user, :first_name, :last_name, :email
6666
project = match :project, api.projects, project, :name
6767
task = match :task, api.tasks(project), task, :name
@@ -83,10 +83,10 @@ module Freeagent
8383
api.batch_create_timeslips timeslips
8484
end
8585

86-
desc 'delete USER PROJECT TASK FROM TO', 'Delete timeslips'
87-
def delete user, project, task, from, to
88-
from = Date::parse from
89-
to = Date::parse to
86+
desc 'delete USER PROJECT TASK [FROM [TO]]', 'Delete timeslips'
87+
def delete user, project, task, from = nil, to = nil
88+
from = from.nil? ? Date::today : Date::parse(from)
89+
to = to.nil? ? from : Date::parse(to)
9090
user = match :user, api.users, user, :first_name, :last_name, :email
9191
project = match :project, api.projects, project, :name
9292
task = match :task, api.tasks(project), task, :name

0 commit comments

Comments
 (0)