Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Commands layout refactored #3

Merged
merged 1 commit into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 45 additions & 38 deletions cmd/pwdmg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,49 +12,55 @@ import (
"syscall"
)

func GetCommand() *cli.Command {
func PwdCommand() *cli.Command {
return &cli.Command{
Name: "get",
Aliases: []string{"g"},
Usage: "pwdmg get",
Name: "pwd",
Usage: "pwdmg pwd",
Subcommands: []*cli.Command{
{
Name: "pwd",
Usage: "pwdmg get pwd <domain> <login>",
Description: "Get password by domain and login",
Action: func(c *cli.Context) error {
domain := c.Args().Get(0)
login := c.Args().Get(1)

fmt.Println(domain, login)

if domain == "" || login == "" {
return errors.New("domain or login cannot be empty")
}

pwd, err := get.PwdByLogin(domain, login)
if err != nil {
return err
}

err = clipboard.WriteAll(pwd)
if err != nil {
return err
}

fmt.Println("Password copied to clipboard")
return nil
},
},
getCommand(),
saveCommand(),
importCommand(),
},
}
}

func getCommand() *cli.Command {
return &cli.Command{
Name: "get",
Aliases: []string{"g"},
Usage: "pwdmg pwd get <domain> <login>",
Description: "Get password by domain and login",
Action: func(c *cli.Context) error {
domain := c.Args().Get(0)
login := c.Args().Get(1)

fmt.Println(domain, login)

if domain == "" || login == "" {
return errors.New("domain or login cannot be empty")
}

pwd, err := get.PwdByLogin(domain, login)
if err != nil {
return err
}

err = clipboard.WriteAll(pwd)
if err != nil {
return err
}

fmt.Println("Password copied to clipboard")
return nil
},
}
}

func SaveCommand() *cli.Command {
func saveCommand() *cli.Command {
return &cli.Command{
Name: "save",
Aliases: []string{"s"},
Usage: "pwdmg save <domain> <login>",
Usage: "pwdmg pwd save <domain> <login>",
Description: "Save password for provided domain and login account",
Action: func(c *cli.Context) error {
domain := c.Args().Get(0)
Expand Down Expand Up @@ -82,21 +88,22 @@ func SaveCommand() *cli.Command {
}
}

func ImportCommand() *cli.Command {
func importCommand() *cli.Command {
return &cli.Command{
Name: "import",
Usage: "pwdmg import",
Aliases: []string{"i"},
Usage: "pwdmg pwd import",
Description: "Save password for provided domain and login account",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "provider",
Aliases: []string{"p"},
Usage: "passwords import provider (for now support only chrome)",
Usage: "passwords import provider (supports only chrome for now)",
},
&cli.StringFlag{
Name: "file",
Aliases: []string{"f"},
Usage: "passwords import file (for now support only csv format)",
Usage: "passwords import file (supports only csv format for now)",
},
},
Action: func(c *cli.Context) error {
Expand Down
11 changes: 6 additions & 5 deletions cmd/pwdmg/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ import (

func main() {
app := &cli.App{
Name: "pwdmg",
Usage: "Manage passwords",
Name: "pwdmg",
Usage: "pwdmg",
Description: "CLI password manager",
Commands: []*cli.Command{
config.GetCommand(),
config.SaveCommand(),
config.ImportCommand(),
config.PwdCommand(),
},
}

fmt.Println(app.Command("pwd").Command("get").Names())

err := app.Run(os.Args)
if err != nil {
fmt.Println(err)
Expand Down