From 32827e60f48285d11dae8747eac9eba8ca74e65c Mon Sep 17 00:00:00 2001 From: Dirk-Willem van Gulik Date: Wed, 2 Jan 2019 19:45:45 +0100 Subject: [PATCH 1/2] Minor tweaks to also show the login; to make this tool marginally more useful. --- README.md | 14 +++++++++++++- cmd.go | 5 ++++- main.go | 12 +++++++----- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 0258e50..2e39e81 100755 --- a/README.md +++ b/README.md @@ -41,7 +41,19 @@ Commands: get Get a password for given context set Add or update a context -Run 'mc-cli login COMMAND --help' for more information on a command. +Run 'mc-cli login COMMAND --help' for more information on a command. A typical example is + + /mc-cli login get github.com "" + +or to fetch the password for your github account. Add the flag '-l' to also extract the username: + + /mc-cli login get github.com "" -l + +Alternatively use: + + /mc-cli login get github.com myusername + +if you want to be specific about a username. ``` ``` diff --git a/cmd.go b/cmd.go index da3956a..51b6153 100755 --- a/cmd.go +++ b/cmd.go @@ -14,7 +14,7 @@ const ( maxFileSize = 524288 ) -func processLoginCmd(subCmd, context, login, pwd, desc string, printDesc bool) (err error) { +func processLoginCmd(subCmd, context, login, pwd, desc string, printDesc bool, printLogin bool) (err error) { m := &MoolticuteMsg{ Data: MsgData{ @@ -47,6 +47,9 @@ func processLoginCmd(subCmd, context, login, pwd, desc string, printDesc bool) ( } if subCmd == "get" { + if printLogin { + fmt.Println(res.Login) + } if printDesc { fmt.Println(res.Description) } else { diff --git a/main.go b/main.go index f2863fd..53d98b1 100755 --- a/main.go +++ b/main.go @@ -43,6 +43,7 @@ var ( optPass *string optDesc *string optPrintDesc *bool + optLoginDesc *bool optFilename *string optParameter *string optValue *string @@ -82,16 +83,17 @@ func main() { app.Command("login", "Manage credentials stored in the device", func(cmd *cli.Cmd) { cmd.Command("get", "Get a password for given context", func(cmd *cli.Cmd) { - optContext = cmd.StringArg("CONTEXT", "", "Context to work on") - optLogin = cmd.StringArg("LOGIN", "", "Login to use") + optContext = cmd.StringArg("CONTEXT", "", "Context to work on (e.g. the site-name)") + optLogin = cmd.StringArg("LOGIN", "", "Login to use (or provided the \"\" (empty) string to select the first)") addDefaultArgs(cmd) - optPrintDesc = cmd.BoolOpt("d description", false, "Output service description instead of password") + optPrintDesc = cmd.BoolOpt("d description", false, "Output service description instead of the password") + optLoginDesc = cmd.BoolOpt("l Output login", false, "Output login too") cmd.Spec = "CONTEXT LOGIN [OPTIONS]" cmd.Action = func() { checkLog() - if err := processLoginCmd("get", *optContext, *optLogin, "", "", *optPrintDesc); err != nil { + if err := processLoginCmd("get", *optContext, *optLogin, "", "", *optPrintDesc, *optLoginDesc); err != nil { exit(err, 1) } } @@ -107,7 +109,7 @@ func main() { cmd.Action = func() { checkLog() - if err := processLoginCmd("set", *optContext, *optLogin, *optPass, *optDesc, false); err != nil { + if err := processLoginCmd("set", *optContext, *optLogin, *optPass, *optDesc, false, false); err != nil { exit(err, 1) } } From 7c844e42abb8772b3bf289710dbdb602ba656eab Mon Sep 17 00:00:00 2001 From: Dirk-Willem van Gulik Date: Wed, 2 Jan 2019 20:08:51 +0100 Subject: [PATCH 2/2] Add delete function. Unfortunately - it seems to require a PIN entry for each and every change with no easy bulk delete at this level. --- cmd.go | 8 +++++--- main.go | 14 ++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/cmd.go b/cmd.go index 51b6153..308879b 100755 --- a/cmd.go +++ b/cmd.go @@ -25,6 +25,8 @@ func processLoginCmd(subCmd, context, login, pwd, desc string, printDesc bool, p if subCmd == "get" { m.Msg = "get_credential" + } else if subCmd == "del" { + m.Msg = "del_credential" } else if subCmd == "set" { if pwd == "" { fmt.Printf("Password: ") @@ -55,7 +57,7 @@ func processLoginCmd(subCmd, context, login, pwd, desc string, printDesc bool, p } else { fmt.Println(res.Password) } - } else if subCmd == "set" { + } else if subCmd == "set" || subCmd == "del" { fmt.Println(green(CharCheck), "Done") } @@ -70,7 +72,7 @@ func processDataCmd(subCmd, context, filename string, progressFunc ProgressCb) ( }, } - if subCmd == "get" { + if subCmd == "get" || subCmd == "del" { m.Msg = "get_data_node" } else if subCmd == "set" { m.Msg = "set_data_node" @@ -108,7 +110,7 @@ func processDataCmd(subCmd, context, filename string, progressFunc ProgressCb) ( b := bytes.NewBuffer(bdec) b.WriteTo(os.Stdout) - } else if subCmd == "set" { + } else if subCmd == "set" || subCmd == "del" { fmt.Println(green(CharCheck), "Done") } diff --git a/main.go b/main.go index 53d98b1..742dba7 100755 --- a/main.go +++ b/main.go @@ -114,6 +114,20 @@ func main() { } } }) + cmd.Command("del", "Delete a context", func(cmd *cli.Cmd) { + optContext = cmd.StringArg("CONTEXT", "", "Context to work on") + optLogin = cmd.StringArg("LOGIN", "", "Login to use (or provided the \"\" (empty) string to select the first)") + addDefaultArgs(cmd) + cmd.Spec = "CONTEXT LOGIN" + + cmd.Action = func() { + checkLog() + + if err := processLoginCmd("del", *optContext, *optLogin, "", "", false, false); err != nil { + exit(err, 1) + } + } + }) }) app.Command("data", "Import & export small files stored in the device", func(cmd *cli.Cmd) {