Skip to content

Commit

Permalink
Add --username flag to retrieve username, remove double quotes from -…
Browse files Browse the repository at this point in the history
…-password output
  • Loading branch information
marevers committed Feb 15, 2024
1 parent f5eaa13 commit 99d5482
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
22 changes: 18 additions & 4 deletions cmd/get-entry.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ pleasant-cli get entry --path <path> --attachments`,
return
}

if cmd.Flags().Changed("pretty") {
switch {
case cmd.Flags().Changed("pretty"):
output, err := pleasant.PrettyPrintJson(entry)
if err != nil {
fmt.Println(err)
Expand All @@ -98,9 +99,21 @@ pleasant-cli get entry --path <path> --attachments`,

fmt.Println(output)
return
}
case cmd.Flags().Changed("username"):
en, err := pleasant.UnmarshalEntry(entry)
if err != nil {
fmt.Println(err)
return
}

fmt.Println(entry)
fmt.Println(en.Username)
return
case cmd.Flags().Changed("password"):
fmt.Println(pleasant.TrimDoubleQuotes(entry))
return
default:
fmt.Println(entry)
}
},
}

Expand All @@ -112,8 +125,9 @@ func init() {
getEntryCmd.MarkFlagsMutuallyExclusive("path", "id")
getEntryCmd.MarkFlagsOneRequired("path", "id")

getEntryCmd.Flags().Bool("username", false, "Get the username of the entry")
getEntryCmd.Flags().Bool("password", false, "Get the password of the entry")
getEntryCmd.Flags().Bool("attachments", false, "Gets the attachments of the entry")
getEntryCmd.Flags().Bool("useraccess", false, "Gets the users that have access to the entry")
getEntryCmd.MarkFlagsMutuallyExclusive("password", "attachments", "useraccess")
getEntryCmd.MarkFlagsMutuallyExclusive("username", "password", "attachments", "useraccess")
}
8 changes: 8 additions & 0 deletions pleasant/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,3 +376,11 @@ func PathAndNameMatching(resourcePath, name string) bool {
s := strings.Split(resourcePath, "/")
return s[len(s)-1] == name
}

func TrimDoubleQuotes(str string) string {
if strings.HasPrefix(str, `"`) && strings.HasSuffix(str, `"`) {
return str[1 : len(str)-1]
}

return str
}

0 comments on commit 99d5482

Please sign in to comment.