File tree Expand file tree Collapse file tree 3 files changed +20
-4
lines changed Expand file tree Collapse file tree 3 files changed +20
-4
lines changed Original file line number Diff line number Diff line change 88 "github.com/urfave/cli/v2"
99
1010 "github.com/oidc-mytoken/client/internal/config"
11+ cutils "github.com/oidc-mytoken/client/internal/utils"
1112)
1213
1314var atCommand = struct {
@@ -47,7 +48,7 @@ func init() {
4748 Name : "out" ,
4849 Aliases : []string {"o" },
4950 Usage : "The access token will be printed to this output" ,
50- Value : "/dev/stdout" ,
51+ Value : os . Stdout . Name () ,
5152 Destination : & atCommand .Out ,
5253 Placeholder : "FILE" ,
5354 },
@@ -77,5 +78,5 @@ func getAT(context *cli.Context) error {
7778 if atRes .TokenUpdate != nil {
7879 updateMytoken (atRes .TokenUpdate .Mytoken )
7980 }
80- return os . WriteFile (atc .Out , append ([] byte ( atRes .AccessToken ), '\n' ), 0600 )
81+ return cutils . WriteOutput (atc .Out , atRes .AccessToken )
8182}
Original file line number Diff line number Diff line change @@ -433,7 +433,7 @@ func init() {
433433 Name : "out" ,
434434 Aliases : []string {"o" },
435435 Usage : "The mytoken will be printed to this output" ,
436- Value : "/dev/stdout" ,
436+ Value : os . Stdout . Name () ,
437437 Destination : & mtCommand .Out ,
438438 Placeholder : "FILE" ,
439439 },
@@ -458,7 +458,7 @@ func obtainMTCmd(context *cli.Context) error {
458458 if err != nil {
459459 return err
460460 }
461- return os . WriteFile (mtCommand .Out , append ([] byte ( mt ), '\n' ), 0600 )
461+ return cutils . WriteOutput (mtCommand .Out , mt )
462462}
463463
464464func obtainMT (context * cli.Context ) (string , error ) {
Original file line number Diff line number Diff line change 1+ package utils
2+
3+ import (
4+ "os"
5+ )
6+
7+ // WriteOutput writes the output to the specified file. This works also with /dev/stdout on Windows
8+ func WriteOutput (out , data string ) error {
9+ outData := append ([]byte (data ), '\n' )
10+ if out == os .Stdout .Name () {
11+ _ , err := os .Stdout .Write (outData )
12+ return err
13+ }
14+ return os .WriteFile (out , outData , 0600 )
15+ }
You can’t perform that action at this time.
0 commit comments