-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
47 lines (39 loc) · 1.12 KB
/
main.go
File metadata and controls
47 lines (39 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package main
import (
"fmt"
"github.com/spf13/cobra"
"os"
)
func main() {
cmd := buildCmdMask()
if err := cmd.Execute(); err != nil {
var exitCode int
if e, ok := err.(*ExitCodeError); ok {
exitCode = e.Code // Extract exit code
} else {
exitCode = 1 // Default error code
}
//fmt.Fprintf(os.Stderr, "Error: %v\n", err)
os.Exit(exitCode)
}
}
func buildCmdMask() *cobra.Command {
cmd := &cobra.Command{
Use: "maskcmd [--flags] [command] [args...]",
Short: "Run a command while masking sensitive data from its stdout and stderr",
Args: cobra.MinimumNArgs(1),
PreRunE: cmdMaskPreRun,
RunE: cmdMask,
}
cmd.Flags().String("secrets-dir", "", "Treat files content in certain directory as secrets")
cmd.Flags().String("env-vars", "", "Mark certain environment variables as secrets")
cmd.Flags().Bool("all-env-vars", false, "Treat all environment variables values as secrets")
return cmd
}
// ExitCodeError is a custom error type with an exit code
type ExitCodeError struct {
Code int
}
func (e *ExitCodeError) Error() string {
return fmt.Sprintf("child command returned exit code: %d", e.Code)
}