Documentation
¶
Index ¶
- func Generate(dir string, manDir string) error
- func GenerateWithFS(inputFS fs.FS, writer FileWriter, dir string, manDir string) error
- func List(dir string) error
- func ParseGoFile(fset *token.FileSet, filename, importPath string, file io.Reader, ...) error
- func ParseSubCommandComments(text string) (cmdName string, subCommandSequence []string, description string, ...)
- func SanitizeToIdentifier(name string) string
- func ToKebabCase(s string) string
- func Validate(dir string) error
- type Command
- type CommandTree
- type CommandsTree
- type DataModel
- type FileWriter
- type FunctionParameter
- type NameAllocator
- type OSFileWriter
- type ParsedParam
- type SubCommand
- type SubCommandTree
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Generate ¶
Generate is a subcommand `gosubc generate` that generates the subcommand code param dir (default: ".") Project root directory containing go.mod param manDir (--man-dir) Directory to generate man pages in (optional)
func GenerateWithFS ¶ added in v0.0.11
GenerateWithFS generates code using provided FS and Writer
func List ¶
List is a subcommand `gosubc list` that lists the subcommands param dir (default: ".") The project root directory containing go.mod
func ParseGoFile ¶
func ParseSubCommandComments ¶
func SanitizeToIdentifier ¶ added in v0.0.11
SanitizeToIdentifier converts a string into a valid Go identifier (CamelCase). It handles hyphens, underscores, and other non-alphanumeric characters by acting as delimiters for CamelCasing.
func ToKebabCase ¶ added in v0.0.11
ToKebabCase converts a CamelCase string to kebab-case. It handles acronyms (e.g. JSONData -> json-data) and simple cases (CamelCase -> camel-case).
Types ¶
type CommandTree ¶
type CommandTree struct {
CommandName string
*SubCommandTree
FunctionName string
Parameters []*FunctionParameter
ReturnsError bool
ReturnCount int
Description string
ExtendedHelp string
}
type CommandsTree ¶
type CommandsTree struct {
Commands map[string]*CommandTree
PackagePath string
}
func (*CommandsTree) Insert ¶
func (cst *CommandsTree) Insert(importPath, packageName, cmdName string, subcommandSequence []string, s *SubCommand)
type FileWriter ¶ added in v0.0.11
type FileWriter interface {
WriteFile(path string, content []byte, perm os.FileMode) error
MkdirAll(path string, perm os.FileMode) error
}
FileWriter interface allows mocking file system writes
type FunctionParameter ¶
type FunctionParameter struct {
Name string
Type string
FlagAliases []string
Default string
Description string
IsPositional bool
PositionalArgIndex int
IsVarArg bool
VarArgMin int
VarArgMax int
}
func (*FunctionParameter) FlagString ¶ added in v0.0.11
func (p *FunctionParameter) FlagString() string
type NameAllocator ¶ added in v0.0.11
type NameAllocator struct {
// contains filtered or unexported fields
}
NameAllocator manages the assignment of unique identifier names.
func NewNameAllocator ¶ added in v0.0.11
func NewNameAllocator() *NameAllocator
NewNameAllocator creates a new allocator with pre-reserved names.
func (*NameAllocator) Allocate ¶ added in v0.0.11
func (na *NameAllocator) Allocate(input string) string
Allocate generates a unique name based on the input string. It sanitizes the input and handles collisions by appending numbers.
type OSFileWriter ¶ added in v0.0.11
type OSFileWriter struct{}
OSFileWriter implements FileWriter using os package
type ParsedParam ¶ added in v0.0.11
type SubCommand ¶
type SubCommand struct {
*Command
Parent *SubCommand
SubCommands []*SubCommand
SubCommandName string
SubCommandStructName string
SubCommandFunctionName string
SubCommandDescription string
SubCommandExtendedHelp string
ImportPath string
SubCommandPackageName string
UsageFileName string
Parameters []*FunctionParameter
ReturnsError bool
ReturnCount int
}
func (*SubCommand) HasSubcommands ¶
func (sc *SubCommand) HasSubcommands() bool
func (*SubCommand) MaxFlagLength ¶ added in v0.0.11
func (sc *SubCommand) MaxFlagLength() int
func (*SubCommand) ParentCmdName ¶
func (sc *SubCommand) ParentCmdName() string
func (*SubCommand) ProgName ¶
func (sc *SubCommand) ProgName() string
func (*SubCommand) SubCommandSequence ¶
func (sc *SubCommand) SubCommandSequence() string
type SubCommandTree ¶
type SubCommandTree struct {
SubCommands map[string]*SubCommandTree
*SubCommand
}
func NewSubCommandTree ¶
func NewSubCommandTree(subCommand *SubCommand) *SubCommandTree
func (*SubCommandTree) Insert ¶
func (sct *SubCommandTree) Insert(importPath, packageName string, sequence []string, s *SubCommand)