refactor: move getHelp to args.go

This commit is contained in:
2024-09-04 03:24:19 +03:00
parent d272aeb6ff
commit 0bb71b5795
2 changed files with 28 additions and 26 deletions

28
args.go
View File

@@ -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

View File

@@ -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.