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
110
cmd/wdcli/main.go
Normal file
110
cmd/wdcli/main.go
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
// Command wdcli implement the entry point for the wisski-distillery
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"runtime/debug"
|
||||
|
||||
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
|
||||
"github.com/FAU-CDI/wisski-distillery/cmd"
|
||||
"github.com/FAU-CDI/wisski-distillery/env"
|
||||
"github.com/tkw1536/goprogram/exit"
|
||||
"github.com/tkw1536/goprogram/stream"
|
||||
)
|
||||
|
||||
var wdcli = wisski_distillery.NewProgram()
|
||||
|
||||
func init() {
|
||||
// self commands
|
||||
wdcli.Register(cmd.Config)
|
||||
wdcli.Register(cmd.License)
|
||||
|
||||
// setup commands
|
||||
wdcli.Register(cmd.Bootstrap)
|
||||
wdcli.Register(cmd.SystemUpdate)
|
||||
|
||||
// sql commands
|
||||
wdcli.Register(cmd.Mysql)
|
||||
wdcli.Register(cmd.MakeMysqlAccount)
|
||||
|
||||
// instance setup and teardown
|
||||
wdcli.Register(cmd.Provision)
|
||||
wdcli.Register(cmd.Purge)
|
||||
wdcli.Register(cmd.Reserve)
|
||||
wdcli.Register(cmd.Rebuild)
|
||||
|
||||
// instance management
|
||||
wdcli.Register(cmd.Ls)
|
||||
wdcli.Register(cmd.Info)
|
||||
|
||||
// instance tasks
|
||||
wdcli.Register(cmd.Shell)
|
||||
wdcli.Register(cmd.BlindUpdate)
|
||||
wdcli.Register(cmd.Cron)
|
||||
wdcli.Register(cmd.UpdatePrefixConfig) // TODO: Move into post-instance configuration
|
||||
|
||||
// backup & cron
|
||||
// wdcli.Register(cmd.BackupInstance)
|
||||
// wdcli.Register(cmd.BackupAll)
|
||||
}
|
||||
|
||||
// an error when no arguments are provided.
|
||||
var errNoArgumentsProvided = exit.Error{
|
||||
ExitCode: exit.ExitGeneralArguments,
|
||||
Message: "Need at least one argument. Use `wdcli license` to view licensing information. ",
|
||||
}
|
||||
|
||||
func main() {
|
||||
// recover from calls to panic(), and exit the program appropriatly.
|
||||
// This has to be in the main() function because any of the library functions might be broken.
|
||||
// For this reason, as few ggman functions as possible are used here; just stuff from the top-level ggman package.
|
||||
defer func() {
|
||||
if err := recover(); err != nil {
|
||||
fmt.Fprintf(os.Stderr, fatalPanicMessage, err)
|
||||
debug.PrintStack()
|
||||
exit.ExitPanic.Return()
|
||||
}
|
||||
}()
|
||||
|
||||
streams := stream.FromEnv()
|
||||
|
||||
// when there are no arguments then parsing argument *will* fail
|
||||
//
|
||||
// we don't need to even bother with the rest of the program
|
||||
// just immediatly return a custom error message.
|
||||
if len(os.Args) == 1 {
|
||||
streams.Die(errNoArgumentsProvided)
|
||||
errNoArgumentsProvided.Return()
|
||||
return
|
||||
}
|
||||
|
||||
// creat a new set of parameters
|
||||
// and then use them to execute the main command
|
||||
err := func() error {
|
||||
params, err := env.ParamsFromEnv()
|
||||
if err != nil {
|
||||
return streams.Die(err)
|
||||
}
|
||||
|
||||
return wdcli.Main(streams, params, os.Args[1:])
|
||||
}()
|
||||
|
||||
// return the error to the user
|
||||
|
||||
exit.AsError(err).Return()
|
||||
}
|
||||
|
||||
const fatalPanicMessage = `Fatal Error: Panic
|
||||
|
||||
The wdcli program panicked and had to abort execution. This is usually
|
||||
indicative of a bug. If this occurs repeatedly you might want to consider
|
||||
filing an issue in the issue tracker at:
|
||||
|
||||
https://github.com/FAU-CDI/wisski-distillery/issues
|
||||
|
||||
Below is debug information that might help the developers track down what
|
||||
happened.
|
||||
|
||||
panic: %v
|
||||
`
|
||||
Loading…
Add table
Add a link
Reference in a new issue