Documentation
¶
Overview ¶
Package cmdutil holds what commands share: the dependency Factory, argument validators and the --json/--jq/--template flags.
Index ¶
- func AddJSONFlags(cmd *cobra.Command, target **output.Exporter, fields []string, ...)
- func ExactArgs(n int, msg string) cobra.PositionalArgs
- func GroupRunE(cmd *cobra.Command, args []string) error
- func MinimumArgs(n int, msg string) cobra.PositionalArgs
- func MutuallyExclusive(message string, conditions ...bool) error
- func NoArgs(cmd *cobra.Command, args []string) error
- type Factory
- func (f *Factory) APIClient() (*transport.Client, hosts.Host, error)
- func (f *Factory) Clock() time.Time
- func (f *Factory) CredentialStore(cfg *config.Config) auth.Store
- func (f *Factory) DebugEnabled() bool
- func (f *Factory) NewClient(host hosts.Host, token string) *transport.Client
- func (f *Factory) ResolveHost(cfg *config.Config) (hosts.Host, error)
- func (f *Factory) ResolveToken(cfg *config.Config, host hosts.Host) (token, source string, err error)
- func (f *Factory) UseURLHost(serviceURL string)
- func (f *Factory) Warnf(format string, args ...any)
- type JSONOption
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddJSONFlags ¶
func AddJSONFlags(cmd *cobra.Command, target **output.Exporter, fields []string, opts ...JSONOption)
AddJSONFlags adds --json <fields>, --jq and --template to cmd. After flag parsing, *target is nil unless --json was given, in which case it holds an exporter limited to the requested fields. Requesting a field outside fields, or --jq/--template without --json, is a usage error.
func ExactArgs ¶
func ExactArgs(n int, msg string) cobra.PositionalArgs
ExactArgs is cobra.ExactArgs returning a usage error with msg.
func GroupRunE ¶
GroupRunE makes a command group print its help when called bare and fail with a usage error on an unknown subcommand, instead of exiting 0.
func MinimumArgs ¶ added in v0.2.0
func MinimumArgs(n int, msg string) cobra.PositionalArgs
MinimumArgs is cobra.MinimumNArgs returning a usage error with msg.
func MutuallyExclusive ¶
MutuallyExclusive returns a usage error when more than one condition holds.
Types ¶
type Factory ¶
type Factory struct {
IOStreams *iostreams.IOStreams
Prompter prompter.Prompter
Browser browser.Browser
AppVersion string
Config func() (*config.Config, error)
// RoundTripper replaces the HTTP transport when non-nil (tests).
RoundTripper http.RoundTripper
// Now returns the current time; nil means time.Now (tests set it).
Now func() time.Time
// Bound to the root command's persistent flags.
HostFlag string
Debug bool
// contains filtered or unexported fields
}
Factory carries the dependencies commands use instead of globals, so tests can swap IO, config, browser, prompts and HTTP.
func (*Factory) APIClient ¶
APIClient resolves the host and token and returns a client for them. It fails with an auth error (exit 4) when either is missing.
func (*Factory) CredentialStore ¶
CredentialStore returns the token store for the config directory.
func (*Factory) DebugEnabled ¶
DebugEnabled reports whether --debug or $YTRACK_DEBUG asks for HTTP traces.
func (*Factory) NewClient ¶
NewClient returns an API client for host using token. It warns when the host is reached over plain http and is not loopback.
func (*Factory) ResolveHost ¶
ResolveHost picks the host to talk to: --host, then the host of an issue URL argument, then $YTRACK_HOST, then the default host from hosts.yml. A known host keeps its stored URL (scheme and path prefix); an unknown one is normalized from the input.
func (*Factory) ResolveToken ¶
func (f *Factory) ResolveToken(cfg *config.Config, host hosts.Host) (token, source string, err error)
ResolveToken returns the token for host and where it came from: $YTRACK_TOKEN wins over stored credentials. It returns "" when there is none. It warns when YTRACK_TOKEN goes to a host that is not in hosts.yml, unless the user named that host with --host or $YTRACK_HOST (the usual CI setup).
func (*Factory) UseURLHost ¶
UseURLHost makes serviceURL, taken from an issue URL argument, the host to talk to when neither --host nor $YTRACK_HOST names one.
type JSONOption ¶
type JSONOption func(*jsonOptions)
JSONOption adjusts AddJSONFlags.
func WithoutJQShorthand ¶
func WithoutJQShorthand() JSONOption
WithoutJQShorthand leaves --jq without its -q shorthand, for commands where -q means something else (issue list uses it for --query).