tool

package
v0.0.0-...-b4fbdbd Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2024 License: Apache-2.0 Imports: 11 Imported by: 24

Documentation

Overview

Package tool contains various helper utilitites useful for implementation of command line tools.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Fail

func Fail(err error)

func Failf

func Failf(msg string, args ...interface{})

func FuzzParseFlags

func FuzzParseFlags(data []byte) int

func Init

func Init() func()

Init handles common tasks for command line tools:

  • invokes flag.Parse
  • adds support for optional flags (see OptionalFlags)
  • adds support for cpu/mem profiling (-cpuprofile/memprofile flags)

Use as defer tool.Init()().

func OptionalFlags

func OptionalFlags(flags []Flag) string

OptionalFlags produces command line flag value that encapsulates the given flags as optional. This is intended for programmatic use only when we invoke older versions of binaries with new unsupported flags. Use tool.Init to support optional flags in the binary. The format keeps flags reasonably readable ("-optional=foo=bar:baz=123"), not subject to accidental splitting into multiple arguments due to spaces and supports bool/non-bool flags.

func ParseFlags

func ParseFlags(set *flag.FlagSet, args []string) error

Types

type CfgsFlag

type CfgsFlag []string

CfgsFlag allows passing a list of configuration files to the same flag and provides parsing utilities.

func (*CfgsFlag) Set

func (cfgs *CfgsFlag) Set(value string) error

Set is used by flag.Parse to correctly parse the command line arguments.

func (*CfgsFlag) String

func (cfgs *CfgsFlag) String() string

String correctly converts the flag values into a string which is required to parse them afterwards.

type Flag

type Flag struct {
	Name  string
	Value string
}

Jump to

Keyboard shortcuts

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