flags

package
v1.4.5 Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2019 License: GPL-2.0, GPL-2.0-or-later Imports: 0 Imported by: 0

README

Package flags parses boolean options from command arguments.


© 2015-2016 Platina Systems, Inc. All rights reserved. Use of this source code is governed by this BSD-style LICENSE.

Documentation

Overview

Package flags parses boolean options from command arguments.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Aliases

type Aliases map[string]string

type ByName

type ByName map[string]bool

type Flags

type Flags struct {
	ByName ByName
	// contains filtered or unexported fields
}

func New

func New(args []string, flags ...interface{}) (*Flags, []string)

Define and parse boolean flags from command arguments.

If an argument has a leading hyphen ('-') followed by runes that all match '-?' flags, the respective flags are set and the argument is removed from the returned list, e.g.

flag, args := flags.New([]string{"-abc"}, "-a", "-b", "-c")

results in

flag.ByName("-a") == true
flag.ByName("-b") == true
flag.ByName("-c") == true
args == []string{}

whereas

flag, args := flags.New([]string{"-abcd"}, "-a", "-b", "-c")

results in

flag.ByName["-a"] == false
flag.ByName["-b"] == false
flag.ByName["-c"] == false
args == []string{"-abcd"}

Flags may be defined with strings or string slices that include aliases of the first entry, e.g.

flag, args := flags.New([]string{"-color"}, "-a", "-b",
	[]string{"-c", "-color", "-colour"})

results in

flag.ByName("-a") == false
flag.ByName("-b") == false
flag.ByName("-c") == true
args == []string{}

func (*Flags) More

func (p *Flags) More(args []string, flags ...interface{}) []string

Define and parse more flags from command arguments.

func (*Flags) Parse

func (p *Flags) Parse(args []string) []string

Parse predefined flags from command arguments.

func (*Flags) Reset

func (p *Flags) Reset()

Reset all flags.

Jump to

Keyboard shortcuts

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