File tree 3 files changed +20
-4
lines changed
3 files changed +20
-4
lines changed Original file line number Diff line number Diff line change 8
8
"github.com/urfave/cli/v2"
9
9
10
10
"github.com/oidc-mytoken/client/internal/config"
11
+ cutils "github.com/oidc-mytoken/client/internal/utils"
11
12
)
12
13
13
14
var atCommand = struct {
@@ -47,7 +48,7 @@ func init() {
47
48
Name : "out" ,
48
49
Aliases : []string {"o" },
49
50
Usage : "The access token will be printed to this output" ,
50
- Value : "/dev/stdout" ,
51
+ Value : os . Stdout . Name () ,
51
52
Destination : & atCommand .Out ,
52
53
Placeholder : "FILE" ,
53
54
},
@@ -77,5 +78,5 @@ func getAT(context *cli.Context) error {
77
78
if atRes .TokenUpdate != nil {
78
79
updateMytoken (atRes .TokenUpdate .Mytoken )
79
80
}
80
- return os . WriteFile (atc .Out , append ([] byte ( atRes .AccessToken ), '\n' ), 0600 )
81
+ return cutils . WriteOutput (atc .Out , atRes .AccessToken )
81
82
}
Original file line number Diff line number Diff line change @@ -433,7 +433,7 @@ func init() {
433
433
Name : "out" ,
434
434
Aliases : []string {"o" },
435
435
Usage : "The mytoken will be printed to this output" ,
436
- Value : "/dev/stdout" ,
436
+ Value : os . Stdout . Name () ,
437
437
Destination : & mtCommand .Out ,
438
438
Placeholder : "FILE" ,
439
439
},
@@ -458,7 +458,7 @@ func obtainMTCmd(context *cli.Context) error {
458
458
if err != nil {
459
459
return err
460
460
}
461
- return os . WriteFile (mtCommand .Out , append ([] byte ( mt ), '\n' ), 0600 )
461
+ return cutils . WriteOutput (mtCommand .Out , mt )
462
462
}
463
463
464
464
func 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