cliutils

package module
v2.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 7, 2022 License: Apache-2.0 Imports: 6 Imported by: 0

README

cliutils

Helpers for github.com/urfave/cli/v2.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppFrom

func AppFrom(cmd *cli.Command, version string) *cli.App

Create a cli.App from a cli.Command.

func Dedent

func Dedent(s string) string

Dedent identifies the most common leading indention and purges it

func HelpFmt

func HelpFmt(s string) string

HelpFmt handles formatting help output for things such as descriptions.

1. Shared indentation in the help string that may occur from tabbed code is dedented. 2. Leading and trailing whitespace is trimmed. 3. Text is wrapped at 80 characters for that "book-like" feel.

func ReqArgCount

func ReqArgCount(c *cli.Context, required_arg_count int) error

ReqArgCount is a helper function for urfave/cli/v2 It is used as an alias to check if a required number of arguments is passed to the command via the cli context.

The reason to use this is to standardize the exit code as well as the error output. Having the common string in one place is better than manually writing this small condition and string many times across a code-base.

func Wrap

func Wrap(str string, wrapLength int) string

Wrap wraps a single line of text, identifying words by ' '. New lines will be separated by '\n'. Very long words, such as URLs will not be wrapped. Leading spaces on a new line are stripped. Trailing spaces are not stripped.

Parameters:

str - the string to be word wrapped
wrapLength - the column (a column can fit only one character) to wrap the words at, less than 1 is treated as 1

Returns:

a line with newlines inserted

Original source: https://github.com/Masterminds/goutils/blob/f1923532a168b8203bfe956d8cd3b17ebece5982/wordutils.go#L71-L73

func WrapCustom

func WrapCustom(str string, wrapLength int, newLineStr string, wrapLongWords bool) string

WrapCustom wraps a single line of text, identifying words by ' '. Leading spaces on a new line are stripped. Trailing spaces are not stripped.

Parameters:

str - the string to be word wrapped
wrapLength - the column number (a column can fit only one character) to wrap the words at, less than 1 is treated as 1
newLineStr - the string to insert for a new line, "" uses '\n'
wrapLongWords - true if long words (such as URLs) should be wrapped

Returns:

a line with newlines inserted

Original source: https://github.com/Masterminds/goutils/blob/f1923532a168b8203bfe956d8cd3b17ebece5982/wordutils.go#L88-L150

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL