textcmd

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: MIT Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var StrCountCmd = &gcli.Command{
	Name:    "length",
	Aliases: []string{"len", "count"},
	Desc:    "count input string length, with rune length, utf8 length, text width",
	Config: func(c *gcli.Command) {
		c.AddArg("text", "input text contents for process. allow @c,@FILE", true)
	},
	Func: func(c *gcli.Command, _ []string) error {
		src, err := apputil.ReadSource(c.Arg("text").String())
		if err != nil {
			return err
		}

		fmt.Printf(
			"raw length: %d\n - rune len: %d\n - utf8 len: %d\n - width: %d\n",
			len(src),
			len([]rune(src)),
			strutil.Utf8Len(src),
			strutil.TextWidth(src),
		)
		return nil
	},
}

StrCountCmd instance

View Source
var StrSplitCmd = &gcli.Command{
	Name: "split",

	Desc: "split input text to multi parts, then fetch or joins",
	Config: func(c *gcli.Command) {
		splitOpts.get.ValueFn = func(val int) error {
			return goutil.OrError(val >= 0, errorx.Raw("get index cannot be < 0"))
		}

		c.StrOpt2(&splitOpts.sep, "sep,s", "set sep char for split input. if not set, will auto detect available char.")
		c.VarOpt2(&splitOpts.get, "get, i", "get values by indexes, multi by comma")

		c.BoolOpt2(&splitOpts.inline, "inline", "inline output result, dont end with NL")
		c.StrOpt2(&splitOpts.join, "join", "set join char for build output", gflag.WithDefault("NL"))
		c.StrOpt2(&splitOpts.format, "format", "format output result, use $0, $1, ... $N")

		c.BoolOpt2(&splitOpts.noTrim, "no-trim", "do not trim input text contents")
		c.BoolOpt2(&splitOpts.noTrimItems, "no-trim-items", "do not trim each item contents")

		c.BoolOpt2(&splitOpts.count, "count, c", "count item number of split strings")
		c.BoolOpt2(&splitOpts.first, "first, 0", "get first part from split strings")
		c.BoolOpt2(&splitOpts.last, "last, l", "get last part from split strings")

		c.AddArg("text", "input text contents for handle. allow use: @c, @i").WithAfterFn(func(a *gflag.CliArg) error {
			splitOpts.text = a.String()
			return nil
		})
	},
	Func: strSplitHandle,
	Help: `
<green>### Sep Chars</>:
 NL             - new line
 TAB            - tab char
 SPACE          - space char
 AS,anySpace    - any space chars, like: space, tab, new line
`,
	Examples: `
# custom output format
{$binWithCmd} --last 'a b c' # Output: c
{$binWithCmd} --first 'a b c' # Output: a
{$binWithCmd} --format '$0,$2' 'a b c' # Output: a,c
`,
}

StrSplitCmd instance

View Source
var TextToolCmd = &gcli.Command{
	Name:    "text",
	Desc:    "useful commands for handle string text",
	Aliases: []string{"txt", "str", "string"},
	Subs: []*gcli.Command{
		StrCountCmd,
		StrSplitCmd,
		NewStrMatchCmd(),
		NewTextParseCmd(),
		NewTextSearchCmd(),
		NewReplaceCmd(),
		NewMd5Cmd(),
		NewHashCmd(),
		NewUuidCmd(),
		NewRandomStrCmd(),
		NewStringJoinCmd(),
		NewTemplateCmd(false),
		convcmd.NewTime2dateCmd(),
	},
}

TextToolCmd instance

Functions

func NewHashCmd

func NewHashCmd() *gcli.Command

NewHashCmd instance

func NewMd5Cmd

func NewMd5Cmd() *gcli.Command

NewMd5Cmd instance

func NewProcessCmd

func NewProcessCmd() *gcli.Command

NewProcessCmd create a new ProcessCmd instance 实现处理输入文本内容

func NewRandomStrCmd

func NewRandomStrCmd() *gcli.Command

NewRandomStrCmd create command

func NewReplaceCmd

func NewReplaceCmd() *gcli.Command

NewReplaceCmd new command

func NewStrMatchCmd

func NewStrMatchCmd() *gcli.Command

NewStrMatchCmd create

func NewStringJoinCmd

func NewStringJoinCmd() *gcli.Command

NewStringJoinCmd new command

func NewTemplateCmd

func NewTemplateCmd(mustFile bool) *gcli.Command

NewTemplateCmd instance

func NewTextParseCmd

func NewTextParseCmd() *gcli.Command

NewTextParseCmd create

func NewTextSearchCmd

func NewTextSearchCmd() *gcli.Command

NewTextSearchCmd instance

func NewUuidCmd

func NewUuidCmd() *gcli.Command

NewUuidCmd create command

Types

This section is empty.

Jump to

Keyboard shortcuts

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