cmdline

package
v0.7.1 Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2025 License: MIT Imports: 7 Imported by: 1

Documentation

Overview

Package cmdline provide quick build and parse cmd line string.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LineBuild

func LineBuild(binFile string, args []string) string

LineBuild build command line string by given args.

func ParseLine

func ParseLine(line string) []string

ParseLine input command line text. alias of the StringToOSArgs()

func Quote added in v0.7.0

func Quote(s string) string

Quote string in shell command env

Types

type LineBuilder

type LineBuilder struct {
	strings.Builder
}

LineBuilder build command line string. codes refer from strings.Builder

func NewBuilder

func NewBuilder(binFile string, args ...string) *LineBuilder

NewBuilder create

func (*LineBuilder) AddAny added in v0.6.7

func (b *LineBuilder) AddAny(args ...any)

AddAny args to builder

func (*LineBuilder) AddArg

func (b *LineBuilder) AddArg(arg string)

AddArg to builder

func (*LineBuilder) AddArgs

func (b *LineBuilder) AddArgs(args ...string)

AddArgs to builder

func (*LineBuilder) AddArray

func (b *LineBuilder) AddArray(args []string)

AddArray to builder

func (*LineBuilder) ResetGet added in v0.7.0

func (b *LineBuilder) ResetGet() string

ResetGet value, will reset after get.

func (*LineBuilder) WriteString

func (b *LineBuilder) WriteString(a string) (int, error)

WriteString arg string to the builder, will auto quote special string. refer strconv.Quote()

type LineParser

type LineParser struct {

	// Line the full input command line text
	// eg `kite top sub -a "this is a message" --foo val1 --bar "val 2"`
	Line string
	// ParseEnv parse ENV var on the line.
	ParseEnv bool
	// contains filtered or unexported fields
}

LineParser struct parse input command line to []string, such as cli os.Args

func NewParser

func NewParser(line string) *LineParser

NewParser create

func (*LineParser) AlsoEnvParse

func (p *LineParser) AlsoEnvParse() []string

AlsoEnvParse input command line text to os.Args, will parse ENV var

func (*LineParser) BinAndArgs

func (p *LineParser) BinAndArgs() (bin string, args []string)

BinAndArgs get binName and args

func (*LineParser) NewExecCmd

func (p *LineParser) NewExecCmd() *exec.Cmd

NewExecCmd quick create exec.Cmd by cmdline string

func (*LineParser) Parse

func (p *LineParser) Parse() []string

Parse input command line text to os.Args

func (*LineParser) WithParseEnv added in v0.6.6

func (p *LineParser) WithParseEnv() *LineParser

WithParseEnv with parse ENV var

Jump to

Keyboard shortcuts

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