forked from toolshed/abra
.gitea
cli
app
catalogue
formatter
internal
recipe
record
server
autocomplete.go
cli.go
upgrade.go
cmd
pkg
scripts
tests
.drone.yml
.envrc.sample
.gitignore
.goreleaser.yml
Makefile
README.md
go.mod
go.sum
renovate.json
103 lines
2.5 KiB
Go
103 lines
2.5 KiB
Go
// Package cli provides the interface for the command-line.
|
|
package cli
|
|
|
|
import (
|
|
"fmt"
|
|
"os"
|
|
"path"
|
|
|
|
"coopcloud.tech/abra/cli/app"
|
|
"coopcloud.tech/abra/cli/catalogue"
|
|
"coopcloud.tech/abra/cli/internal"
|
|
"coopcloud.tech/abra/cli/recipe"
|
|
"coopcloud.tech/abra/cli/record"
|
|
"coopcloud.tech/abra/cli/server"
|
|
"coopcloud.tech/abra/pkg/config"
|
|
logrusStack "github.com/Gurpartap/logrus-stack"
|
|
"github.com/sirupsen/logrus"
|
|
"github.com/urfave/cli/v2"
|
|
)
|
|
|
|
func newAbraApp(version, commit string) *cli.App {
|
|
app := &cli.App{
|
|
Name: "abra",
|
|
Usage: `The Co-op Cloud command-line utility belt 🎩🐇
|
|
____ ____ _ _
|
|
/ ___|___ ___ _ __ / ___| | ___ _ _ __| |
|
|
| | / _ \ _____ / _ \| '_ \ | | | |/ _ \| | | |/ _' |
|
|
| |__| (_) |_____| (_) | |_) | | |___| | (_) | |_| | (_| |
|
|
\____\___/ \___/| .__/ \____|_|\___/ \__,_|\__,_|
|
|
|_|
|
|
|
|
If you haven't already done so, consider setting up autocompletion for a more
|
|
convenient command-line experience. See "abra autocomplete -h" for more.
|
|
`,
|
|
Version: fmt.Sprintf("%s-%s", version, commit[:7]),
|
|
Commands: []*cli.Command{
|
|
app.AppCommand,
|
|
server.ServerCommand,
|
|
recipe.RecipeCommand,
|
|
catalogue.CatalogueCommand,
|
|
record.RecordCommand,
|
|
UpgradeCommand,
|
|
AutoCompleteCommand,
|
|
},
|
|
Flags: []cli.Flag{
|
|
internal.VerboseFlag,
|
|
internal.DebugFlag,
|
|
internal.NoInputFlag,
|
|
},
|
|
Authors: []*cli.Author{
|
|
// If you're looking at this and you hack on Abra and you're not listed
|
|
// here, please do add yourself! This is a community project, let's show
|
|
// some love
|
|
{Name: "3wordchant"},
|
|
{Name: "decentral1se"},
|
|
{Name: "kawaiipunk"},
|
|
{Name: "knoflook"},
|
|
{Name: "roxxers"},
|
|
},
|
|
}
|
|
|
|
app.EnableBashCompletion = true
|
|
|
|
app.Before = func(c *cli.Context) error {
|
|
if internal.Debug {
|
|
logrus.SetLevel(logrus.DebugLevel)
|
|
logrus.SetFormatter(&logrus.TextFormatter{})
|
|
logrus.SetOutput(os.Stderr)
|
|
logrus.AddHook(logrusStack.StandardHook())
|
|
}
|
|
|
|
paths := []string{
|
|
config.ABRA_DIR,
|
|
path.Join(config.SERVERS_DIR),
|
|
path.Join(config.RECIPES_DIR),
|
|
path.Join(config.VENDOR_DIR),
|
|
}
|
|
|
|
for _, path := range paths {
|
|
if err := os.Mkdir(path, 0764); err != nil {
|
|
if !os.IsExist(err) {
|
|
logrus.Fatal(err)
|
|
}
|
|
continue
|
|
}
|
|
}
|
|
|
|
logrus.Debugf("abra version %s, commit %s", version, commit)
|
|
|
|
return nil
|
|
}
|
|
return app
|
|
}
|
|
|
|
// RunApp runs CLI abra app.
|
|
func RunApp(version, commit string) {
|
|
app := newAbraApp(version, commit)
|
|
|
|
if err := app.Run(os.Args); err != nil {
|
|
logrus.Fatal(err)
|
|
}
|
|
}
|