app

package
v0.0.0-...-d32eb86 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2024 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Copyright 2023 Talhuang<talhuang1231@gmail.com>. All rights reserved. Use of this source code is governed by a MIT style license that can be found in the LICENSE file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatBaseName

func FormatBaseName(basename string) string

FormatBaseName cleans up and formats the basename, especially for windows OS.

Types

type App

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

App is the central structure representing the CLI application.

func NewApp

func NewApp(name string, basename string, opts ...Option) *App

NewApp initializes a new App instance.

func (*App) AddCommand

func (a *App) AddCommand(cmd *Command)

AddCommand adds a command to the App.

func (*App) AddCommands

func (a *App) AddCommands(cmds ...*Command)

AddCommands adds multiple commands to the App.

func (*App) Command

func (a *App) Command() *cobra.Command

Command returns the main cobra command for the App.

func (*App) Run

func (a *App) Run()

Run starts the App.

type CliOptions

type CliOptions interface {
	// Flags returns a set of named flag sets that can be used by the application.
	// NamedFlagSets helps organize flags into logical groups for better CLI display.
	Flags() (fss flag.NamedFlagSets)

	// Validate checks the validity of the provided command-line options.
	// It returns a list of errors encountered during validation.
	Validate() []error
}

CliOptions defines an interface for command-line options. This interface provides methods for getting flag sets and validating those flags.

type Command

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

Command struct represents an individual CLI command.

func NewCommand

func NewCommand(usage string, desc string, opts ...CommandOption) *Command

NewCommand initializes and returns a new Command.

func (*Command) AddCommand

func (c *Command) AddCommand(cmd *Command)

AddCommand adds a subcommand to the current command.

func (*Command) AddCommands

func (c *Command) AddCommands(cmds ...*Command)

AddCommands adds multiple subcommands to the current command.

type CommandOption

type CommandOption func(*Command)

CommandOption represents a function that configures a Command.

func WithCommandOptions

func WithCommandOptions(opt CliOptions) CommandOption

WithCommandOptions returns a CommandOption that sets the options for a command.

func WithCommandRunFunc

func WithCommandRunFunc(run RunCommandFunc) CommandOption

WithCommandRunFunc returns a CommandOption that sets the run function of a command.

type CompleteableOptions

type CompleteableOptions interface {
	// Complete completes any additional setup or data fetching required for the option.
	Complete() error
}

CompleteableOptions defines an interface for options that require completion. Some options might need additional setup or data fetching after being parsed and validated.

type Option

type Option func(*App)

Option represents a function that can modify an App.

func WithDefaultValidArgs

func WithDefaultValidArgs() Option

WithDefaultValidArgs sets default validation for command arguments.

func WithDescription

func WithDescription(desc string) Option

WithDescription sets a description for the App.

func WithOptions

func WithOptions(opt CliOptions) Option

WithOptions allows CLI options to be passed into the App.

func WithRunFunc

func WithRunFunc(run RunFunc) Option

WithRunFunc sets the run function callback for the app.

func WithValidArgs

func WithValidArgs(args cobra.PositionalArgs) Option

WithValidArgs sets validation for command arguments.

type PrintableOptions

type PrintableOptions interface {
	// String returns a string representation of the option.
	String() string
}

PrintableOptions defines an interface for options that can be converted to a string. This interface provides a method to get a string representation of the option, which can be useful for logging or display purposes.

type RunCommandFunc

type RunCommandFunc func(args []string) error

RunCommandFunc defines the function signature for commands that run.

type RunFunc

type RunFunc func(basename string) error

RunFunc is a function callback that is executed when the app starts.

Jump to

Keyboard shortcuts

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