[WIP] v0.7.0 getCommandType first
Some checks failed
ci/woodpecker/push/go-lint Pipeline failed

This commit is contained in:
2025-01-15 23:33:55 -06:00
parent a664edaed7
commit 8c633fd4b2
5 changed files with 12 additions and 15 deletions

View File

@@ -45,12 +45,14 @@ func (command *Command) RunCmd(cmdCtxLogger zerolog.Logger, opts *ConfigOpts) ([
}
)
// Get the command type
// This must be done before concatenating the arguments
command = getCommandType(command)
for _, v := range command.Args {
ArgsStr += fmt.Sprintf(" %s", v)
}
command = getCommandType(command)
if command.Type == "user" {
if command.UserOperation == "password" {
cmdCtxLogger.Info().Str("password", command.UserPassword).Msg("user password to be updated")
@@ -60,7 +62,6 @@ func (command *Command) RunCmd(cmdCtxLogger zerolog.Logger, opts *ConfigOpts) ([
var errSSH error
// is host defined
if command.Host != nil {
print("host is defined")
outputArr, errSSH = command.RunCmdSSH(cmdCtxLogger, opts)
if errSSH != nil {
return outputArr, errSSH
@@ -78,7 +79,7 @@ func (command *Command) RunCmd(cmdCtxLogger zerolog.Logger, opts *ConfigOpts) ([
cmd.Stderr = cmdOutWriters
if err := cmd.Run(); err != nil {
return nil, fmt.Errorf("error running command %s policy: %w", ArgsStr, err)
return nil, fmt.Errorf("error running command %s: %w", ArgsStr, err)
}
return parsePackageVersion(cmdOutBuf.String(), cmdCtxLogger, command, cmdOutBuf)
@@ -98,6 +99,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()
localCMD = exec.Command(command.Cmd, command.Args...)
}
if command.Dir != nil {

View File

@@ -492,7 +492,8 @@ func (command *Command) RunCmdSSH(cmdCtxLogger zerolog.Logger, opts *ConfigOpts)
env: command.Environment,
}
)
// Get the command type
// This must be done before concatenating the arguments
command.Type = strings.TrimSpace(command.Type)
command = getCommandType(command)
@@ -506,7 +507,7 @@ func (command *Command) RunCmdSSH(cmdCtxLogger zerolog.Logger, opts *ConfigOpts)
Str("Host", *command.Host).
Msgf("Running %s on host %s", getCommandTypeLabel(command.Type), *command.Host)
cmdCtxLogger.Debug().Str("cmd", command.Cmd).Strs("args", command.Args).Send()
// cmdCtxLogger.Debug().Str("cmd", command.Cmd).Strs("args", command.Args).Send()
// Ensure SSH client is connected
if command.RemoteHost.SshClient == nil {

View File

@@ -259,8 +259,6 @@ func getCommandType(command *Command) *Command {
case "checkVersion":
command.Cmd, command.Args = command.pkgMan.CheckVersion(command.PackageName, command.PackageVersion)
}
} else if command.Type != "package" {
command.packageCmdSet = false
}
if command.Type == "user" && !command.userCmdSet {