Implement basic flavor support

This commit is contained in:
Tom Wiesing 2023-11-02 20:06:09 +01:00
parent 9a3e508ce8
commit d6c0c465e4
No known key found for this signature in database
24 changed files with 246 additions and 82 deletions

View file

@ -1,10 +1,13 @@
package cmd
import (
"encoding/json"
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
"github.com/FAU-CDI/wisski-distillery/internal/cli"
"github.com/FAU-CDI/wisski-distillery/internal/dis/component/provision"
"github.com/FAU-CDI/wisski-distillery/internal/models"
"github.com/FAU-CDI/wisski-distillery/internal/wisski/ingredient/barrel/manager"
"github.com/FAU-CDI/wisski-distillery/pkg/logging"
"github.com/tkw1536/goprogram/exit"
)
@ -15,12 +18,26 @@ var Provision wisski_distillery.Command = pv{}
type pv struct {
PHPVersion string `short:"p" long:"php" description:"specific php version to use for instance. Should be one of '8.0', '8.1'."`
OPCacheDevelopment bool `short:"o" long:"opcache-devel" description:"Include opcache development configuration"`
Flavor string `short:"f" long:"flavor" description:"Use specific flavor. Use '--list-flavors' to list flavors. "`
ListFlavors bool `short:"l" long:"list-flavors" description:"List all known flavors"`
ContentSecurityPolicy string `short:"c" long:"content-security-policy" description:"Setup ContentSecurityPolicy"`
Positionals struct {
Slug string `positional-arg-name:"slug" required:"1-1" description:"slug of instance to create"`
Slug string `positional-arg-name:"slug" description:"slug of instance to create"`
} `positional-args:"true"`
}
var errMissingSlug = exit.Error{
ExitCode: exit.ExitCommandArguments,
Message: "must provide a slug",
}
func (pv pv) AfterParse() error {
if !pv.ListFlavors && pv.Positionals.Slug == "" {
return errMissingSlug
}
return nil
}
func (pv) Description() wisski_distillery.Description {
return wisski_distillery.Description{
Requirements: cli.Requirements{
@ -39,8 +56,13 @@ var errProvisionGeneric = exit.Error{
// TODO: AfterParse to check instance!
func (p pv) Run(context wisski_distillery.Context) error {
if p.ListFlavors {
return p.listFlavors(context)
}
instance, err := context.Environment.Provision().Provision(context.Stderr, context.Context, provision.Flags{
Slug: p.Positionals.Slug,
Slug: p.Positionals.Slug,
Flavor: p.Flavor,
System: models.System{
PHP: p.PHPVersion,
OpCacheDevelopment: p.OPCacheDevelopment,
@ -48,7 +70,7 @@ func (p pv) Run(context wisski_distillery.Context) error {
},
})
if err != nil {
return errProvisionGeneric.WithMessageF(p.Positionals.Slug).Wrap(err)
return errProvisionGeneric.WithMessageF(p.Positionals.Slug).WrapError(err)
}
// and we're done!
@ -59,3 +81,10 @@ func (p pv) Run(context wisski_distillery.Context) error {
return nil
}
func (pv) listFlavors(context wisski_distillery.Context) error {
encoder := json.NewEncoder(context.Stdout)
encoder.SetIndent("", " ")
encoder.Encode(manager.Profiles())
return nil
}