From 26a5898e1515ba2b310b8fb9380736c93aeb6622 Mon Sep 17 00:00:00 2001 From: Randall Winkhart Date: Mon, 18 Mar 2024 12:59:18 -0400 Subject: [PATCH] Better document new blank option="password" shortcut, order arguments in order of expected use, list passwords first in entry reader --- extra/completion.bash | 2 +- extra/completion.ps1 | 2 +- extra/completion.zsh | 2 +- main.go | 20 ++++++++++---------- src/cli/entryReader.go | 16 +++++----------- src/cli/printInfo.go | 40 ++++++++++++++++++++-------------------- 6 files changed, 38 insertions(+), 44 deletions(-) diff --git a/extra/completion.bash b/extra/completion.bash index f4902c5..d854af2 100644 --- a/extra/completion.bash +++ b/extra/completion.bash @@ -21,7 +21,7 @@ _mutn_completions() { while read -r; do ITEM=${REPLY// /\\ }; COMPREPLY+=( "$ITEM" ); done < <( compgen -W "$(printf "'%s' " "${trimmed_paths[@]}")" -- "$cur" ) ;; /* ) - while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "add gen edit copy shear" -- "$cur" ) + while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "copy edit gen add shear" -- "$cur" ) ;; add ) while read -r; do COMPREPLY+=( "$REPLY" ); done < <( compgen -W "password note folder" -- "$cur" ) diff --git a/extra/completion.ps1 b/extra/completion.ps1 index 0fa585d..9edb418 100644 --- a/extra/completion.ps1 +++ b/extra/completion.ps1 @@ -33,7 +33,7 @@ function mutn { [string]$entry, [Parameter(Position = 1)] - [ArgumentCompletions('add', 'gen', 'edit', 'copy', 'shear')] + [ArgumentCompletions('copy', 'edit', 'gen', 'add', 'shear')] [string]$argument, [Parameter(Position = 2, ValueFromRemainingArguments=$true)] diff --git a/extra/completion.zsh b/extra/completion.zsh index a1549ea..6d16b34 100644 --- a/extra/completion.zsh +++ b/extra/completion.zsh @@ -13,7 +13,7 @@ case ${words[-2]} in compadd $trimmed_paths ;; /* ) - compadd {add,gen,edit,copy,shear} + compadd {copy,edit,gen,add,shear} ;; add ) compadd {password,note,folder} diff --git a/main.go b/main.go index 61894aa..3cc1661 100644 --- a/main.go +++ b/main.go @@ -34,25 +34,25 @@ func main() { 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 "gen": + cli.AddEntry(targetLocation, true, 1) case "add": cli.AddEntry(targetLocation, true, 0) + case "shear": + offline.Shear(targetLocation) 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 "gen": + cli.AddEntry(targetLocation, false, 1) case "add": cli.AddEntry(targetLocation, false, 0) default: @@ -175,14 +175,14 @@ func main() { fmt.Println(offline.AnsiError + "\"tweak\" is not yet implemented" + offline.AnsiReset) os.Exit(0) // TODO offline.Tweak() - case "add": - cli.HelpAdd() - case "edit": - cli.HelpEdit() case "copy": cli.HelpCopy() + case "edit": + cli.HelpEdit() case "gen": cli.HelpGen() + case "add": + cli.HelpAdd() case "version", "-v": cli.Version() default: diff --git a/src/cli/entryReader.go b/src/cli/entryReader.go index 3ba9de9..25d29d9 100644 --- a/src/cli/entryReader.go +++ b/src/cli/entryReader.go @@ -16,19 +16,8 @@ func EntryReader(decryptedEntry []string, hidePassword bool, sync bool) { var notesFlag bool for i := range decryptedEntry { - - // if the entry only contains a password, skip the username field to avoid an index out of range error - if len(decryptedEntry) == 1 { - i = 1 - } - switch i { case 0: - // if the second field (username) is not empty, print it - if decryptedEntry[1] != "" { - fmt.Print(ansiDirectoryHeader + "Username:" + offline.AnsiReset + "\n" + decryptedEntry[1] + "\n\n") - } - case 1: // if the first field (password) is not empty, print it if decryptedEntry[0] != "" { if !hidePassword { @@ -37,6 +26,11 @@ func EntryReader(decryptedEntry []string, hidePassword bool, sync bool) { fmt.Print(ansiDirectoryHeader + "Password:" + offline.AnsiReset + "\n" + ansiEmptyDirectoryWarning + "End command in \"show\" or \"-s\" to view" + offline.AnsiReset + "\n\n") } } + case 1: + // if the second field (username) is not empty, print it + if decryptedEntry[1] != "" { + fmt.Print(ansiDirectoryHeader + "Username:" + offline.AnsiReset + "\n" + decryptedEntry[1] + "\n\n") + } case 2: // if the third field (url) is not empty, print it if decryptedEntry[2] != "" { diff --git a/src/cli/printInfo.go b/src/cli/printInfo.go index d751a29..05c0d65 100644 --- a/src/cli/printInfo.go +++ b/src/cli/printInfo.go @@ -24,35 +24,35 @@ This program comes with absolutely no warranty; type "mutn version" for details. version|-v Display version and license information init Set up MUTN (generates libmutton.ini) tweak Change configuration options - add Add an entry - gen Generate a new password - edit Edit an existing entry copy Copy details of an entry to your clipboard + edit Edit an existing entry + gen Generate a new password + add Add an entry shear Delete an existing entry sync Manually sync the entry directory ` + ansiBold + "Options:" + offline.AnsiReset + ` - add: - password|-pw Add a password entry - note|-n Add a note entry - folder|-f Add a new folder for entries - edit: - 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: + password|-pw| Copy the password 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 + edit: + password|-pw| Change the password of an entry + username|-u Change the username of an entry + url|-l Change the url attached to an entry + note|-n Change the note attached to an entry + rename|-r Rename or relocate an entry gen: update|-u Generate a password for an existing entry + add: + password|-pw| Add a password entry + note|-n Add a note entry + folder|-f Add a new folder for entries ` + 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 ` + ansiBold + "Tip 4:" + offline.AnsiReset + " Using \"add\", \"edit\", or \"copy\" without specifying an option (field) will default to \"password\"\n\n") os.Exit(0) } @@ -62,7 +62,7 @@ func HelpAdd() { ` + ansiBold + "Options:" + offline.AnsiReset + ` add: - password|-pw Add a password entry + 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) @@ -73,11 +73,11 @@ func HelpEdit() { ` + ansiBold + "Options:" + offline.AnsiReset + ` edit: - rename|-r Rename or relocate an entry + password|-pw| Change the password of 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") + note|-n Change the note attached to an entry + rename|-r Rename or relocate an entry` + "\n\n") os.Exit(0) } @@ -86,8 +86,8 @@ func HelpCopy() { ` + ansiBold + "Options:" + offline.AnsiReset + ` copy: + password|-pw| Copy the password in an entry to your clipboard 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)