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:
Tom Wiesing 2022-08-14 10:57:59 +02:00
parent db2ad9b4bd
commit 7b38fdd801
No known key found for this signature in database
93 changed files with 4689 additions and 645 deletions

49
cmd/shell.go Normal file
View file

@ -0,0 +1,49 @@
package cmd
import (
"fmt"
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
"github.com/FAU-CDI/wisski-distillery/env"
"github.com/tkw1536/goprogram/exit"
"github.com/tkw1536/goprogram/parser"
)
// Shell is the 'shell' command
var Shell wisski_distillery.Command = shell{}
type shell struct {
Positionals struct {
Slug string `positional-arg-name:"SLUG" required:"1-1" description:"slug of instance to show run shell in"`
Args []string `positional-arg-name:"ARGS" description:"arguments to pass to the shell"`
} `positional-args:"true"`
}
func (shell) Description() wisski_distillery.Description {
return wisski_distillery.Description{
Requirements: env.Requirements{
NeedsConfig: true,
},
ParserConfig: parser.Config{
IncludeUnknown: true,
},
Command: "shell",
Description: "Open a shell in the provided instance",
}
}
func (sh shell) Run(context wisski_distillery.Context) error {
instance, err := context.Environment.Instance(sh.Positionals.Slug)
if err != nil {
return err
}
code := instance.Shell(context.IOStream, sh.Positionals.Args...)
if code != 0 {
return exit.Error{
ExitCode: exit.ExitCode(uint8(code)),
Message: fmt.Sprintf("Exit code %d", code),
}
}
return nil
}