Documentation
¶
Overview ¶
The initialize package provides functions to create a new craft project.
The main function to be used is Run and it can be tuned with options (see documentation).
Example:
func main() { ctx := context.Background() destdir, _ := os.Getwd() config, err := initialize.Run(ctx, destdir) }
Example with a custom FormGroup:
func main() { ctx := context.Background() destdir, _ := os.Getwd() config, err := initialize.Run(ctx, destdir, initialize.WithFormGroups(initialize.ReadMaintainer, initialize.ReadChart, ReadLicense)) if err != nil { // handle err } } // ReadLicense returns the appropriate huh.Group for initialize.Run form groups. func ReadLicense(config *craft.Configuration) *huh.Group { return huh.NewGroup(huh.NewInput(). Title("Would you like to specify a license ?"). Validate(func(s string) error { if s != "" { config.License = &s } return nil })) }
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrAlreadyInitialized is the error returned (wrapped) when Run function is called but the project is already initialized. ErrAlreadyInitialized = errors.New("project already initialized") // ErrRequiredField is the error that can be used with huh.Validate(f func(string) error) to specify to the user that the field is required. ErrRequiredField = errors.New("required field") )
Functions ¶
func ReadChart ¶
func ReadChart(config *craft.Configuration) *huh.Group
ReadChart retrieves the chart generation choice from the end user.
func ReadMaintainer ¶
func ReadMaintainer(config *craft.Configuration) *huh.Group
ReadMaintainer creates a maintainer with Q&A method from the end user.
func Run ¶
Run initializes a new craft project in case a craft.CraftFile doesn't exist in destdir. All user inputs must be configured through WithFormGroups option, by default the main maintainer and chart generation will be asked.
Multiple options can be given like saving craft configuration file at the end (default is false), the logger used to ask question to the end user or the reader from where retrieve the end user answers (but as provided in WithReader doc it should be used with caution - you should know what you're doing).
In case craft.CraftFile already exists, it's read and returned alongside ErrAlreadyInitialized (should be handled in caller).
Types ¶
type FormGroup ¶
type FormGroup func(config *craft.Configuration) *huh.Group
FormGroup is the signature function for functions reading user inputs. Inspiration can be found with ReadMaintainer and ReadChart functions.
type RunOption ¶
type RunOption func(runOptions) runOptions
RunOption represents an option to be given to Run function.
func WithFormGroups ¶
WithFormGroups sets (it overrides the previously defined functions everytime it's called) the functions reading user inputs in Run function.
func WithTeaOptions ¶
func WithTeaOptions(opts ...tea.ProgramOption) RunOption
WithTeaOptions sets the slice of tea.ProgramOption for huh form tuning.