textcmd

package
v0.0.0-...-9c55465 Latest Latest
Warning

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

Go to latest
Published: Apr 10, 2024 License: MIT Imports: 18 Imported by: 0

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")
		c.StrOpt2(&splitOpts.join, "join", "set join char for build output, default is NL", gflag.WithDefault("NL"))
		c.VarOpt2(&splitOpts.get, "get, i", "get values by indexes, multi by comma")

		c.BoolOpt2(&splitOpts.noTrim, "no-trim", "do not trim input text contents")
		c.BoolOpt2(&splitOpts.count, "count, c", "count item number of split strings")
		c.BoolOpt2(&splitOpts.first, "first, f", "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").WithAfterFn(func(a *gflag.CliArg) error {
			splitOpts.text = a.String()
			return nil
		})
	},
	Func: strSplitHandle,
	Help: `
### Sep chars:
 NL             - new line
 TAB            - tab char
 SPACE          - space char
 AS,anySpace    - any space chars, like: space, tab, new line
`,
}

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