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..308879b 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{ @@ -25,6 +25,8 @@ func processLoginCmd(subCmd, context, login, pwd, desc string, printDesc bool) ( if subCmd == "get" { m.Msg = "get_credential" + } else if subCmd == "del" { + m.Msg = "del_credential" } else if subCmd == "set" { if pwd == "" { fmt.Printf("Password: ") @@ -47,12 +49,15 @@ 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 { fmt.Println(res.Password) } - } else if subCmd == "set" { + } else if subCmd == "set" || subCmd == "del" { fmt.Println(green(CharCheck), "Done") } @@ -67,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" @@ -105,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 f2863fd..742dba7 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,21 @@ 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) + } + } + }) + 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) } }