aboutsummaryrefslogtreecommitdiff
path: root/cmd/args.go
diff options
context:
space:
mode:
authorBryan McNulty <bryanmcnulty@protonmail.com>2025-04-17 02:26:28 -0500
committerBryan McNulty <bryanmcnulty@protonmail.com>2025-04-17 02:26:28 -0500
commit22e4fc56cca0a8c466bf09a6f529573063ce5cb6 (patch)
tree05675cb02426f4718bacff88be672ca7e4a285e5 /cmd/args.go
parent5f0928b65e1e1c2a92818ecea0eb81aa547f4a95 (diff)
downloadgoexec-22e4fc56cca0a8c466bf09a6f529573063ce5cb6.tar.gz
goexec-22e4fc56cca0a8c466bf09a6f529573063ce5cb6.zip
Validate output flag before method execution
Diffstat (limited to 'cmd/args.go')
-rw-r--r--cmd/args.go18
1 files changed, 17 insertions, 1 deletions
diff --git a/cmd/args.go b/cmd/args.go
index 50e7c74..b2b6fe2 100644
--- a/cmd/args.go
+++ b/cmd/args.go
@@ -6,6 +6,7 @@ import (
"fmt"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
+ "os"
)
func registerRpcFlags(cmd *cobra.Command) {
@@ -122,5 +123,20 @@ func argsOutput(methods ...string) func(cmd *cobra.Command, args []string) error
as = append(as, argsSmbClient())
}
}
- return args(as...)
+
+ return args(append(as, func(*cobra.Command, []string) (err error) {
+
+ if outputPath != "" {
+ if outputPath == "-" {
+ exec.Output.Writer = os.Stdout
+
+ } else if outputPath != "" {
+
+ if exec.Output.Writer, err = os.OpenFile(outputPath, os.O_WRONLY|os.O_CREATE, 0644); err != nil {
+ log.Fatal().Err(err).Msg("Failed to open output file")
+ }
+ }
+ }
+ return
+ })...)
}