Skip to content
This repository was archived by the owner on Feb 16, 2023. It is now read-only.

Commit cf88a57

Browse files
Merge pull request #263 from secrethub/feature/no-newline-flag-read
Add -n flag to read command to not print newline
2 parents 1e7293d + 25e37f6 commit cf88a57

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

internals/secrethub/read.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ type ReadCommand struct {
2525
clipper clip.Clipper
2626
outFile string
2727
fileMode filemode.FileMode
28+
noNewLine bool
2829
newClient newClientFunc
2930
}
3031

@@ -51,6 +52,7 @@ func (cmd *ReadCommand) Register(r command.Registerer) {
5152
).Short('c').BoolVar(&cmd.useClipboard)
5253
clause.Flag("out-file", "Write the secret value to this file.").Short('o').StringVar(&cmd.outFile)
5354
clause.Flag("file-mode", "Set filemode for the output file. Defaults to 0600 (read and write for current user) and is ignored without the --out-file flag.").Default("0600").SetValue(&cmd.fileMode)
55+
clause.Flag("no-newline", "Do not print a new line after the secret.").Short('n').BoolVar(&cmd.noNewLine)
5456

5557
command.BindAction(clause, cmd.Run)
5658
}
@@ -81,15 +83,20 @@ func (cmd *ReadCommand) Run() error {
8183
)
8284
}
8385

86+
secretData := secret.Data
87+
if !cmd.noNewLine {
88+
secretData = posix.AddNewLine(secretData)
89+
}
90+
8491
if cmd.outFile != "" {
85-
err = ioutil.WriteFile(cmd.outFile, posix.AddNewLine(secret.Data), cmd.fileMode.FileMode())
92+
err = ioutil.WriteFile(cmd.outFile, secretData, cmd.fileMode.FileMode())
8693
if err != nil {
8794
return ErrCannotWrite(cmd.outFile, err)
8895
}
8996
}
9097

9198
if cmd.outFile == "" && !cmd.useClipboard {
92-
fmt.Fprintf(cmd.io.Stdout(), "%s", string(posix.AddNewLine(secret.Data)))
99+
fmt.Fprintf(cmd.io.Stdout(), "%s", string(secretData))
93100
}
94101

95102
return nil

0 commit comments

Comments
 (0)