cli

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 28, 2024 License: Apache-2.0 Imports: 8 Imported by: 6

README

godoc Go Report Card

cli - command-line interface utilities

a collection of utilities for working with github.com/urfave/cli

Installation

> go get github.com/go-corelibs/cli@latest

Examples

FlagStringer

import (
    "github.com/urfave/cli/v2"

    clcli "github.com/go-corelibs/cli"
)

func init() {
    // - remove default text from boolean flag usage
    // - place defaults and env vars on newlines
    cli.FlagStringer = clcli.NewFlagStringer().
		PruneDefaultBools(true).
		DetailsOnNewLines(true).
		Make()
}

Go-CoreLibs

Go-CoreLibs is a repository of shared code between the Go-Curses and Go-Enjin projects.

License

Copyright 2024 The Go-CoreLibs Authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use 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.

Documentation

Overview

Package cli provides command-line interface utilities

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClearEmptyCategories

func ClearEmptyCategories(flags []cli.Flag)

ClearEmptyCategories sets all flag.Category strings to empty if the specific category does not have any visible flags

func ShowOptions added in v0.3.0

func ShowOptions(ctx *cli.Context)

ShowOptions prints each option (and it's aliases), one per line, to os.Stderr and with flags named "usage", "help", "version" and "verbose" separated and sorted after all other flags

func ShowUsage added in v0.3.0

func ShowUsage(ctx *cli.Context)

ShowUsage prints a very brief usage text line to os.Stderr

func ShowUsageAndExit added in v0.3.0

func ShowUsageAndExit(ctx *cli.Context, exitCode int)

ShowUsageAndExit calls ShowUsage and then os.Exit with the `exitCode` given

func ShowUsageOptions added in v0.3.0

func ShowUsageOptions(ctx *cli.Context)

ShowUsageOptions is like ShowUsage but includes a listing of all option names and aliases

func ShowUsageOptionsAndExit added in v0.3.0

func ShowUsageOptionsAndExit(ctx *cli.Context, exitCode int)

ShowUsageOptionsAndExit calls ShowUsageOptions and then os.Exit with the `exitCode` given

Types

type BaseFlag added in v0.3.0

type BaseFlag struct {
	Name        string
	Category    string
	DefaultText string
	Usage       string
	Required    bool
	Hidden      bool
	Aliases     []string
	EnvVars     []string
	// contains filtered or unexported fields
}

BaseFlag is a type containing only the common variables for any given cli.Flag type

func DecodeBaseFlag added in v0.3.0

func DecodeBaseFlag(flag cli.Flag) (base *BaseFlag)

DecodeBaseFlag returns a BaseFlag representation of the given cli.Flag

func NewBaseFlag added in v0.3.0

func NewBaseFlag(name, category, defaultText, usage string, required, hidden bool, aliases, envVars []string, original cli.Flag) *BaseFlag

NewBaseFlag constructs a new BaseFlag instance

func (*BaseFlag) NameWithAliases added in v0.4.0

func (b *BaseFlag) NameWithAliases() (name string)

NameWithAliases returns the flag name and any aliases, with leading dashes

func (*BaseFlag) Original added in v0.3.0

func (b *BaseFlag) Original() (f cli.Flag)

Original returns the actual cli.Flag this BaseFlag instance was derived from

type FlagStringer

type FlagStringer interface {
	// PruneEnvVars specifies if `[$ENV_VAR...]` text is removed
	PruneEnvVars(enable bool) FlagStringer
	// PruneDefaults specifies if `(default: ...)` text is removed
	PruneDefaults(enable bool) FlagStringer
	// PruneDefaultBools specifies if only boolean flag defaults are removed
	PruneDefaultBools(enable bool) FlagStringer
	// PruneRepeats specifies if slice flags have their repeated example removed
	PruneRepeats(enable bool) FlagStringer
	// DetailsOnNewLines specifies if defaults and env vars are places on new
	// lines instead of all in one line
	DetailsOnNewLines(enable bool) FlagStringer
	// Make produces the cli.FlagStringFunc
	Make() cli.FlagStringFunc
}

FlagStringer is a buildable interface for constructing a pre-configured cli.FlagStringFunc instances

func NewFlagStringer

func NewFlagStringer() FlagStringer

NewFlagStringer creates a new FlagStringer instance, ready to be configured and made into a cli.FlagStringFunc

Jump to

Keyboard shortcuts

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