Skip to content

Commit 72da607

Browse files
committed
change template char from '!' to '@'
1 parent eaf5b8c commit 72da607

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

internal/commands/at.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
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

1314
var 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
}

internal/commands/mt.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff 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

464464
func obtainMT(context *cli.Context) (string, error) {

internal/utils/printer.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
}

0 commit comments

Comments
 (0)