flag

package
v0.0.102 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseFlag

func ParseFlag(args []string, i *int) (string, func() (string, bool))

ParseFlag parses a flag from the args slice.

Usage example:

for i := 0; i < n; i++ {
  flag, value := flag.ParseFlag(args, &i)
  if flag == "" {
    remainArgs = append(remainArgs, args[i])
    continue
  }
  switch flag {
  case "-t", "--timeout":
    value, ok := value()
    if !ok {
      return fmt.Errorf("%s requires a value", flag)
    }
    ...
  default:
    return fmt.Errorf("unknown flag: %s", flag)
  }
}

Types

This section is empty.

Jump to

Keyboard shortcuts

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