mirror of
https://github.com/rwinkhart/MUTN.git
synced 2026-08-28 04:46:41 -04:00
Properly format function documentation comments
This commit is contained in:
@@ -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"
|
||||
|
||||
+2
-2
@@ -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)
|
||||
|
||||
+5
-5
@@ -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) {
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user