From 0bb71b5795426c39b6dcb981de2b48b5085ec256 Mon Sep 17 00:00:00 2001 From: Chen Asraf Date: Wed, 4 Sep 2024 03:24:19 +0300 Subject: [PATCH] refactor: move getHelp to args.go --- args.go | 28 ++++++++++++++++++++++++++++ describe.go | 26 -------------------------- 2 files changed, 28 insertions(+), 26 deletions(-) diff --git a/args.go b/args.go index b8c1fd8..ca134bb 100644 --- a/args.go +++ b/args.go @@ -4,11 +4,39 @@ import ( "embed" "fmt" "os" + "strings" ) //go:embed version.txt var VERSION embed.FS +// helpText generates and returns a strings.Builder containing the help text for the program. +// The help text includes usage instructions and descriptions of the available command-line options. +// +// Returns: +// +// strings.Builder - A builder containing the formatted help text. +func helpText() strings.Builder { + LE := getLE() + var builder strings.Builder + builder.WriteString("Usage: treelike [OPTIONS] [TREE-STRUCTURE]" + LE) + builder.WriteString("Prints a tree-like representation of the input." + LE) + builder.WriteString("" + LE) + builder.WriteString("Options:" + LE) + builder.WriteString(" -h, --help Show this help message and exit" + LE) + builder.WriteString(" -V, --version Show the version number and exit" + LE) + builder.WriteString(" -f, --file FILE Read from FILE" + LE) + builder.WriteString(" -, --stdin Read from stdin" + LE) + builder.WriteString(" -c, --charset CHARSET Use CHARSET to display characters (utf-8, ascii)" + LE) + builder.WriteString(" -s, --trailing-slash Display trailing slash on directory" + LE) + builder.WriteString(" -p, --full-path Display full path" + LE) + builder.WriteString(" -r, --root-path Use PATH to change the name of the root node (default: .)" + LE) + builder.WriteString(" N/A if `--no-root-dot` is enabled" + LE) + builder.WriteString(" -D, --no-root-dot Do not display a root element" + LE) + return builder + +} + // getOpts parses command-line arguments and returns an Options struct populated with the parsed values. // It supports various flags to customize the behavior of the program, such as reading from stdin, // specifying a file, setting the charset, and more. If an invalid charset is provided, the function diff --git a/describe.go b/describe.go index 15c7316..a32a4b8 100644 --- a/describe.go +++ b/describe.go @@ -5,32 +5,6 @@ import ( "strings" ) -// helpText generates and returns a strings.Builder containing the help text for the program. -// The help text includes usage instructions and descriptions of the available command-line options. -// -// Returns: -// -// strings.Builder - A builder containing the formatted help text. -func helpText() strings.Builder { - LE := getLE() - var builder strings.Builder - builder.WriteString("Usage: treelike [OPTIONS] [TREE-STRUCTURE]" + LE) - builder.WriteString("Prints a tree-like representation of the input." + LE) - builder.WriteString("" + LE) - builder.WriteString("Options:" + LE) - builder.WriteString(" -h, --help Show this help message and exit" + LE) - builder.WriteString(" -V, --version Show the version number and exit" + LE) - builder.WriteString(" -f, --file FILE Read from FILE" + LE) - builder.WriteString(" -, --stdin Read from stdin" + LE) - builder.WriteString(" -c, --charset CHARSET Use CHARSET to display characters (utf-8, ascii)" + LE) - builder.WriteString(" -s, --trailing-slash Display trailing slash on directory" + LE) - builder.WriteString(" -p, --full-path Display full path" + LE) - builder.WriteString(" -r, --root-path Use PATH to change the name of the root node (default: .)" + LE) - builder.WriteString(" N/A if `--no-root-dot` is enabled" + LE) - builder.WriteString(" -D, --no-root-dot Do not display a root element" + LE) - return builder -} - // describeTree generates a string representation of the tree structure starting from the given node. // It recursively traverses the tree and collects lines representing each node and its children. // The function ensures that blank lines are removed from the final output.