Skip to content

Commit 6cb7de7

Browse files
committed
cleanup
1 parent 5f74225 commit 6cb7de7

File tree

2 files changed

+13
-30
lines changed

2 files changed

+13
-30
lines changed

cmd/tdf-decrypt.go

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package cmd
33
import (
44
"fmt"
55
"os"
6-
"strings"
76

87
"github.com/opentdf/otdfctl/pkg/cli"
98
"github.com/opentdf/otdfctl/pkg/man"
@@ -32,35 +31,20 @@ func dev_tdfDecryptCmd(cmd *cobra.Command, args []string) {
3231
cli.ExitWithError("Failed to decrypt file", err)
3332
}
3433

35-
if output == "stdout" {
34+
if output == "" {
3635
// Print decrypted content to stdout
3736
fmt.Print(decrypted.String())
3837
return
39-
} else if output != "" {
40-
// Here 'output' is the filename given with -o
41-
f, err := os.Create(output)
42-
if err != nil {
43-
cli.ExitWithError("Failed to write decrypted data to file", err)
44-
}
45-
defer f.Close()
46-
_, err = f.Write(decrypted.Bytes())
47-
if err != nil {
48-
cli.ExitWithError("Failed to write decrypted data to file", err)
49-
}
50-
return
51-
} else {
52-
// Here the 'output' filename is based on the input filename
53-
// Write decrypted string to file with stripped .tdf extension
54-
f, err := os.Create(strings.Replace(tdfFile, ".tdf", "", 1))
55-
if err != nil {
56-
cli.ExitWithError("Failed to write decrypted data to file", err)
57-
}
58-
defer f.Close()
59-
_, err = f.Write(decrypted.Bytes())
60-
if err != nil {
61-
cli.ExitWithError("Failed to write decrypted data to file", err)
62-
}
63-
return
38+
}
39+
// Here 'output' is the filename given with -o
40+
f, err := os.Create(output)
41+
if err != nil {
42+
cli.ExitWithError("Failed to write decrypted data to file", err)
43+
}
44+
defer f.Close()
45+
_, err = f.Write(decrypted.Bytes())
46+
if err != nil {
47+
cli.ExitWithError("Failed to write decrypted data to file", err)
6448
}
6549
}
6650

docs/man/decrypt/_index.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ command:
55
flags:
66
- name: out
77
shorthand: o
8-
description: "The decrypted out destination. Default: 'stdout'. Options: ['file', 'stdout']"
9-
default: 'stdout'
8+
description: 'The file destination for decrypted content to be written.'
9+
default: ''
1010
---
1111

1212
Decrypt a Trusted Data Format (TDF) file and output the contents to stdout or a file in the current working directory.
@@ -23,5 +23,4 @@ otdfctl decrypt
2323
otdfctl decrypt hello.txt.tdf # print to stdout
2424
otdfctl decrypt hello.txt.tdf > hello.txt # consume stdout to write to hello.txt file
2525
otdfctl decrypt hello.txt.tdf -o hello.txt # write to hello.txt file
26-
2726
```

0 commit comments

Comments
 (0)