cmdfactory

package
v0.6.3-29-gac878ce Latest Latest
Warning

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

Go to latest
Published: Jul 5, 2023 License: BSD-3-Clause Imports: 18 Imported by: 6

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 except 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 except 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 except in compliance with the License.

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

Index

Constants

View Source
const AnnotationHelpGroup = "help:group"

AnnotationHelpGroup is used to indicate in which help group a command belongs.

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 AttributeFlags added in v0.4.0

func AttributeFlags(c *cobra.Command, obj any, args ...string) error

AttributeFlags associates a given struct with public attributes and a set of tags with the provided cobra command so as to enable dynamic population of CLI flags.

func BoolVar added in v0.4.0

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

BoolVar returns an instantiated flag for to an associated pointer boolean value with a given name, default value and usage line.

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(ctx context.Context, cmd *cobra.Command)

Main executes the given 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) (*cobra.Command, error)

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 StringVar added in v0.4.0

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

StringVar returns an instantiated flag for to an associated pointer string value with a given name, default value and usage line.

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 VarF added in v0.4.0

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

VarF returns and instantiated flag based on a pointer value, a name and usage line.

func VarPF

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

VarPF is like VarP, but returns the flag created

Types

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