forked from toolshed/abra
refactor: urfave v3
This commit is contained in:
32
cli/cli.go
32
cli/cli.go
@ -2,6 +2,7 @@
|
||||
package cli
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
@ -18,7 +19,7 @@ import (
|
||||
"coopcloud.tech/abra/pkg/log"
|
||||
"coopcloud.tech/abra/pkg/web"
|
||||
charmLog "github.com/charmbracelet/log"
|
||||
"github.com/urfave/cli/v2"
|
||||
"github.com/urfave/cli/v3"
|
||||
)
|
||||
|
||||
// AutoCompleteCommand helps people set up auto-complete in their shells
|
||||
@ -38,11 +39,11 @@ EXAMPLE:
|
||||
Flags: []cli.Flag{
|
||||
internal.DebugFlag,
|
||||
},
|
||||
Action: func(c *cli.Context) error {
|
||||
shellType := c.Args().First()
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
shellType := cmd.Args().First()
|
||||
|
||||
if shellType == "" {
|
||||
internal.ShowSubcommandHelpAndError(c, errors.New("no shell provided"))
|
||||
internal.ShowSubcommandHelpAndError(cmd, errors.New("no shell provided"))
|
||||
}
|
||||
|
||||
supportedShells := map[string]bool{
|
||||
@ -125,18 +126,18 @@ EXAMPLE:
|
||||
abra upgrade
|
||||
abra upgrade --rc`,
|
||||
Flags: []cli.Flag{internal.RCFlag},
|
||||
Action: func(c *cli.Context) error {
|
||||
Action: func(ctx context.Context, cmd *cli.Command) error {
|
||||
mainURL := "https://install.abra.coopcloud.tech"
|
||||
cmd := exec.Command("bash", "-c", fmt.Sprintf("wget -q -O- %s | bash", mainURL))
|
||||
c := exec.Command("bash", "-c", fmt.Sprintf("wget -q -O- %s | bash", mainURL))
|
||||
|
||||
if internal.RC {
|
||||
releaseCandidateURL := "https://git.coopcloud.tech/coop-cloud/abra/raw/branch/main/scripts/installer/installer"
|
||||
cmd = exec.Command("bash", "-c", fmt.Sprintf("wget -q -O- %s | bash -s -- --rc", releaseCandidateURL))
|
||||
c = exec.Command("bash", "-c", fmt.Sprintf("wget -q -O- %s | bash -s -- --rc", releaseCandidateURL))
|
||||
}
|
||||
|
||||
log.Debugf("attempting to run %s", cmd)
|
||||
log.Debugf("attempting to run %s", c)
|
||||
|
||||
if err := internal.RunCmd(cmd); err != nil {
|
||||
if err := internal.RunCmd(c); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
@ -144,8 +145,8 @@ EXAMPLE:
|
||||
},
|
||||
}
|
||||
|
||||
func newAbraApp(version, commit string) *cli.App {
|
||||
app := &cli.App{
|
||||
func newAbraApp(version, commit string) *cli.Command {
|
||||
app := &cli.Command{
|
||||
Name: "abra",
|
||||
Usage: `the Co-op Cloud command-line utility belt 🎩🐇
|
||||
____ ____ _ _
|
||||
@ -164,12 +165,11 @@ func newAbraApp(version, commit string) *cli.App {
|
||||
&UpgradeCommand,
|
||||
&AutoCompleteCommand,
|
||||
},
|
||||
BashComplete: autocomplete.SubcommandComplete,
|
||||
EnableShellCompletion: true,
|
||||
ShellComplete: autocomplete.SubcommandComplete,
|
||||
}
|
||||
|
||||
app.EnableBashCompletion = true
|
||||
|
||||
app.Before = func(c *cli.Context) error {
|
||||
app.Before = func(ctx context.Context, cmd *cli.Command) error {
|
||||
paths := []string{
|
||||
config.ABRA_DIR,
|
||||
config.SERVERS_DIR,
|
||||
@ -200,7 +200,7 @@ func newAbraApp(version, commit string) *cli.App {
|
||||
func RunApp(version, commit string) {
|
||||
app := newAbraApp(version, commit)
|
||||
|
||||
if err := app.Run(os.Args); err != nil {
|
||||
if err := app.Run(context.Background(), os.Args); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user