From 0f09cc66b3412ea31a4230acfe63756cf99f296f Mon Sep 17 00:00:00 2001 From: jwnpoh Date: Sun, 4 Jul 2021 23:44:35 +0800 Subject: [PATCH 1/3] edit typos in revert help messages --- README.md | 12 ++++++------ cli/delete.go | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index adde5d0..4861420 100644 --- a/README.md +++ b/README.md @@ -411,7 +411,7 @@ timetrace edit project **Flags:** |Flag|Short|Description| |-|-|-| -|`--revert`|`-r`|Revert the project to it's state prior to the last edit.| +|`--revert`|`-r`|Revert the project to its state prior to the last edit.| **Example:** @@ -421,7 +421,7 @@ Edit a project called `make-coffee`: timetrace edit project make-coffee ``` -:fire: **New:** Restore the project to it's state prior to the last edit: +:fire: **New:** Restore the project to its state prior to the last edit: ``` timetrace edit project make-coffee --revert @@ -447,7 +447,7 @@ timetrace edit record {|latest} |-|-|-| |`--plus`|`-p`|Add the given duration to the record's end time, e.g. `--plus 1h 10m`| |`--minus`|`-m`|Subtract the given duration from the record's end time, e.g. `--minus 1h 10m`| -|`--revert`|`-r`|Revert the record to it's state prior to the last edit.| +|`--revert`|`-r`|Revert the record to its state prior to the last edit.| **Example:** @@ -463,7 +463,7 @@ Add 15 minutes to the end of the record created on May 1st, 3PM: timetrace edit record 2021-05-01-15-00 --plus 15m ``` -:fire: **New:** Restore the record to it's state prior to the last edit: +:fire: **New:** Restore the record to its state prior to the last edit: ``` timetrace edit record 2021-05-01-15-00 --revert @@ -498,7 +498,7 @@ Delete a project called `make-coffee`: timetrace delete project make-coffee ``` -:fire: **New:** Restore the project to it's pre-deletion state: +:fire: **New:** Restore the project to its pre-deletion state: ``` timetrace delete project make-coffee --revert @@ -531,7 +531,7 @@ Delete a record created on May 1st 2021, 3:00 PM: timetrace delete record 2021-05-01-15-00 ``` -:fire: **New:** Restore the record to it's pre-deletion state: +:fire: **New:** Restore the record to its pre-deletion state: ``` timetrace delete record 2021-05-01-15-00 --revert diff --git a/cli/delete.go b/cli/delete.go index 8abff63..c6a3e39 100644 --- a/cli/delete.go +++ b/cli/delete.go @@ -74,7 +74,7 @@ func deleteProjectCommand(t *core.Timetrace) *cobra.Command { }, } - deleteProject.PersistentFlags().BoolVarP(&options.Revert, "revert", "r", false, "Restores the record to it's state prior to the last 'delete' command.") + deleteProject.PersistentFlags().BoolVarP(&options.Revert, "revert", "r", false, "Restores the record to its state prior to the last 'delete' command.") return deleteProject } @@ -133,7 +133,7 @@ func deleteRecordCommand(t *core.Timetrace) *cobra.Command { }, } - deleteRecord.PersistentFlags().BoolVarP(&options.Revert, "revert", "r", false, "Restores the record to it's state prior to the last 'delete' command.") + deleteRecord.PersistentFlags().BoolVarP(&options.Revert, "revert", "r", false, "Restores the record to its state prior to the last 'delete' command.") return deleteRecord } From 2031eb5b5cb7e18eb7198aab42c2a206a14ef8cc Mon Sep 17 00:00:00 2001 From: jwnpoh Date: Mon, 5 Jul 2021 01:25:28 +0800 Subject: [PATCH 2/3] fix --revert flag to work properly for delete project --- cli/delete.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/cli/delete.go b/cli/delete.go index c6a3e39..8f031b2 100644 --- a/cli/delete.go +++ b/cli/delete.go @@ -55,9 +55,11 @@ func deleteProjectCommand(t *core.Timetrace) *cobra.Command { Key: key, } - if !askForConfirmation() { - out.Info("Record NOT deleted.") - return + if !confirmed { + if !askForConfirmation() { + out.Info("Project NOT deleted.") + return + } } if err := t.BackupProject(key); err != nil { From eb58c2060319474383710161097f5caf5ffa5593 Mon Sep 17 00:00:00 2001 From: jwnpoh Date: Mon, 5 Jul 2021 22:41:07 +0800 Subject: [PATCH 3/3] refactor for cleaner code --- cli/delete.go | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/cli/delete.go b/cli/delete.go index 8f031b2..836190a 100644 --- a/cli/delete.go +++ b/cli/delete.go @@ -42,12 +42,13 @@ func deleteProjectCommand(t *core.Timetrace) *cobra.Command { Args: cobra.ExactArgs(1), Run: func(cmd *cobra.Command, args []string) { key := args[0] + if options.Revert { if err := t.RevertProject(key); err != nil { out.Err("Failed to revert project: %s", err.Error()) - } else { - out.Info("Project backup restored successfully") + return } + out.Info("Project backup restored successfully") return } @@ -55,11 +56,9 @@ func deleteProjectCommand(t *core.Timetrace) *cobra.Command { Key: key, } - if !confirmed { - if !askForConfirmation() { - out.Info("Project NOT deleted.") - return - } + if !confirmed && !askForConfirmation() { + out.Info("Project NOT deleted.") + return } if err := t.BackupProject(key); err != nil { @@ -101,9 +100,9 @@ func deleteRecordCommand(t *core.Timetrace) *cobra.Command { if options.Revert { if err := t.RevertRecord(start); err != nil { out.Err("Failed to revert record: %s", err.Error()) - } else { - out.Info("Record backup restored successfully") + return } + out.Info("Record backup restored successfully") return } @@ -114,11 +113,10 @@ func deleteRecordCommand(t *core.Timetrace) *cobra.Command { } showRecord(record, t.Formatter()) - if !confirmed { - if !askForConfirmation() { - out.Info("Record NOT deleted.") - return - } + + if !confirmed && !askForConfirmation() { + out.Info("Record NOT deleted.") + return } if err := t.BackupRecord(start); err != nil {