diff --git a/src/cli/1globals.go b/src/cli/1globals.go index 394ccda..c5625da 100644 --- a/src/cli/1globals.go +++ b/src/cli/1globals.go @@ -6,12 +6,10 @@ import ( "golang.org/x/term" ) -// global variables used across multiple files var ( width, _, _ = term.GetSize(int(os.Stdout.Fd())) ) -// global constants used across multiple files const ( AnsiBold = "\033[1m" ansiBlackOnWhite = "\033[38;5;0;48;5;15m" diff --git a/src/cli/add.go b/src/cli/add.go index 62ebcf6..84f8937 100644 --- a/src/cli/add.go +++ b/src/cli/add.go @@ -8,8 +8,8 @@ import ( "github.com/rwinkhart/libmutton/core" ) -// AddEntry creates a new entry at targetLocation by taking user input via CLI prompts -// entryType: 0 = standard (password), 1 = auto-generated password, 2 = note +// AddEntry creates a new entry at targetLocation by taking user input via CLI prompts. +// Requires: entryType (0 = standard password entry, 1 = auto-generated password entry, 2 = note-only entry). func AddEntry(targetLocation string, hideSecrets bool, entryType uint8) { // ensure target location does not already exist _, isAccessible := core.TargetIsFile(targetLocation, false, 0) diff --git a/src/cli/edit.go b/src/cli/edit.go index ca08e2b..d2cf8e8 100644 --- a/src/cli/edit.go +++ b/src/cli/edit.go @@ -12,7 +12,7 @@ import ( "github.com/rwinkhart/libmutton/sync" ) -// RenameCli renames an entry at oldLocationIncomplete to a new location (user input) on both the client and the server +// RenameCli renames an entry at oldLocationIncomplete to a new location (user input) on both the client and the server. func RenameCli(oldLocationIncomplete string) { // prompt user for new location and rename newLocationIncomplete := input("New location:") @@ -21,7 +21,7 @@ func RenameCli(oldLocationIncomplete string) { // exit is done from sync.RenameRemoteFromClient } -// EditEntryField edits a field of an entry at targetLocation (user input) +// EditEntryField edits a field of an entry at targetLocation (user input). func EditEntryField(targetLocation string, hideSecrets bool, field int) { // fetch old entry data (with all required lines present) unencryptedEntry := core.GetOldEntryData(targetLocation, field) @@ -54,7 +54,7 @@ func EditEntryField(targetLocation string, hideSecrets bool, field int) { writeEntryCLI(targetLocation, unencryptedEntry, hideSecrets, false) } -// GenUpdate generates a new password for an entry at targetLocation (user input) +// GenUpdate generates a new password for an entry at targetLocation (user input). func GenUpdate(targetLocation string, hideSecrets bool) { // fetch old entry data unencryptedEntry := core.GetOldEntryData(targetLocation, 0) @@ -66,8 +66,8 @@ func GenUpdate(targetLocation string, hideSecrets bool) { writeEntryCLI(targetLocation, unencryptedEntry, hideSecrets, false) } -// editNote uses the user-specified text editor to edit an existing note (or create a new one if baseNote is empty) -// returns the edited note and a boolean indicating whether the note was edited +// editNote uses the user-specified text editor to edit an existing note (or create a new one if baseNote is empty). +// Returns the edited note and a boolean indicating whether the note was edited. func editNote(baseNote []string) ([]string, bool) { tempFile := core.CreateTempFile() defer func(name string) { diff --git a/src/cli/entryList.go b/src/cli/entryList.go index 7c7ad9f..890af80 100644 --- a/src/cli/entryList.go +++ b/src/cli/entryList.go @@ -9,14 +9,14 @@ import ( "github.com/rwinkhart/libmutton/sync" ) -// global constants used only in this file +// ANSI color constants used only in this file const ( ansiAlternateEntryColor = "\033[38;5;8m" ansiDirectoryHeader = "\033[38;5;7;48;5;8m" ansiEmptyDirectoryWarning = "\033[38;5;11m" ) -// calculates and returns the final visual indentation multiplier (needed to adjust indentation for skipped parent directories) - also subtracts "old" text from directory header +// determineIndentation calculates and returns the final visual indentation multiplier (needed to adjust indentation for skipped parent directories); also subtracts "old" text from directory header. func determineIndentation(skippedDirList []bool, dirList []string, currentDirIndex int) (int, string) { var subtractor int // tracks how much to subtract from expected indentation multiplier var lastPrefixIndex int // tracks the index (in both skippedDirList and dirList) of the last displayed parent directory @@ -46,7 +46,7 @@ func determineIndentation(skippedDirList []bool, dirList []string, currentDirInd return indent, trimmedDirectory } -// processing for printing file entries (determines color, line wrapping, and prints) +// printFileEntry handles processing for printing file entries (determines color, wraps lines, and prints). func printFileEntry(entry string, lastSlash, charCounter, indent int, colorAlternator int8) (int, int8) { // determine color to print fileEntryName (alternate each time function is run) var colorCode string @@ -77,7 +77,7 @@ func printFileEntry(entry string, lastSlash, charCounter, indent int, colorAlter return charCounter, colorAlternator } -// EntryListGen generates and displays full libmutton entry list +// EntryListGen generates and displays the full libmutton entry list. func EntryListGen() { fileList, dirList := sync.WalkEntryDir() diff --git a/src/cli/entryReader.go b/src/cli/entryReader.go index e11b202..80acc89 100644 --- a/src/cli/entryReader.go +++ b/src/cli/entryReader.go @@ -11,7 +11,7 @@ import ( const ansiShownPassword = "\033[38;5;10m" -// EntryReader prints the decrypted contents of a libmutton entry in a human-readable format +// EntryReader prints the decrypted contents of a libmutton entry in a human-readable format. func EntryReader(decryptedEntry []string, hideSecrets, syncEnabled bool) { fmt.Println() @@ -71,7 +71,7 @@ func EntryReader(decryptedEntry []string, hideSecrets, syncEnabled bool) { os.Exit(0) } -// EntryReaderDecrypt is a wrapper for EntryReader that first decrypts a GPG-encrypted file before sending it to EntryReader +// EntryReaderDecrypt is a wrapper for EntryReader that first decrypts a GPG-encrypted file before sending it to EntryReader. func EntryReaderDecrypt(targetLocation string, hideSecrets bool) { if isFile, _ := core.TargetIsFile(targetLocation, true, 2); isFile { EntryReader(core.DecryptGPG(targetLocation), hideSecrets, false) // never sync if decrypting straight to EntryReader, as this means the entry could not have been modified diff --git a/src/cli/entryReaderMD.go b/src/cli/entryReaderMD.go index a6e9d98..7dddb42 100644 --- a/src/cli/entryReaderMD.go +++ b/src/cli/entryReaderMD.go @@ -8,7 +8,7 @@ import ( "github.com/charmbracelet/glamour" ) -// renderNote renders the notes section of an entry (in Markdown) to stdout +// renderNote renders the notes section of an entry (in Markdown) to stdout. func renderNote(note *string) { r, _ := glamour.NewTermRenderer(glamour.WithStylesFromJSONBytes(glamourStyle()), glamour.WithPreservedNewLines(), glamour.WithWordWrap(width)) markdownNotesString, _ := r.Render(*note) diff --git a/src/cli/entryReaderMDDisabled.go b/src/cli/entryReaderMDDisabled.go index ddad872..d5162ce 100644 --- a/src/cli/entryReaderMDDisabled.go +++ b/src/cli/entryReaderMDDisabled.go @@ -6,7 +6,7 @@ import ( "fmt" ) -// renderNote prints the notes section of an entry to stdout (when Markdown rendering is disabled) +// renderNote prints the notes section of an entry to stdout (when Markdown rendering is disabled). func renderNote(note *string) { fmt.Print("\n" + *note + "\n\n") } diff --git a/src/cli/init.go b/src/cli/init.go index 45761f7..181bcdb 100644 --- a/src/cli/init.go +++ b/src/cli/init.go @@ -10,7 +10,7 @@ import ( "github.com/rwinkhart/libmutton/sync" ) -// TempInitCli initializes the MUTN environment based on user input (will be replaced with a TUI menu) +// TempInitCli initializes the MUTN environment based on user input. func TempInitCli() { // gpgID var gpgID string diff --git a/src/cli/printInfo.go b/src/cli/printInfo.go index b36e2b4..28c37bd 100644 --- a/src/cli/printInfo.go +++ b/src/cli/printInfo.go @@ -7,7 +7,7 @@ import ( "github.com/rwinkhart/libmutton/core" ) -// global constants used only in this file +// ANSI color constants used only in this file const ( ansiVersionMeat = "\033[38;2;157;0;6m" ansiVersionOutline = "\033[38;2;131;165;152m" diff --git a/src/cli/utilitiesMisc.go b/src/cli/utilitiesMisc.go index e429e6d..72a08a4 100644 --- a/src/cli/utilitiesMisc.go +++ b/src/cli/utilitiesMisc.go @@ -10,7 +10,7 @@ import ( "golang.org/x/term" ) -// input prompts the user for input and returns the input as a string +// input prompts the user for input and returns the input as a string. func input(prompt string) string { fmt.Print("\n" + prompt + " ") reader := bufio.NewReader(os.Stdin) @@ -18,7 +18,7 @@ func input(prompt string) string { return strings.TrimRight(userInput, "\n\r ") // remove trailing newlines, carriage returns, and spaces } -// inputHidden prompts the user for input and returns the input as a string, hiding the input from the terminal +// inputHidden prompts the user for input and returns the input as a string, hiding the input from the terminal. func inputHidden(prompt string) string { fmt.Print("\n" + prompt + " ") byteInput, _ := term.ReadPassword(int(os.Stdin.Fd())) @@ -27,8 +27,8 @@ func inputHidden(prompt string) string { return password } -// inputInt prompts the user for input and returns the input as an integer -// a maxValue of 0 will cause the function to return 0, an error - a negative maxValue will disable the maxValue check +// inputInt prompts the user for input and returns the input as an integer. +// A maxValue of 0 will cause the function to return 0, an error - a negative maxValue will disable the maxValue check. func inputInt(prompt string, maxValue int) int { if maxValue == 0 { return 0 @@ -45,7 +45,7 @@ func inputInt(prompt string, maxValue int) int { } } -// inputBinary prompts the user with a yes/no question and returns the response as a boolean +// inputBinary prompts the user with a yes/no question and returns the response as a boolean. func inputBinary(prompt string) bool { reader := bufio.NewReader(os.Stdin) fmt.Print("\n" + prompt + " (y/N) ") @@ -56,7 +56,7 @@ func inputBinary(prompt string) bool { return false } -// inputMenuGen prompts the user with a menu and returns the user's choice as an integer +// inputMenuGen prompts the user with a menu and returns the user's choice as an integer. func inputMenuGen(prompt string, options []string) int { for i, option := range options { fmt.Printf("%d. %s\n", i+1, option) @@ -64,7 +64,7 @@ func inputMenuGen(prompt string, options []string) int { return inputInt(prompt, len(options)) } -// writeEntryCLI writes an entry to targetLocation and previews it (errors if no data is supplied) +// writeEntryCLI writes an entry to targetLocation and previews it (errors if no data is supplied). func writeEntryCLI(targetLocation string, unencryptedEntry []string, hideSecrets, verifyEntryDoesNotExist bool) { if core.EntryIsNotEmpty(unencryptedEntry) { // write the entry to the target location @@ -78,7 +78,7 @@ func writeEntryCLI(targetLocation string, unencryptedEntry []string, hideSecrets } } -// expandPathWithHome, given a path (as a string) containing "~", returns the path with "~" expanded to the user's home directory +// expandPathWithHome, given a path (as a string) containing "~", returns the path with "~" expanded to the user's home directory. func expandPathWithHome(path string) string { return strings.Replace(path, "~", core.Home, 1) }