From 3e3084d82873432954a02b2030c975251622b366 Mon Sep 17 00:00:00 2001 From: Jonas Kaninda Date: Sun, 20 Oct 2024 06:36:59 +0200 Subject: [PATCH] chore: add command usage error --- cmd/backup.go | 3 ++- cmd/migrate.go | 2 +- cmd/restore.go | 2 +- utils/utils.go | 4 ++++ 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/cmd/backup.go b/cmd/backup.go index 8a576a2..19f8b11 100644 --- a/cmd/backup.go +++ b/cmd/backup.go @@ -20,7 +20,8 @@ var BackupCmd = &cobra.Command{ if len(args) == 0 { pkg.StartBackup(cmd) } else { - utils.Fatal("Error, no argument required") + utils.Fatal(`"backup" accepts no argument %q`, args) + } }, } diff --git a/cmd/migrate.go b/cmd/migrate.go index 12320a5..9201d00 100644 --- a/cmd/migrate.go +++ b/cmd/migrate.go @@ -19,7 +19,7 @@ var MigrateCmd = &cobra.Command{ if len(args) == 0 { pkg.StartMigration(cmd) } else { - utils.Fatal("Error, no argument required") + utils.Fatal(`"migrate" accepts no argument %q`, args) } diff --git a/cmd/restore.go b/cmd/restore.go index 5ea2193..270c50c 100644 --- a/cmd/restore.go +++ b/cmd/restore.go @@ -20,7 +20,7 @@ var RestoreCmd = &cobra.Command{ if len(args) == 0 { pkg.StartRestore(cmd) } else { - utils.Fatal("Error, no argument required") + utils.Fatal(`"restore" accepts no argument %q`, args) } diff --git a/utils/utils.go b/utils/utils.go index c93ee89..dffbbf4 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -213,3 +213,7 @@ func CronNextTime(cronExpr string) time.Time { //Info("The next scheduled time is: %v\n", next) return next } +func UsageErrorf(cmd *cobra.Command, message string, args ...interface{}) error { + msg := fmt.Sprintf(message, args...) + return fmt.Errorf("%s\nSee '%s -h' for help and examples", msg, cmd.CommandPath()) +}