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

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

View File

@ -33,7 +33,7 @@ commands:
Args:
- docker-ce-cli
packageManager: apt
packageOperation: install
packageOperation: upgrade
cmd-lists:
cmds-to-run: # this can be any name you want

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 {

View File

@ -40,6 +40,7 @@ func (a *AptManager) Install(pkg, version string, args []string) (string, []stri
if args != nil {
baseArgs = append(baseArgs, args...)
}
fmt.Printf("baseArgs: %v\n", baseArgs)
return baseCmd, baseArgs
}
@ -105,11 +106,6 @@ func (a *AptManager) SetAuthCommand(authCommand string) {
a.authCommand = authCommand
}
// SetPackageParser assigns a PackageParser.
func (a *AptManager) SetPackageParser(parser pkgcommon.PackageParser) {
a.Parser = parser
}
// Parse parses the apt-cache policy output to extract Installed and Candidate versions.
func (a *AptManager) Parse(output string) (*pkgcommon.PackageVersion, error) {
// Check for error message in the output