mirror of
https://github.com/drone-plugins/drone-manifest.git
synced 2026-06-04 18:24:08 +08:00
f43d8309d5
Instead of downloading and using the manifest tool mimic the behavior of the CLI commands used. This is now possible with the v2 of the manifest tool library which can be used in this manner. Use the new coding conventions for the plugin.
38 lines
861 B
Go
38 lines
861 B
Go
// Copyright (c) 2023, the Drone Plugins project authors.
|
|
// Please see the AUTHORS file for details. All rights reserved.
|
|
// Use of this source code is governed by an Apache 2.0 license that can be
|
|
// found in the LICENSE file.
|
|
|
|
package plugin
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"encoding/json"
|
|
"io"
|
|
"os"
|
|
)
|
|
|
|
//nolint:errcheck
|
|
func writeCard(path string, card interface{}) {
|
|
data, _ := json.Marshal(card)
|
|
|
|
switch {
|
|
case path == "/dev/stdout":
|
|
writeCardTo(os.Stdout, data)
|
|
case path == "/dev/stderr":
|
|
writeCardTo(os.Stderr, data)
|
|
case path != "":
|
|
os.WriteFile(path, data, 0o644) //nolint:gomnd,gosec
|
|
}
|
|
}
|
|
|
|
//nolint:errcheck
|
|
func writeCardTo(out io.Writer, data []byte) {
|
|
encoded := base64.StdEncoding.EncodeToString(data)
|
|
|
|
io.WriteString(out, "\u001B]1338;")
|
|
io.WriteString(out, encoded)
|
|
io.WriteString(out, "\u001B]0m")
|
|
io.WriteString(out, "\n")
|
|
}
|