CnsPanel

package
v0.2.17 Latest Latest
Warning

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

Go to latest
Published: Mar 16, 2024 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package CnsPanel provides a structure and functions for handling console command flags.

Package CnsPanel provides a structure and functions for handling console command flags.

Package CnsPanel provides a structure and functions for handling console command flags.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CommandInfoOption

type CommandInfoOption func(*ConsoleCommandInfo) error

CommandInfoOption is a function type that modifies ConsoleCommandInfo.

Parameters:

  • command: The ConsoleCommandInfo to modify.

Returns:

  • error: An error if the modification fails.

func WithCallback

func WithCallback(callback func(map[string]any) (any, error)) CommandInfoOption

WithCallback is a CommandInfoOption that sets the callback for a ConsoleCommandInfo. If the provided callback is nil, it returns an error of type *ErrInvalidParameter.

Parameters:

  • callback: The function to call when the command is used.

Returns:

  • CommandInfoOption: A CommandInfoOption that sets the callback for a ConsoleCommandInfo.

func WithCommandDescription

func WithCommandDescription(description ...string) CommandInfoOption

WithCommandDescription is a CommandInfoOption that sets the description for a ConsoleCommandInfo. It splits each line of the description by newline characters.

Parameters:

  • description: The description to set.

Returns:

  • CommandInfoOption: A CommandInfoOption that sets the description for a ConsoleCommandInfo.

func WithFlag

func WithFlag(name string, callback func(...string) (any, error), options ...FlagInfoOption) CommandInfoOption

WithFlag is a CommandInfoOption that adds a new flag to a ConsoleCommandInfo. It creates a new ConsoleFlagInfo with the provided name and callback, and applies the provided options to it. If the flag name is empty or the callback is nil, it returns an error of type *ErrInvalidParameter.

Parameters:

  • name: The name of the flag.
  • callback: The function to call when the flag is used.
  • options: The options to apply to the flag.

Returns:

  • CommandInfoOption: A CommandInfoOption that adds a new flag to a ConsoleCommandInfo.

type ConsoleBuilder

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

ConsoleBuilder represents a builder for a command line interface.

func (*ConsoleBuilder) AddCommand

func (b *ConsoleBuilder) AddCommand(commandName string, options ...CommandInfoOption) error

AddCommand is a method of ConsoleBuilder that adds a new command to a ConsoleBuilder.

Parameters:

  • commandName: The name of the command.
  • options: The options to apply to the command.

Returns:

  • error: An error if the command cannot be added.

func (*ConsoleBuilder) AppendParagraph

func (b *ConsoleBuilder) AppendParagraph(contents ...string)

AppendParagraph is a method of ConsoleBuilder that appends a paragraph to the description of a ConsoleBuilder.

Parameters:

  • contents: The contents of the paragraph to append.

func (*ConsoleBuilder) Build

func (b *ConsoleBuilder) Build() *ConsolePanel

Build is a method of ConsoleBuilder that builds a CMLine from a ConsoleBuilder.

Returns:

  • *CMLine: A CMLine built from the ConsoleBuilder.

func (*ConsoleBuilder) Reset

func (b *ConsoleBuilder) Reset()

Reset is a method of ConsoleBuilder that resets a ConsoleBuilder.

func (*ConsoleBuilder) SetExecutableName

func (b *ConsoleBuilder) SetExecutableName(name string)

SetExecutableName is a method of ConsoleBuilder that sets the executable name for a ConsoleBuilder.

Parameters:

  • name: The name of the executable.

type ConsoleCommandInfo

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

ConsoleCommandInfo represents a console command.

func (*ConsoleCommandInfo) FString

func (cci *ConsoleCommandInfo) FString(indentLevel int) string

FString generates a formatted string representation of a ConsoleCommandInfo. It includes the command name, description, usage information for each flag, and the list of flags and their details.

Parameters:

  • indentLevel: The level of indentation to use. Sign is ignored.

Returns:

  • string: A string representing the ConsoleCommandInfo.

type ConsoleFlagInfo

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

ConsoleFlagInfo represents a flag for a console command.

func (*ConsoleFlagInfo) FString

func (cfi *ConsoleFlagInfo) FString(indentLevel int) string

FString generates a formatted string representation of a ConsoleFlagInfo, including the flag name, arguments, description, and whether it is required.

Parameters:

  • indentLevel: The level of indentation to use. Sign is ignored.

Returns:

  • string: A string representing the ConsoleFlagInfo.

type ConsolePanel

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

ConsolePanel represents a command line interface.

func (*ConsolePanel) FString

func (cns *ConsolePanel) FString(indentLevel int) string

FString generates a formatted string representation of a CMLine. It includes the usage information, and the list of commands and their details.

Returns:

  • string: A string representing the CMLine.

func (*ConsolePanel) ParseArgs

func (cns *ConsolePanel) ParseArgs(args []string) (*parsedCommand, error)

ParseArgs parses the provided command line arguments and executes the corresponding command.

Panics with an error of type *ErrInvalidParameter if no arguments are provided, or with an error of type *ErrCallFailed if the ParseArgs function fails.

Parameters:

  • args: The command line arguments to parse. Without the executable name.

Returns:

  • *parsedCommand: The parsed command.
  • error: An error, if any.

type FlagInfoOption

type FlagInfoOption func(*ConsoleFlagInfo)

FlagInfoOption is a function type that modifies ConsoleFlagInfo.

Parameters:

  • ConsoleFlagInfo: The ConsoleFlagInfo to modify.

func WithArgs

func WithArgs(args ...string) FlagInfoOption

WithArgs is a FlagInfoOption that sets the arguments for a ConsoleFlagInfo. It trims the space from each argument and ignores empty arguments.

Parameters:

  • args: The arguments to set.

Returns:

  • FlagInfoOption: A FlagInfoOption that sets the arguments for a ConsoleFlagInfo.

func WithFlagDescription

func WithFlagDescription(description ...string) FlagInfoOption

WithFlagDescription is a FlagInfoOption that sets the description for a ConsoleFlagInfo. It splits each line of the description by newline characters.

Parameters:

  • description: The description to set.

Returns:

  • FlagInfoOption: A FlagInfoOption that sets the description for a ConsoleFlagInfo.

func WithRequired

func WithRequired(required bool) FlagInfoOption

WithRequired is a FlagInfoOption that sets whether a ConsoleFlagInfo is required.

Parameters:

  • required: Whether the flag is required.

Returns:

  • FlagInfoOption: A FlagInfoOption that sets whether a ConsoleFlagInfo is required.

Jump to

Keyboard shortcuts

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