Skip to content

Commit

Permalink
Make termwiz default action adhere to the copy flag (#534)
Browse files Browse the repository at this point in the history
Fixes #531
  • Loading branch information
dominikschulz authored Dec 18, 2017
1 parent 9d96a7e commit fb425e1
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 1 deletion.
12 changes: 12 additions & 0 deletions action/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ func (s *Action) Create(ctx context.Context, c *cli.Context) error {
}
act, sel := termwiz.GetSelection(ctx, "Type of secret to create", "<↑/↓> to change the selection, <→> to select, <ESC> to quit", types)
switch act {
case "default":
fallthrough
case "show":
switch sel {
case 0:
Expand Down Expand Up @@ -91,6 +93,8 @@ func (s *Action) createWebsite(ctx context.Context, c *cli.Context) error {
stores = append(stores, s.Store.MountPoints()...)
act, sel := termwiz.GetSelection(ctx, "Store for secret", "<↑/↓> to change the selection, <→> to select, <ESC> to quit", stores)
switch act {
case "default":
fallthrough
case "show":
store = stores[sel]
if store == "<root>" {
Expand Down Expand Up @@ -165,6 +169,8 @@ func (s *Action) createPIN(ctx context.Context, c *cli.Context) error {
stores = append(stores, s.Store.MountPoints()...)
act, sel := termwiz.GetSelection(ctx, "Store for secret", "<↑/↓> to change the selection, <→> to select, <ESC> to quit", stores)
switch act {
case "default":
fallthrough
case "show":
store = stores[sel]
if store == "<root>" {
Expand Down Expand Up @@ -231,6 +237,8 @@ func (s *Action) createAWS(ctx context.Context, c *cli.Context) error {
stores = append(stores, s.Store.MountPoints()...)
act, sel := termwiz.GetSelection(ctx, "Store for secret", "<↑/↓> to change the selection, <→> to select, <ESC> to quit", stores)
switch act {
case "default":
fallthrough
case "show":
store = stores[sel]
if store == "<root>" {
Expand Down Expand Up @@ -298,6 +306,8 @@ func (s *Action) createGCP(ctx context.Context, c *cli.Context) error {
stores = append(stores, s.Store.MountPoints()...)
act, sel := termwiz.GetSelection(ctx, "Store for secret", "<↑/↓> to change the selection, <→> to select, <ESC> to quit", stores)
switch act {
case "default":
fallthrough
case "show":
store = stores[sel]
if store == "<root>" {
Expand Down Expand Up @@ -373,6 +383,8 @@ func (s *Action) createGeneric(ctx context.Context, c *cli.Context) error {
stores = append(stores, s.Store.MountPoints()...)
act, sel := termwiz.GetSelection(ctx, "Store for secret", "<↑/↓> to change the selection, <→> to select, <ESC> to quit", stores)
switch act {
case "default":
fallthrough
case "show":
store = stores[sel]
if store == "<root>" {
Expand Down
4 changes: 4 additions & 0 deletions action/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ func (s *Action) Find(ctx context.Context, c *cli.Context) error {

act, sel := termwiz.GetSelection(ctx, "Found secrets -", "", choices)
switch act {
case "default":
// display or copy selected entry
fmt.Println(choices[sel])
return s.show(ctx, c, choices[sel], "", false)
case "copy":
// display selected entry
fmt.Println(choices[sel])
Expand Down
2 changes: 2 additions & 0 deletions action/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ func (s *Action) InitOnboarding(ctx context.Context, c *cli.Context) error {
}
act, sel := termwiz.GetSelection(ctx, "Store for secret", "<↑/↓> to change the selection, <→> to select, <ESC> to quit", choices)
switch act {
case "default":
fallthrough
case "show":
switch sel {
case 0:
Expand Down
8 changes: 8 additions & 0 deletions action/recipients.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ func (s *Action) RecipientsAdd(ctx context.Context, c *cli.Context) error {
stores = append(stores, s.Store.MountPoints()...)
act, sel := termwiz.GetSelection(ctx, "Store for secret", "<↑/↓> to change the selection, <→> to select, <ESC> to quit", stores)
switch act {
case "default":
fallthrough
case "show":
store = stores[sel]
if store == "<root>" {
Expand All @@ -90,6 +92,8 @@ func (s *Action) RecipientsAdd(ctx context.Context, c *cli.Context) error {
if len(choices) > 0 {
act, sel := termwiz.GetSelection(ctx, "Add Recipient -", "<↑/↓> to change the selection, <→> to add this recipient, <ESC> to quit", choices)
switch act {
case "default":
fallthrough
case "show":
recipients = []string{kl[sel].Fingerprint}
default:
Expand Down Expand Up @@ -141,6 +145,8 @@ func (s *Action) RecipientsRemove(ctx context.Context, c *cli.Context) error {
stores = append(stores, s.Store.MountPoints()...)
act, sel := termwiz.GetSelection(ctx, "Store for secret", "<↑/↓> to change the selection, <→> to select, <ESC> to quit", stores)
switch act {
case "default":
fallthrough
case "show":
store = stores[sel]
if store == "<root>" {
Expand Down Expand Up @@ -169,6 +175,8 @@ func (s *Action) RecipientsRemove(ctx context.Context, c *cli.Context) error {
if len(choices) > 0 {
act, sel := termwiz.GetSelection(ctx, "Remove recipient -", "<↑/↓> to change the selection, <→> to remove this recipient, <ESC> to quit", choices)
switch act {
case "default":
fallthrough
case "show":
recipients = []string{ids[sel]}
default:
Expand Down
4 changes: 3 additions & 1 deletion utils/termwiz/selection.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,10 @@ func GetSelection(ctx context.Context, prompt, usage string, choices []string) (
return "aborted", cur
case termbox.KeyArrowLeft:
return "copy", cur
case termbox.KeyArrowRight, termbox.KeyEnter:
case termbox.KeyArrowRight:
return "show", cur
case termbox.KeyEnter:
return "default", cur
case termbox.KeyArrowDown, termbox.KeyTab:
cur++
if cur >= len(choices) {
Expand Down

0 comments on commit fb425e1

Please sign in to comment.