helper

package
v3.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2022 License: MIT Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// RegGoodName match a good option, argument name
	RegGoodName = `^[a-zA-Z][\w-]*$`
	// RegGoodCmdName match a good command name
	RegGoodCmdName = `^[a-zA-Z][\w-]*$`
	// RegGoodCmdId match command id. eg: "self:init"
	RegGoodCmdId = `^[a-zA-Z][\w:-]*$`
)
View Source
const HelpVarFormat = "{$%s}"

HelpVarFormat allow var replace on render help info.

Default support:

"{$binName}" "{$cmd}" "{$fullCmd}" "{$workDir}"

Variables

This section is empty.

Functions

func Download

func Download(url, saveDir string, rename ...string) error

Download file from remote URL. from https://gist.github.com/albulescu/e61979cc852e4ee8f49c

func GetTerminalSize

func GetTerminalSize(refresh ...bool) (w int, h int)

GetTerminalSize for current console terminal.

func IsGoodCmdId added in v3.1.0

func IsGoodCmdId(name string) bool

IsGoodCmdId check

func IsGoodCmdName added in v3.1.0

func IsGoodCmdName(name string) bool

IsGoodCmdName check

func IsGoodName added in v3.1.0

func IsGoodName(name string) bool

IsGoodName check

func Panicf added in v3.1.0

func Panicf(format string, v ...any)

Panicf message

func RenderText

func RenderText(input string, data any, fns template.FuncMap, isFile ...bool) string

RenderText render text template with data. TODO use strutil.RenderText()

func SimpleDownload

func SimpleDownload(url, saveAs string) (err error)

SimpleDownload simple download

Types

type Downloader

type Downloader struct {
	FileURL  string
	SaveDir  string
	Filename string // save file name.
	Progress bool   // display progress info
	// contains filtered or unexported fields
}

Downloader struct definition. refer: https://gist.github.com/albulescu/e61979cc852e4ee8f49c

func (*Downloader) Download

func (d *Downloader) Download() error

Download begin

type HelpVars added in v3.1.0

type HelpVars struct {
	VarOpen, VarClose string

	// Vars you can add some vars map for render help info. TODO rename replaces/pairs
	Vars map[string]string
}

HelpVars struct. provide string var function for render help template.

func (*HelpVars) AddVar added in v3.1.0

func (hv *HelpVars) AddVar(name, value string)

AddVar get command name

func (*HelpVars) AddVars added in v3.1.0

func (hv *HelpVars) AddVars(vars map[string]string)

AddVars add multi tpl vars

func (*HelpVars) GetVar added in v3.1.0

func (hv *HelpVars) GetVar(name string) string

GetVar get a help var by name

func (*HelpVars) GetVars added in v3.1.0

func (hv *HelpVars) GetVars() map[string]string

GetVars get all tpl vars

func (*HelpVars) ReplaceVars added in v3.1.0

func (hv *HelpVars) ReplaceVars(input string) string

ReplaceVars replace vars in the input string.

Jump to

Keyboard shortcuts

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