cli

package
v0.2.1-2-g5dc37d7 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2022 License: BSD-3-Clause Imports: 23 Imported by: 0

Documentation

Overview

SPDX-License-Identifier: MIT Copyright (c) 2019, 2019 GitHub Inc. Copyright (c) 2022, Unikraft GmbH and The KraftKit Authors. Licensed under the MIT License (the "License"). You may not use this file expect in compliance with the License.

SPDX-License-Identifier: Apache-2.0 Copyright 2022 Acorn Labs, Inc; All rights reserved. Copyright 2022 Unikraft GmbH; All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License.

SPDX-License-Identifier: MIT Copyright (c) 2019 GitHub Inc. Copyright (c) 2022 Unikraft GmbH.

SPDX-License-Identifier: BSD-3-Clause Copyright (c) 2012 Alex Ogier. Copyright (c) 2012 The Go Authors. Copyright (c) 2022, Unikraft GmbH and The KraftKit Authors. Licensed under the BSD-3-Clause License (the "License"). You may not use this file expect in compliance with the License.

SPDX-License-Identifier: BSD-3-Clause Copyright (c) 2012 Alex Ogier. Copyright (c) 2012 The Go Authors. Copyright (c) 2022, Unikraft GmbH and The KraftKit Authors. Licensed under the BSD-3-Clause License (the "License"). You may not use this file expect in compliance with the License.

SPDX-License-Identifier: BSD-3-Clause Copyright (c) 2022, Unikraft GmbH and The KraftKit Authors. Licensed under the BSD-3-Clause License (the "License"). You may not use this file expect in compliance with the License.

SPDX-License-Identifier: BSD-3-Clause Copyright (c) 2012 Alex Ogier. Copyright (c) 2012 The Go Authors. Copyright (c) 2022, Unikraft GmbH and The KraftKit Authors. Licensed under the BSD-3-Clause License (the "License"). You may not use this file expect in compliance with the License.

SPDX-License-Identifier: MIT Copyright (c) 2019 GitHub Inc. Copyright (c) 2022 Unikraft GmbH.

SPDX-License-Identifier: BSD-3-Clause Copyright (c) 2022, Unikraft GmbH and The KraftKit Authors. Licensed under the BSD-3-Clause License (the "License"). You may not use this file expect in compliance with the License.

Index

Constants

This section is empty.

Variables

View Source
var ErrCancel = errors.New("ErrCancel")

ErrCancel signals user-initiated cancellation

View Source
var ErrSilent = errors.New("ErrSilent")

ErrSilent is an error that triggers exit code 1 without any error messaging

Functions

func BoolVarP

func BoolVarP(p *bool, name, shorthand string, value bool, usage string) *pflag.Flag

BoolVarP is like BoolVar, but accepts a shorthand letter that can be used after a single dash.

func ExactArgs

func ExactArgs(n int, msg string) cobra.PositionalArgs

func FlagErrorWrap

func FlagErrorWrap(err error) error

FlagError returns a new FlagError that wraps the specified error.

func FlagErrorf

func FlagErrorf(format string, args ...interface{}) error

FlagErrorf returns a new FlagError that wraps an error produced by fmt.Errorf(format, args...).

func HasFailed

func HasFailed() bool

HasFailed signals that the main process should exit with non-zero status

func IsUserCancellation

func IsUserCancellation(err error) bool

func Main

func Main(cmd *cobra.Command)

func MaxDirArgs

func MaxDirArgs(n int) cobra.PositionalArgs

func MinimumArgs

func MinimumArgs(n int, msg string) cobra.PositionalArgs

func MutuallyExclusive

func MutuallyExclusive(message string, conditions ...bool) error

func Name

func Name(obj any) string

func New

func New(obj Runnable, cmd cobra.Command, opts ...CliOption) *cobra.Command

New populates a cobra.Command object by extracting args from struct tags of the Runnable obj passed. Also the Run method is assigned to the RunE of the command. name = Override the struct field with

func NoArgsQuoteReminder

func NoArgsQuoteReminder(cmd *cobra.Command, args []string) error

func RegisterFlag

func RegisterFlag(cmdline string, flag *pflag.Flag)

func StringVarP

func StringVarP(p *string, name, shorthand string, value string, usage string) *pflag.Flag

StringVarP is like StringVar, but accepts a shorthand letter that can be used after a single dash.

func VarPF

func VarPF(value pflag.Value, name, shorthand, usage string) *pflag.Flag

VarPF is like VarP, but returns the flag created

Types

type CliOption

type CliOption func(*CliOptions)

func WithConfigManager

func WithConfigManager(cfgm *config.ConfigManager) CliOption

WithConfigManager sets a previously instantiate ConfigManager to be used as part of the CLI options.

func WithDefaultConfigManager

func WithDefaultConfigManager() CliOption

WithDefaultConfigManager instantiates a configuration manager based on default options.

func WithDefaultHTTPClient

func WithDefaultHTTPClient() CliOption

WithDefaultHTTPClient initializes a HTTP client using host-provided configuration.

func WithDefaultIOStreams

func WithDefaultIOStreams() CliOption

WithDefaultIOStreams instantiates ta new IO streams using environmental variables and host-provided configuration.

func WithDefaultLogger

func WithDefaultLogger() CliOption

WithDefaultLogger sets up the built in logger based on provided conifg found from the ConfigManager.

func WithDefaultPackageManager

func WithDefaultPackageManager() CliOption

WithDefaultPackageManager initializes a new package manager based on the umbrella package manager using host-provided configuration.

func WithDefaultPluginManager

func WithDefaultPluginManager() CliOption

WithDefaultPluginManager returns an initialized plugin manager using the host-provided configuration plugin path.

func WithHTTPClient

func WithHTTPClient(httpClient *http.Client) CliOption

WithHTTPClient sets a previously instantiated http.Client to be used within the command.

func WithIOStreams

func WithIOStreams(io *iostreams.IOStreams) CliOption

WithIOStreams sets a previously instantiated iostreams.IOStreams structure to be used within the command.

func WithPackageManager

func WithPackageManager(pm packmanager.PackageManager) CliOption

WithPackageManager sets a previously initialized package manager to be used with the command.

func WithPluginManager

func WithPluginManager(pm *plugins.PluginManager) CliOption

WithPluginManager sets a previously instantiated plugin manager to be used withthe command.

type CliOptions

type CliOptions struct {
	// contains filtered or unexported fields
}

type EnumFlag

type EnumFlag struct {
	Allowed []string
	Value   string
}

func NewEnumFlag

func NewEnumFlag(allowed []string, d string) *EnumFlag

NewEnumFlag give a list of allowed flag parameters, where the second argument is the default

func (*EnumFlag) Set

func (a *EnumFlag) Set(p string) error

func (*EnumFlag) String

func (a *EnumFlag) String() string

func (*EnumFlag) Type

func (a *EnumFlag) Type() string

type FlagError

type FlagError struct {
	// contains filtered or unexported fields
}

A *FlagError indicates an error processing command-line flags or other arguments. Such errors cause the application to display the usage message.

func (*FlagError) Error

func (fe *FlagError) Error() string

func (*FlagError) Unwrap

func (fe *FlagError) Unwrap() error

type PersistentPreRunnable

type PersistentPreRunnable interface {
	PersistentPre(cmd *cobra.Command, args []string) error
}

type PreRunnable

type PreRunnable interface {
	Pre(cmd *cobra.Command, args []string) error
}

type Runnable

type Runnable interface {
	Run(cmd *cobra.Command, args []string) error
}

Jump to

Keyboard shortcuts

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