Skip to content

Commit

Permalink
update --archived: accept true/false
Browse files Browse the repository at this point in the history
This way we're consistent, since read already printed true/false.
  • Loading branch information
vmiklos committed Apr 19, 2024
1 parent c82c3ea commit 6346f6e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
9 changes: 7 additions & 2 deletions commands/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package commands
import (
"bufio"
"fmt"
"strconv"
"strings"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -137,7 +138,11 @@ func newUpdateCommand(ctx *Context) *cobra.Command {
return fmt.Errorf("db.Prepare() failed: %s", err)
}

result, err := query.Exec(archived, id)
parsed, err := strconv.ParseBool(archived)
if err != nil {
return fmt.Errorf("ParseBool() failed: %s", err)
}
result, err := query.Exec(parsed, id)
if err != nil {
return fmt.Errorf("db.Exec() failed: %s", err)
}
Expand Down Expand Up @@ -168,7 +173,7 @@ func newUpdateCommand(ctx *Context) *cobra.Command {
cmd.Flags().StringVarP(&user, "user", "u", "", "new user (default: keep unchanged)")
cmd.Flags().VarP(&passwordType, "type", "t", `new password type ("plain" or "totp"; default: keep unchanged)`)
cmd.Flags().StringVarP(&password, "password", "p", "", `new password ("-" generates a new one; default: keep unchanged)`)
cmd.Flags().StringVarP(&archived, "archived", "a", "", `new archived value (default: keep unchanged)`)
cmd.Flags().StringVarP(&archived, "archived", "a", "", `new archived value ("true" or "false"; default: keep unchanged)`)

return cmd
}
2 changes: 1 addition & 1 deletion commands/update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ func TestUpdateArchived(t *testing.T) {
expectedMachine := "mymachine"
expectedService := "myservice"
expectedUser := "myuser"
expectedArchived := "1"
expectedArchived := "true"
expectedPassword := "mypassword"
secure := false
_, err := createPassword(&ctx, expectedMachine, expectedService, expectedUser, expectedPassword, "plain", secure)
Expand Down
2 changes: 1 addition & 1 deletion guide/src/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,5 +175,5 @@ Again, you can use `cpm search` to find the password ID.
An alternative for deletion is to just mark the password as archived:

```console
cpm update -i ... -a 1
cpm update -i ... --archived true
```

0 comments on commit 6346f6e

Please sign in to comment.