diff --git a/pkg/backy/backy.go b/pkg/backy/backy.go index 6ad21ed..d33a411 100644 --- a/pkg/backy/backy.go +++ b/pkg/backy/backy.go @@ -54,7 +54,7 @@ func (command *Command) RunCmd(cmdCtxLogger zerolog.Logger, opts *ConfigOpts) ([ ArgsStr += fmt.Sprintf(" %s", v) } - if command.Type == User { + if command.Type == UserCT { if command.UserOperation == "password" { cmdCtxLogger.Info().Str("password", command.UserPassword).Msg("user password to be updated") } @@ -68,7 +68,7 @@ func (command *Command) RunCmd(cmdCtxLogger zerolog.Logger, opts *ConfigOpts) ([ } else { // Handle package operations - if command.Type == Package && command.PackageOperation == "checkVersion" { + if command.Type == PackageCT && command.PackageOperation == "checkVersion" { cmdCtxLogger.Info().Str("package", command.PackageName).Msg("Checking package versions") // Execute the package version command @@ -85,7 +85,7 @@ func (command *Command) RunCmd(cmdCtxLogger zerolog.Logger, opts *ConfigOpts) ([ } var localCMD *exec.Cmd - if command.Type == RemoteScript { + if command.Type == RemoteScriptCT { script, err := command.Fetcher.Fetch(command.Cmd) if err != nil { return nil, err @@ -156,7 +156,7 @@ func (command *Command) RunCmd(cmdCtxLogger zerolog.Logger, opts *ConfigOpts) ([ cmdCtxLogger.Info().Str("Command", fmt.Sprintf("Running command %s on local machine", command.Name)).Send() // execute package commands in a shell - if command.Type == Package { + if command.Type == PackageCT { cmdCtxLogger.Info().Str("package", command.PackageName).Msg("Executing package command") ArgsStr = fmt.Sprintf("%s %s", command.Cmd, ArgsStr) localCMD = exec.Command("/bin/sh", "-c", ArgsStr) diff --git a/pkg/backy/commandtype_enumer.go b/pkg/backy/commandtype_enumer.go index d27e3fe..e5b8f7b 100644 --- a/pkg/backy/commandtype_enumer.go +++ b/pkg/backy/commandtype_enumer.go @@ -25,29 +25,29 @@ func (i CommandType) String() string { // Re-run the stringer command to generate them again. func _CommandTypeNoOp() { var x [1]struct{} - _ = x[Default-(0)] - _ = x[Script-(1)] - _ = x[ScriptFile-(2)] - _ = x[RemoteScript-(3)] - _ = x[Package-(4)] - _ = x[User-(5)] + _ = x[DefaultCT-(0)] + _ = x[ScriptCT-(1)] + _ = x[ScriptFileCT-(2)] + _ = x[RemoteScriptCT-(3)] + _ = x[PackageCT-(4)] + _ = x[UserCT-(5)] } -var _CommandTypeValues = []CommandType{Default, Script, ScriptFile, RemoteScript, Package, User} +var _CommandTypeValues = []CommandType{DefaultCT, ScriptCT, ScriptFileCT, RemoteScriptCT, PackageCT, UserCT} var _CommandTypeNameToValueMap = map[string]CommandType{ - _CommandTypeName[0:0]: Default, - _CommandTypeLowerName[0:0]: Default, - _CommandTypeName[0:6]: Script, - _CommandTypeLowerName[0:6]: Script, - _CommandTypeName[6:16]: ScriptFile, - _CommandTypeLowerName[6:16]: ScriptFile, - _CommandTypeName[16:28]: RemoteScript, - _CommandTypeLowerName[16:28]: RemoteScript, - _CommandTypeName[28:35]: Package, - _CommandTypeLowerName[28:35]: Package, - _CommandTypeName[35:39]: User, - _CommandTypeLowerName[35:39]: User, + _CommandTypeName[0:0]: DefaultCT, + _CommandTypeLowerName[0:0]: DefaultCT, + _CommandTypeName[0:6]: ScriptCT, + _CommandTypeLowerName[0:6]: ScriptCT, + _CommandTypeName[6:16]: ScriptFileCT, + _CommandTypeLowerName[6:16]: ScriptFileCT, + _CommandTypeName[16:28]: RemoteScriptCT, + _CommandTypeLowerName[16:28]: RemoteScriptCT, + _CommandTypeName[28:35]: PackageCT, + _CommandTypeLowerName[28:35]: PackageCT, + _CommandTypeName[35:39]: UserCT, + _CommandTypeLowerName[35:39]: UserCT, } var _CommandTypeNames = []string{ diff --git a/pkg/backy/config.go b/pkg/backy/config.go index 605b72b..924c1c1 100644 --- a/pkg/backy/config.go +++ b/pkg/backy/config.go @@ -578,7 +578,7 @@ func processCmds(opts *ConfigOpts) error { } // Parse package commands - if cmd.Type == Package { + if cmd.Type == PackageCT { if cmd.PackageManager == "" { return fmt.Errorf("package manager is required for package command %s", cmd.PackageName) } @@ -603,7 +603,7 @@ func processCmds(opts *ConfigOpts) error { } // Parse user commands - if cmd.Type == User { + if cmd.Type == UserCT { if cmd.Username == "" { return fmt.Errorf("username is required for user command %s", cmd.Name) } @@ -630,7 +630,7 @@ func processCmds(opts *ConfigOpts) error { } - if cmd.Type == RemoteScript { + if cmd.Type == RemoteScriptCT { var fetchErr error if !isRemoteURL(cmd.Cmd) { return fmt.Errorf("remoteScript command %s must be a remote resource", cmdName) diff --git a/pkg/backy/ssh.go b/pkg/backy/ssh.go index f711e26..7a58b58 100644 --- a/pkg/backy/ssh.go +++ b/pkg/backy/ssh.go @@ -531,13 +531,13 @@ func (command *Command) RunCmdSSH(cmdCtxLogger zerolog.Logger, opts *ConfigOpts) // Handle command execution based on type switch command.Type { - case Script: + case ScriptCT: return command.runScript(commandSession, cmdCtxLogger, &cmdOutBuf) - case RemoteScript: + case RemoteScriptCT: return command.runRemoteScript(commandSession, cmdCtxLogger, &cmdOutBuf) - case ScriptFile: + case ScriptFileCT: return command.runScriptFile(commandSession, cmdCtxLogger, &cmdOutBuf) - case Package: + case PackageCT: if command.PackageOperation == "checkVersion" { commandSession.Stderr = nil // Execute the package version command remotely diff --git a/pkg/backy/types.go b/pkg/backy/types.go index b49e23c..e26af8d 100644 --- a/pkg/backy/types.go +++ b/pkg/backy/types.go @@ -299,10 +299,10 @@ type ( //go:generate go run github.com/dmarkham/enumer -linecomment -yaml -text -json -type=CommandType const ( - Default CommandType = iota // - Script // script - ScriptFile // scriptFile - RemoteScript // remoteScript - Package // package - User // user + DefaultCT CommandType = iota // + ScriptCT // script + ScriptFileCT // scriptFile + RemoteScriptCT // remoteScript + PackageCT // package + UserCT // user ) diff --git a/pkg/backy/utils.go b/pkg/backy/utils.go index 3e76c22..f89aa1d 100644 --- a/pkg/backy/utils.go +++ b/pkg/backy/utils.go @@ -256,7 +256,7 @@ func expandEnvVars(backyEnv map[string]string, envVars []string) { // Returns the modified Command with the package- or userManager command as Cmd and the package- or userOperation as args, plus any additional Args func getCommandTypeAndSetCommandInfo(command *Command) *Command { - if command.Type == Package && !command.packageCmdSet { + if command.Type == PackageCT && !command.packageCmdSet { command.packageCmdSet = true switch command.PackageOperation { case "install": @@ -270,7 +270,7 @@ func getCommandTypeAndSetCommandInfo(command *Command) *Command { } } - if command.Type == User && !command.userCmdSet { + if command.Type == UserCT && !command.userCmdSet { command.userCmdSet = true switch command.UserOperation { case "add":