style: improve code readability with consistent multi-line formatting

- Add golines to the list of golangci-lint formatters
- Format multi-line env variable declarations for CLI flags for consistency
- Split string slice initializations onto multiple lines for improved readability in tests
- Use multi-line function calls for better readability in plugin and test code
- Improve readability of script command appends in logic and tests

Signed-off-by: appleboy <appleboy.tw@gmail.com>
This commit is contained in:
appleboy
2025-11-28 21:44:27 +08:00
parent 7a94dda076
commit 36b01aed49
4 changed files with 166 additions and 65 deletions
+17 -6
View File
@@ -15,9 +15,11 @@ import (
var (
errMissingHost = errors.New("error: missing server host")
errMissingPasswordOrKey = errors.New("error: can't connect without a private SSH key or password")
errCommandTimeOut = errors.New("error: command timeout")
envsFormat = "export {NAME}={VALUE}"
errMissingPasswordOrKey = errors.New(
"error: can't connect without a private SSH key or password",
)
errCommandTimeOut = errors.New("error: command timeout")
envsFormat = "export {NAME}={VALUE}"
)
type (
@@ -119,7 +121,10 @@ func (p Plugin) exec(host string, wg *sync.WaitGroup, errChannel chan error) {
for _, key := range p.Config.Envs {
key = strings.ToUpper(key)
if val, found := os.LookupEnv(key); found {
env = append(env, p.format(p.Config.EnvsFormat, "{NAME}", key, "{VALUE}", escapeArg(val)))
env = append(
env,
p.format(p.Config.EnvsFormat, "{NAME}", key, "{VALUE}", escapeArg(val)),
)
}
}
@@ -131,7 +136,10 @@ func (p Plugin) exec(host string, wg *sync.WaitGroup, errChannel chan error) {
p.log(host, "======END======")
}
stdoutChan, stderrChan, doneChan, errChan, err := ssh.Stream(strings.Join(p.Config.Script, "\n"), p.Config.CommandTimeout)
stdoutChan, stderrChan, doneChan, errChan, err := ssh.Stream(
strings.Join(p.Config.Script, "\n"),
p.Config.CommandTimeout,
)
if err != nil {
errChannel <- err
return
@@ -257,7 +265,10 @@ func (p Plugin) scriptCommands() []string {
}
commands = append(commands, cmd)
if p.Config.ScriptStop && cmd[(len(cmd)-1):] != "\\" {
commands = append(commands, "DRONE_SSH_PREV_COMMAND_EXIT_CODE=$? ; if [ $DRONE_SSH_PREV_COMMAND_EXIT_CODE -ne 0 ]; then exit $DRONE_SSH_PREV_COMMAND_EXIT_CODE; fi;")
commands = append(
commands,
"DRONE_SSH_PREV_COMMAND_EXIT_CODE=$? ; if [ $DRONE_SSH_PREV_COMMAND_EXIT_CODE -ne 0 ]; then exit $DRONE_SSH_PREV_COMMAND_EXIT_CODE; fi;",
)
}
}