Skip to content

Commit

Permalink
Use reflect to check if a secret is unset
Browse files Browse the repository at this point in the history
  • Loading branch information
slarwise committed Aug 13, 2024
1 parent 410e96b commit e55ed1c
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"log/slog"
"net/http"
"os"
"reflect"
"slices"
"strings"
"sync"
Expand Down Expand Up @@ -156,12 +157,14 @@ func main() {
case tcell.KeyEscape, tcell.KeyCtrlC:
return
case tcell.KeyEnter:
bytes, err := json.MarshalIndent(state.Secret, "", " ")
if err != nil {
state.Error = fmt.Sprintf("Failed to marshal secret: %s", err)
return
if !(reflect.ValueOf(state.Secret).IsZero()) {
bytes, err := json.MarshalIndent(state.Secret, "", " ")
if err != nil {
state.Error = fmt.Sprintf("Failed to marshal secret: %s", err)
return
}
state.Result = bytes
}
state.Result = bytes
return
case tcell.KeyBackspace, tcell.KeyBackspace2:
if len(state.Prompt) > 0 {
Expand Down Expand Up @@ -406,7 +409,7 @@ func drawScrollbar(s State) {
}

func drawSecret(s State) {
if s.Secret.Data.Data == nil && s.Secret.Data.Metadata == nil {
if reflect.ValueOf(s.Secret).IsZero() {
return
}
x := s.Width/2 + 2
Expand Down

0 comments on commit e55ed1c

Please sign in to comment.