From b41b5e2be8929ebafeb956ca542b62d6b66d2fc5 Mon Sep 17 00:00:00 2001 From: jake Date: Wed, 26 Nov 2025 13:04:14 -0500 Subject: [PATCH] moving run command - run command is no longer attached to the 'command' subcmd - run is standalone --- cmd/command/add.go | 5 +++-- cmd/command/command.go | 7 ------- cmd/command/delete.go | 5 +++-- cmd/command/view.go | 5 +++-- cmd/destroy.go | 6 +++--- cmd/{command => }/run.go | 11 ++++++----- constants/error.go | 8 ++++++++ 7 files changed, 26 insertions(+), 21 deletions(-) rename cmd/{command => }/run.go (86%) create mode 100644 constants/error.go diff --git a/cmd/command/add.go b/cmd/command/add.go index 7a212fe..594f4bc 100644 --- a/cmd/command/add.go +++ b/cmd/command/add.go @@ -8,6 +8,7 @@ import ( "fmt" "os" + "code.jakeyoungdev.com/jake/mctl/constants" "code.jakeyoungdev.com/jake/mctl/database" "github.com/spf13/cobra" ) @@ -42,8 +43,8 @@ var addCmd = &cobra.Command{ err = db.SaveCmd(cfgname, cfgcmd) if err != nil { - if err.Error() == ErrInit { - fmt.Println(ErrInitRsp) + if err.Error() == constants.ErrInit { + fmt.Println(constants.ErrInitRsp) return } } diff --git a/cmd/command/command.go b/cmd/command/command.go index ac0e7f9..600466b 100644 --- a/cmd/command/command.go +++ b/cmd/command/command.go @@ -7,13 +7,6 @@ import ( "github.com/spf13/cobra" ) -const ( - //sqlite doesn't have an error type for this error, but we want to catch when this error is thrown - //and provide the proper response. It should not be treated as an error if the db isn't setup. - ErrInit = "sqlite3: SQL logic error: no such table: commands" - ErrInitRsp = "The 'init' command must be run before mctl can be used" -) - // CommandCmd is such a cool name lol var CommandCmd = &cobra.Command{ Use: "command", diff --git a/cmd/command/delete.go b/cmd/command/delete.go index 95fcfa8..6dc1d6e 100644 --- a/cmd/command/delete.go +++ b/cmd/command/delete.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" + "code.jakeyoungdev.com/jake/mctl/constants" "code.jakeyoungdev.com/jake/mctl/database" "github.com/spf13/cobra" ) @@ -23,8 +24,8 @@ var deleteCmd = &cobra.Command{ err = db.DeleteCmd(args[0]) if err != nil { - if err.Error() == ErrInit { - fmt.Println(ErrInitRsp) + if err.Error() == constants.ErrInit { + fmt.Println(constants.ErrInitRsp) return } } diff --git a/cmd/command/view.go b/cmd/command/view.go index 08c1257..851ec21 100644 --- a/cmd/command/view.go +++ b/cmd/command/view.go @@ -6,6 +6,7 @@ package command import ( "fmt" + "code.jakeyoungdev.com/jake/mctl/constants" "code.jakeyoungdev.com/jake/mctl/database" "github.com/spf13/cobra" ) @@ -22,8 +23,8 @@ var viewCmd = &cobra.Command{ ts, err := db.AllCmds() if err != nil { - if err.Error() == ErrInit { - fmt.Println(ErrInitRsp) + if err.Error() == constants.ErrInit { + fmt.Println(constants.ErrInitRsp) return } } diff --git a/cmd/destroy.go b/cmd/destroy.go index dc51872..dc4e52d 100644 --- a/cmd/destroy.go +++ b/cmd/destroy.go @@ -9,7 +9,7 @@ import ( "os" "strings" - "code.jakeyoungdev.com/jake/mctl/cmd/command" + "code.jakeyoungdev.com/jake/mctl/constants" "code.jakeyoungdev.com/jake/mctl/database" "github.com/spf13/cobra" ) @@ -32,8 +32,8 @@ var destroyCmd = &cobra.Command{ err = db.Destroy() if err != nil { - if err.Error() == command.ErrInit { - fmt.Println(command.ErrInitRsp) + if err.Error() == constants.ErrInit { + fmt.Println(constants.ErrInitRsp) return } } diff --git a/cmd/command/run.go b/cmd/run.go similarity index 86% rename from cmd/command/run.go rename to cmd/run.go index ee8778e..636441f 100644 --- a/cmd/command/run.go +++ b/cmd/run.go @@ -1,7 +1,7 @@ /* Copyright © 2025 Jake jake.young.dev@gmail.com */ -package command +package cmd import ( "errors" @@ -9,6 +9,7 @@ import ( "strings" "code.jakeyoungdev.com/jake/mctl/client" + "code.jakeyoungdev.com/jake/mctl/constants" "code.jakeyoungdev.com/jake/mctl/database" "github.com/spf13/cobra" ) @@ -19,7 +20,7 @@ var ( var runCmd = &cobra.Command{ Use: "run", - Example: "mctl command run -s args...", + Example: "mctl run -s args...", Short: "Runs a saved command on a server", Long: `Runs the named command with the provided args on the default/active server unless -s is specified`, SilenceUsage: true, @@ -34,8 +35,8 @@ var runCmd = &cobra.Command{ crun, err := db.Cmd(cname) if err != nil { - if err.Error() == ErrInit { - fmt.Println(ErrInitRsp) + if err.Error() == constants.ErrInit { + fmt.Println(constants.ErrInitRsp) return nil } return err @@ -76,5 +77,5 @@ var runCmd = &cobra.Command{ func init() { runCmd.Flags().StringVarP(&cfgserver, "server", "s", "", "server name") - CommandCmd.AddCommand(runCmd) + rootCmd.AddCommand(runCmd) } diff --git a/constants/error.go b/constants/error.go new file mode 100644 index 0000000..ef455c7 --- /dev/null +++ b/constants/error.go @@ -0,0 +1,8 @@ +package constants + +const ( + //sqlite doesn't have an error type for this error, but we want to catch when this error is thrown + //and provide the proper response. It should not be treated as an error if the db isn't setup. + ErrInit = "sqlite3: SQL logic error: no such table: commands" + ErrInitRsp = "The 'init' command must be run before mctl can be used" +)