Categorygithub.com/gobs/args
modulepackage
0.0.0-20210311043657-b8c0b223be93
Repository: https://github.com/gobs/args.git
Documentation: pkg.go.dev

# README

args

command line argument parser

Given a string (the "command line") it splits into words separated by white spaces, respecting quotes (single and double) and the escape character (backslash)

Installation

$ go get github.com/gobs/args

Documentation

http://godoc.org/github.com/gobs/args

Example

import "github.com/gobs/args"

s := `one two three "double quotes" 'single quotes' arg\ with\ spaces "\"quotes\" in 'quotes'" '"quotes" in \'quotes'"`

for i, arg := range GetArgs(s) {
	fmt.Println(i, arg)
}

You can also "parse" the arguments and divide them in "options" and "parameters":

import "github.com/gobs/args"

s := "-l --number=42 -where=here -- -not-an-option- one two three"
parsed := ParseArgs(s)

fmt.Println("options:", parsed.Options)
fmt.Println("arguments:", parsed.Arguments)

Or parse using flag.FlagSet:

import "github.com/gobs/args"

s := "-l --number=42 -where=here -- -not-an-option- one two three"
flags := args.NewFlags("test")

list := flags.Bool("l", false, "list something")
num := flags.Int("number", 0, "a number option")
where := flags.String("where", "", "a string option")

flags.Usage()

args.ParseFlags(flags, s)

fmt.Println("list:", *list)
fmt.Println("num:", *num)
fmt.Println("where:", *where)
fmt.Println("args:", flags.Args())

# Functions

Parse the input line into an array of arguments.
Parse the input line into an array of max n arguments.
No description provided by the author
InfieldBrackets enable processing of in-field brackets (i.e.
Create a new FlagSet to be used with ParseFlags.
Creates a new Scanner with io.Reader as input source.
Creates a new Scanner with a string as input source.
No description provided by the author
Parse the input line through the (initialized) FlagSet.
UserTokens allows a client to define a list of tokens (runes) that can be used as additional separators.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Variables

No description provided by the author

# Structs

No description provided by the author
No description provided by the author

# Type aliases

GetArgsOption is the type for GetArgs options.