From dd0d1ffe55a181aa86c1a3e2248add767e8ff980 Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Sun, 17 Mar 2024 17:32:13 -0400 Subject: [PATCH] Revert use of ":" for options on Windows, use "-" but replace "-p" with "-pw" to avoid ambiguity, interpret no options as "password" --- extra/completion.ps1 | 11 ++--- main.go | 86 ++++++++++++++++++++++------------------ src/cli/entryReader.go | 2 +- src/cli/printInfo.go | 59 +++++++++++++-------------- src/cli/printInfoUNIX.go | 5 --- src/cli/printInfoWIN.go | 5 --- 6 files changed, 83 insertions(+), 85 deletions(-) delete mode 100644 src/cli/printInfoUNIX.go delete mode 100644 src/cli/printInfoWIN.go diff --git a/extra/completion.ps1 b/extra/completion.ps1 index 9b96a13..0fa585d 100644 --- a/extra/completion.ps1 +++ b/extra/completion.ps1 @@ -36,14 +36,11 @@ function mutn { [ArgumentCompletions('add', 'gen', 'edit', 'copy', 'shear')] [string]$argument, - [Parameter(Position = 2)] + [Parameter(Position = 2, ValueFromRemainingArguments=$true)] [ArgumentCompleter({ MUTNOptionCompleter @args })] - [string]$option, - - [Parameter(Position = 3)] - [string]$potentialShowFlag + [string]$option ) - #Invoke-Expression -Command ('/usr/local/bin/mutn ' + ($entry -replace ' ', '` '), $argument, ($option -replace ':', '-'), ($potentialShowFlag -replace ':', '-')).Trim() # UNIX testing - Invoke-Expression -Command ('./mutn.exe ' + ($entry -replace ' ', '` '), $argument, $option, $potentialShowFlag).Trim() + #Invoke-Expression -Command ('/usr/local/bin/mutn ' + ($entry -replace ' ', '` '), $argument, $option).Trim() # UNIX testing + Invoke-Expression -Command ('./mutn.exe ' + ($entry -replace ' ', '` '), $argument, $option).Trim() } diff --git a/main.go b/main.go index 7e55114..61894aa 100644 --- a/main.go +++ b/main.go @@ -29,23 +29,35 @@ func main() { if argsCount == 2 { cli.EntryReaderShortcut(targetLocation, true, false) // perform other operations on the entry (if other arguments are supplied) - } else if argsCount == 3 { - - switch args[2] { - case "show", cli.OptionFlag + "s": - cli.EntryReaderShortcut(targetLocation, false, false) - case "shear": - offline.Shear(targetLocation) - case "gen": - cli.AddEntry(targetLocation, true, 1) - case "copy": - cli.HelpCopy() - case "edit": - cli.HelpEdit() - case "add": - cli.HelpAdd() - default: - cli.HelpMain() + } else if argsCount == 3 || (argsCount == 4 && (args[3] == "show" || args[3] == "-s")) { + if argsCount == 3 { // default to "password" if no field is specified (for copy, edit, and add) + switch args[2] { + case "show", "-s": + cli.EntryReaderShortcut(targetLocation, false, false) + case "shear": + offline.Shear(targetLocation) + case "gen": + cli.AddEntry(targetLocation, true, 1) + case "copy": + offline.CopyArgument(targetLocation, 0, args[0]) + case "edit": + cli.EditEntry(targetLocation, true, 0) + case "add": + cli.AddEntry(targetLocation, true, 0) + default: + cli.HelpMain() + } + } else { // handle "show" or "-s" argument for gen, edit, and add + switch args[2] { + case "gen": + cli.AddEntry(targetLocation, false, 1) + case "edit": + cli.EditEntry(targetLocation, false, 0) + case "add": + cli.AddEntry(targetLocation, false, 0) + default: + cli.HelpMain() + } } } else if argsCount >= 4 { @@ -56,13 +68,13 @@ func main() { case "copy": var field int // indicates which (numbered) field to copy switch args[3] { - case "password", cli.OptionFlag + "p": + case "password", "-pw": field = 0 - case "username", cli.OptionFlag + "u": + case "username", "-u": field = 1 - case "url", cli.OptionFlag + "l": + case "url", "-l": field = 2 - case "note", cli.OptionFlag + "n": + case "note", "-n": field = 3 default: cli.HelpCopy() @@ -71,24 +83,24 @@ func main() { case "edit": var field int // indicates which field to edit switch args[3] { - case "password", cli.OptionFlag + "p": + case "password", "-pw": field = 0 - case "username", cli.OptionFlag + "u": + case "username", "-u": field = 1 - case "url", cli.OptionFlag + "l": + case "url", "-l": field = 2 - case "note", cli.OptionFlag + "n": + case "note", "-n": if argsCount == 4 { cli.EditEntryNote(targetLocation, true) } else { switch args[4] { - case "show", cli.OptionFlag + "s": + case "show", "-s": cli.EditEntryNote(targetLocation, false) default: cli.EditEntryNote(targetLocation, true) } } - case "rename", cli.OptionFlag + "r": + case "rename", "-r": cli.RenameCli(targetLocation) default: cli.HelpEdit() @@ -97,7 +109,7 @@ func main() { cli.EditEntry(targetLocation, true, field) } else { switch args[4] { - case "show", cli.OptionFlag + "s": + case "show", "-s": cli.EditEntry(targetLocation, false, field) default: cli.EditEntry(targetLocation, true, field) @@ -106,16 +118,14 @@ func main() { case "gen": if argsCount == 4 { switch args[3] { - case "show", cli.OptionFlag + "s": - cli.AddEntry(targetLocation, false, 1) - case "update", cli.OptionFlag + "u": + case "update", "-u": cli.GenUpdate(targetLocation, true) default: cli.HelpGen() } - } else if args[3] == "update" || args[3] == cli.OptionFlag+"u" { + } else if args[3] == "update" || args[3] == "-u" { switch args[4] { - case "show", cli.OptionFlag + "s": + case "show", "-s": cli.GenUpdate(targetLocation, false) default: cli.GenUpdate(targetLocation, true) @@ -124,20 +134,20 @@ func main() { cli.HelpGen() case "add": switch args[3] { - case "password", cli.OptionFlag + "p": + case "password", "-pw": if argsCount == 4 { cli.AddEntry(targetLocation, true, 0) } else { switch args[4] { - case "show", cli.OptionFlag + "s": + case "show", "-s": cli.AddEntry(targetLocation, false, 0) default: cli.AddEntry(targetLocation, true, 0) } } - case "note", cli.OptionFlag + "n": + case "note", "-n": cli.AddEntry(targetLocation, true, 2) - case "folder", cli.OptionFlag + "f": + case "folder", "-f": offline.AddFolder(targetLocation) default: cli.HelpAdd() @@ -173,7 +183,7 @@ func main() { cli.HelpCopy() case "gen": cli.HelpGen() - case "version", cli.OptionFlag + "v": + case "version", "-v": cli.Version() default: cli.HelpMain() diff --git a/src/cli/entryReader.go b/src/cli/entryReader.go index 30e8e39..3ba9de9 100644 --- a/src/cli/entryReader.go +++ b/src/cli/entryReader.go @@ -34,7 +34,7 @@ func EntryReader(decryptedEntry []string, hidePassword bool, sync bool) { if !hidePassword { fmt.Print(ansiDirectoryHeader + "Password:" + offline.AnsiReset + "\n" + ansiShownPassword + decryptedEntry[0] + offline.AnsiReset + "\n\n") } else { - fmt.Print(ansiDirectoryHeader + "Password:" + offline.AnsiReset + "\n" + ansiEmptyDirectoryWarning + "End command in \"show\" or \"" + OptionFlag + "s\" to view" + offline.AnsiReset + "\n\n") + fmt.Print(ansiDirectoryHeader + "Password:" + offline.AnsiReset + "\n" + ansiEmptyDirectoryWarning + "End command in \"show\" or \"-s\" to view" + offline.AnsiReset + "\n\n") } } case 2: diff --git a/src/cli/printInfo.go b/src/cli/printInfo.go index 8f43701..d751a29 100644 --- a/src/cli/printInfo.go +++ b/src/cli/printInfo.go @@ -20,8 +20,8 @@ This program comes with absolutely no warranty; type "mutn version" for details. ` + ansiBold + "Usage:" + offline.AnsiReset + ` mutn [/ [argument] [option]] | [argument] ` + ansiBold + "Arguments:" + offline.AnsiReset + ` - help|` + OptionFlag + `h Bring up this menu - version|` + OptionFlag + `v Display version and license information + help|-h Bring up this menu + version|-v Display version and license information init Set up MUTN (generates libmutton.ini) tweak Change configuration options add Add an entry @@ -33,26 +33,27 @@ This program comes with absolutely no warranty; type "mutn version" for details. ` + ansiBold + "Options:" + offline.AnsiReset + ` add: - password|` + OptionFlag + `p Add a password entry - note|` + OptionFlag + `n Add a note entry - folder|` + OptionFlag + `f Add a new folder for entries + password|-pw Add a password entry + note|-n Add a note entry + folder|-f Add a new folder for entries edit: - rename|` + OptionFlag + `r Rename or relocate an entry - username|` + OptionFlag + `u Change the username of an entry - password|` + OptionFlag + `p Change the password of an entry - url|` + OptionFlag + `l Change the url attached to an entry - note|` + OptionFlag + `n Change the note attached to an entry + rename|-r Rename or relocate an entry + username|-u Change the username of an entry + password|-pw Change the password of an entry + url|-l Change the url attached to an entry + note|-n Change the note attached to an entry copy: - username|` + OptionFlag + `u Copy the username of an entry to your clipboard - password|` + OptionFlag + `p Copy the password of an entry to your clipboard - url|` + OptionFlag + `l Copy the url of an entry to your clipboard - note|` + OptionFlag + `n Copy the note of an entry to your clipboard + username|-u Copy the username of an entry to your clipboard + password|-pw Copy the password of an entry to your clipboard + url|-l Copy the url of an entry to your clipboard + note|-n Copy the note of an entry to your clipboard gen: - update|` + OptionFlag + `u Generate a password for an existing entry + update|-u Generate a password for an existing entry ` + ansiBold + "Tip 1:" + offline.AnsiReset + ` You can quickly read an entry with "mutn /" ` + ansiBold + "Tip 2:" + offline.AnsiReset + ` Type "mutn" (no arguments/options) to view a list of saved entries -` + ansiBold + "Tip 3:" + offline.AnsiReset + " Provide \"add\", \"edit\", \"copy\", or \"gen\" as the only argument to receive more specific help\n\n") +` + ansiBold + "Tip 3:" + offline.AnsiReset + ` Provide "add", "edit", "copy", or "gen" as the only argument to receive more specific help\n\n +` + ansiBold + "Tip 4:" + offline.AnsiReset + " Using \"add\", \"edit\", or \"copy\" without specifying an option (field) will default to \"password\"\n\n") os.Exit(0) } @@ -61,9 +62,9 @@ func HelpAdd() { ` + ansiBold + "Options:" + offline.AnsiReset + ` add: - password|` + OptionFlag + `p Add a password entry - note|` + OptionFlag + `n Add a note entry - folder|` + OptionFlag + `f Add a new folder for entries` + "\n\n") + password|-pw Add a password entry + note|-n Add a note entry + folder|-f Add a new folder for entries` + "\n\n") os.Exit(0) } @@ -72,11 +73,11 @@ func HelpEdit() { ` + ansiBold + "Options:" + offline.AnsiReset + ` edit: - rename|` + OptionFlag + `r Rename or relocate an entry - username|` + OptionFlag + `u Change the username of an entry - password|` + OptionFlag + `p Change the password of an entry - url|` + OptionFlag + `l Change the url attached to an entry - note|` + OptionFlag + `n Change the note attached to an entry` + "\n\n") + rename|-r Rename or relocate an entry + username|-u Change the username of an entry + password|-pw Change the password of an entry + url|-l Change the url attached to an entry + note|-n Change the note attached to an entry` + "\n\n") os.Exit(0) } @@ -85,10 +86,10 @@ func HelpCopy() { ` + ansiBold + "Options:" + offline.AnsiReset + ` copy: - username|` + OptionFlag + `u Copy the username in an entry to your clipboard - password|` + OptionFlag + `p Copy the password in an entry to your clipboard - url|` + OptionFlag + `l Copy the url in an entry to your clipboard - note|` + OptionFlag + `n Copy the first note line in an entry to your clipboard` + "\n\n") + username|-u Copy the username in an entry to your clipboard + password|-pw Copy the password in an entry to your clipboard + url|-l Copy the url in an entry to your clipboard + note|-n Copy the first note line in an entry to your clipboard` + "\n\n") os.Exit(0) } @@ -97,7 +98,7 @@ func HelpGen() { ` + ansiBold + "Options:" + offline.AnsiReset + ` gen: - update|` + OptionFlag + `u Generate a password for an existing entry + update|-u Generate a password for an existing entry ` + ansiBold + "Tip:" + offline.AnsiReset + " If no options are provided, a new password entry is generated\n\n") os.Exit(0) diff --git a/src/cli/printInfoUNIX.go b/src/cli/printInfoUNIX.go deleted file mode 100644 index 6b57567..0000000 --- a/src/cli/printInfoUNIX.go +++ /dev/null @@ -1,5 +0,0 @@ -//go:build !windows - -package cli - -const OptionFlag = "-" diff --git a/src/cli/printInfoWIN.go b/src/cli/printInfoWIN.go deleted file mode 100644 index c10e3a7..0000000 --- a/src/cli/printInfoWIN.go +++ /dev/null @@ -1,5 +0,0 @@ -//go:build windows - -package cli - -const OptionFlag = ":"