flag

package
v0.14.5 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package flag is an internal package to allow us to gracefully transition from the standard library's flag package to pflag. See VEP-4 for details.

In general, this package should not be imported or depended on, except in the cases of package servenv, and entrypoints in go/cmd. This package WILL be deleted after the migration to pflag is completed, without any support for compatibility.

Copyright 2022 The Vitess Authors.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Arg

func Arg(i int) string

Arg returns the ith command-line argument after flags have been processed, ignoring the first double-dash ("--") argument separator. If fewer than `i` arguments were specified, the empty string is returned. If no double-dash was specified, this is equivalent to flag.Arg(i) from the standard library flag package.

func Args

func Args() (args []string)

Args returns the positional arguments with the first double-dash ("--") removed. If no double-dash was specified on the command-line, this is equivalent to flag.Args() from the standard library flag package.

func Parse

func Parse()

Parse wraps the standard library's flag.Parse to perform some sanity checking and issue deprecation warnings in advance of our move to pflag.

It also adjusts the global CommandLine's Usage func to print out flags with double-dashes when a user requests the help, attempting to otherwise leave the default Usage formatting unchanged.

See VEP-4, phase 1 for details: https://github.com/vitessio/enhancements/blob/c766ea905e55409cddeb666d6073cd2ac4c9783e/veps/vep-4.md#phase-1-preparation

func SetUsage

func SetUsage(fs *goflag.FlagSet, opts UsageOptions)

SetUsage sets the Usage function for the given FlagSet according to the options. For VEP-4, all flags are printed in their double-dash form.

Types

type UsageOptions

type UsageOptions struct {
	// Preface determines the beginning of the help text, before flag usages
	// and defaults. If this function is nil, the Usage will print "Usage of <os.Args[0]:\n".
	Preface func(w io.Writer)
	// Epilogue optionally prints text after the flag usages and defaults. If
	// this function is nil, the flag usage/defaults will be the end of the
	// Usage text.
	Epilogue func(w io.Writer)
	// FlagFilter allows certain flags to be omitted from the flag usage and
	// defaults. If non-nil, flags for which this function returns false are
	// omitted.
	FlagFilter func(f *goflag.Flag) bool
}

UsageOptions controls the custom behavior when overriding the Usage for a FlagSet.

Jump to

Keyboard shortcuts

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