From 63c5db734d4e5c8394d48fed84d93b0929f4722f Mon Sep 17 00:00:00 2001 From: Tom Date: Sat, 15 Jul 2023 15:36:17 +0200 Subject: [PATCH] rebuild: Add explicit flag for updating --- cmd/rebuild.go | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/cmd/rebuild.go b/cmd/rebuild.go index 9c4cf39..4e5075f 100644 --- a/cmd/rebuild.go +++ b/cmd/rebuild.go @@ -18,6 +18,7 @@ var Rebuild wisski_distillery.Command = rebuild{} type rebuild struct { Parallel int `short:"a" long:"parallel" description:"run on (at most) this many instances in parallel. 0 for no limit." default:"1"` + System bool `short:"s" long:"system-update" description:"Update the system configuration according to other flags"` PHPVersion string `short:"p" long:"php" description:"update to 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"` ContentSecurityPolicy string `short:"c" long:"content-security-policy" description:"Setup ContentSecurityPolicy"` @@ -27,6 +28,21 @@ type rebuild struct { } `positional-args:"true"` } +var errRebuildNoSystem = exit.Error{ + Message: "flags for system reconfiguration have been set, but `--system' was not provided", + ExitCode: exit.ExitCommandArguments, +} + +func (rb rebuild) AfterParse() error { + if rb.System { + return nil + } + if rb.PHPVersion != "" || rb.OPCacheDevelopment || rb.ContentSecurityPolicy != "" { + return errRebuildNoSystem + } + return nil +} + func (rebuild) Description() wisski_distillery.Description { return wisski_distillery.Description{ Requirements: cli.Requirements{ @@ -55,11 +71,16 @@ func (rb rebuild) Run(context wisski_distillery.Context) (err error) { // and do the actual rebuild return status.WriterGroup(context.Stderr, rb.Parallel, func(instance *wisski.WissKI, writer io.Writer) error { - return instance.SystemManager().Apply(context.Context, writer, models.System{ - PHP: rb.PHPVersion, - OpCacheDevelopment: rb.OPCacheDevelopment, - ContentSecurityPolicy: rb.ContentSecurityPolicy, - }, true) + sys := instance.System + if rb.System { + sys = models.System{ + PHP: rb.PHPVersion, + OpCacheDevelopment: rb.OPCacheDevelopment, + ContentSecurityPolicy: rb.ContentSecurityPolicy, + } + } + + return instance.SystemManager().Apply(context.Context, writer, sys, true) }, wissKIs, status.SmartMessage(func(item *wisski.WissKI) string { return fmt.Sprintf("rebuild %q", item.Slug) }))