Skip to content

Commit

Permalink
added context to cmd funcs
Browse files Browse the repository at this point in the history
  • Loading branch information
KonstantinGasser committed Jul 5, 2021
1 parent 83789de commit ddcb27f
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 13 deletions.
4 changes: 2 additions & 2 deletions cmd/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ type addOptions struct {
insecure bool
}

func cmdAddAccount(sherlock *internal.Sherlock) *cobra.Command {
func cmdAddAccount(ctx context.Context, sherlock *internal.Sherlock) *cobra.Command {
var opts addOptions

add := &cobra.Command{
Expand Down Expand Up @@ -58,7 +58,7 @@ func cmdAddAccount(sherlock *internal.Sherlock) *cobra.Command {
terminal.Error(err.Error())
return
}
if err := sherlock.AddAccount(context.Background(), account, groupKey, opts.gid); err != nil {
if err := sherlock.AddAccount(ctx, account, groupKey, opts.gid); err != nil {
terminal.Error(err.Error())
return
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/del.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type delOptions struct {
force bool
}

func cmdDel(sherlock *internal.Sherlock) *cobra.Command {
func cmdDel(ctx context.Context, sherlock *internal.Sherlock) *cobra.Command {
var opts delOptions
del := &cobra.Command{
Use: "del",
Expand All @@ -39,7 +39,7 @@ func cmdDel(sherlock *internal.Sherlock) *cobra.Command {
}
}

if err := sherlock.DeleteAccount(context.Background(), opts.gid, opts.account, groupKey); err != nil {
if err := sherlock.DeleteAccount(ctx, opts.gid, opts.account, groupKey); err != nil {
terminal.Error(err.Error())
return
}
Expand Down
4 changes: 3 additions & 1 deletion cmd/get.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cmd

import (
"context"

"github.com/KonstantinGasser/sherlock/internal"
"github.com/KonstantinGasser/sherlock/terminal"
"github.com/atotto/clipboard"
Expand All @@ -11,7 +13,7 @@ type getOptions struct {
verbose bool
}

func cmdGet(sherlock *internal.Sherlock) *cobra.Command {
func cmdGet(ctx context.Context, sherlock *internal.Sherlock) *cobra.Command {
var opts getOptions
get := &cobra.Command{
Use: "get",
Expand Down
4 changes: 3 additions & 1 deletion cmd/list.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cmd

import (
"context"

"github.com/KonstantinGasser/sherlock/internal"
"github.com/KonstantinGasser/sherlock/terminal"
"github.com/spf13/cobra"
Expand All @@ -10,7 +12,7 @@ type listOptions struct {
filterByTag string
}

func cmdList(sherlock *internal.Sherlock) *cobra.Command {
func cmdList(ctx context.Context, sherlock *internal.Sherlock) *cobra.Command {
var opts listOptions

list := &cobra.Command{
Expand Down
15 changes: 10 additions & 5 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package cmd

import (
"context"

"github.com/KonstantinGasser/sherlock/internal"
"github.com/spf13/cobra"
)
Expand All @@ -10,6 +12,9 @@ const (
)

func RootCmd(sherlock *internal.Sherlock) *cobra.Command {

ctx := context.Background()

root := &cobra.Command{
Use: "sherlock",
Short: "sherlock a CLI password manager for the simple use",
Expand All @@ -29,10 +34,10 @@ func RootCmd(sherlock *internal.Sherlock) *cobra.Command {
},
}

root.AddCommand(cmdSetup(sherlock))
root.AddCommand(cmdAddAccount(sherlock))
root.AddCommand(cmdDel(sherlock))
root.AddCommand(cmdList(sherlock))
root.AddCommand(cmdGet(sherlock))
root.AddCommand(cmdSetup(ctx, sherlock))
root.AddCommand(cmdAddAccount(ctx, sherlock))
root.AddCommand(cmdDel(ctx, sherlock))
root.AddCommand(cmdList(ctx, sherlock))
root.AddCommand(cmdGet(ctx, sherlock))
return root
}
4 changes: 3 additions & 1 deletion cmd/setup.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package cmd

import (
"context"

"github.com/KonstantinGasser/sherlock/internal"
"github.com/KonstantinGasser/sherlock/terminal"
"github.com/spf13/cobra"
)

func cmdSetup(sherlock *internal.Sherlock) *cobra.Command {
func cmdSetup(ctx context.Context, sherlock *internal.Sherlock) *cobra.Command {
return &cobra.Command{
Use: "setup",
Short: "setup allows to initially set-up a main password for your vault",
Expand Down
2 changes: 1 addition & 1 deletion terminal/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func Error(format string, a ...interface{}) {
}

func ReadPassword(format string, a ...interface{}) (string, error) {
prettyNoNewLine(color.FgHiBlue, emoji.Locked, format, a...)
prettyNoNewLine(color.FgHiBlue, emoji.Key, format, a...)
b, err := terminal.ReadPassword(int(syscall.Stdin))
if err != nil {
return "", err
Expand Down

0 comments on commit ddcb27f

Please sign in to comment.