Do a large chunk of the move to go
This commit moves a huge chunk of the code to go. The TODO.md document indicates what is left to be done.
This commit is contained in:
parent
db2ad9b4bd
commit
7b38fdd801
93 changed files with 4689 additions and 645 deletions
54
cmd/blind_update.go
Normal file
54
cmd/blind_update.go
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
package cmd
|
||||
|
||||
import (
|
||||
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
|
||||
"github.com/FAU-CDI/wisski-distillery/env"
|
||||
"github.com/tkw1536/goprogram/exit"
|
||||
)
|
||||
|
||||
// BlindUpdate is the 'blind-update' command
|
||||
var BlindUpdate wisski_distillery.Command = blindUpdate{}
|
||||
|
||||
type blindUpdate struct {
|
||||
Force bool `short:"f" long:"force" description:"force running blind-update even if AutoBlindUpdate is set to false"`
|
||||
Positionals struct {
|
||||
Slug []string `positional-arg-name:"SLUG" required:"0" description:"slug of instance(s) to run blind-update in"`
|
||||
} `positional-args:"true"`
|
||||
}
|
||||
|
||||
func (blindUpdate) Description() wisski_distillery.Description {
|
||||
return wisski_distillery.Description{
|
||||
Requirements: env.Requirements{
|
||||
NeedsConfig: true,
|
||||
},
|
||||
Command: "blind_update",
|
||||
Description: "Runs the blind update in the provided instances",
|
||||
}
|
||||
}
|
||||
|
||||
var errBlindUpdateFailed = exit.Error{
|
||||
Message: "Failed to run blind update script for instance %q: exited with code %s",
|
||||
ExitCode: exit.ExitGeneric,
|
||||
}
|
||||
|
||||
func (bu blindUpdate) Run(context wisski_distillery.Context) error {
|
||||
instances, err := context.Environment.Instances(bu.Positionals.Slug...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, instance := range instances {
|
||||
if !(instance.IsBlindUpdateEnabled() || bu.Force) {
|
||||
context.EPrintf("skipping instance %q\n", instance.Slug)
|
||||
continue
|
||||
}
|
||||
context.EPrintf("Updating instance %s\n", instance.Slug)
|
||||
|
||||
code := instance.Shell(context.IOStream, "/utils/blind_update.sh")
|
||||
if code != 0 {
|
||||
return errBlindUpdateFailed.WithMessageF(instance.Slug, code)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue