Documentation
¶
Overview ¶
Package cli contains common command-line flags and configuration options.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrExitVersion is an error indicating the application should exit after // showing version. ErrExitVersion = &unprintableError{errors.New("version flag exit")} // ErrInvalidArgs indicates that the command-line arguments provided to the // application are invalid or insufficient. This error should be wrapped with // fmt.Errorf to provide a specific, user-friendly message explaining the // nature of the invalid arguments. For example: // // return fmt.Errorf("%w: missing required argument 'filename'", cli.ErrInvalidArgs) // ErrInvalidArgs = errors.New("invalid arguments") )
Functions ¶
func Run ¶ added in v0.3.0
Run executes the provided function f within a context that is canceled when an interrupt signal (e.g., Ctrl+C) is received.
If f returns a non-nil error, Run prints the error message to standard error (if the error is considered "printable") and exits the program with a status code of 1.
Printable errors are those that provide useful information to the user. Errors like flag parsing errors or help requests are considered non-printable and are not displayed to the user.
Types ¶
type App ¶ added in v0.3.0
type App struct { Name string // Name of the application. Description string // Description of the application. ArgsUsage string // Usage message for the command-line arguments. Flags *flag.FlagSet // Command-line flags. }
App represents a command-line application.
func (*App) HandleStartup ¶ added in v0.3.0
HandleStartup handles the command startup. All exported fields shouldn't be modified after HandleStartup is called.
It sets up the command-line flags, parses the arguments, and handles the version flag if specified.