Skip to content

Tiny tweaks ('del'ete and show login) #7

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
14 changes: 13 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
```

```
Expand Down
13 changes: 9 additions & 4 deletions cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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: ")
Expand All @@ -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")
}

Expand All @@ -67,7 +72,7 @@ func processDataCmd(subCmd, context, filename string, progressFunc ProgressCb) (
},
}

if subCmd == "get" {
if subCmd == "get" || subCmd == "del" {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's wrong... To delete a credential you need to put the device into "Memory Management Mode", and deal with the MMM api then. Your path add a del command that does the same as get... What the point?

m.Msg = "get_data_node"
} else if subCmd == "set" {
m.Msg = "set_data_node"
Expand Down Expand Up @@ -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")
}

Expand Down
26 changes: 21 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ var (
optPass *string
optDesc *string
optPrintDesc *bool
optLoginDesc *bool
optFilename *string
optParameter *string
optValue *string
Expand Down Expand Up @@ -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)
}
}
Expand All @@ -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)
}
}
Expand Down