Compare commits

...

1 Commits

Author SHA1 Message Date
1bdf1fcfae
wip: refactor!: migrate to cobra
Some checks failed
continuous-integration/drone/push Build is failing
continuous-integration/drone/pr Build is passing
2024-07-18 21:39:10 +02:00
4 changed files with 63 additions and 21 deletions

View File

@ -18,6 +18,7 @@ import (
"coopcloud.tech/abra/pkg/log" "coopcloud.tech/abra/pkg/log"
"coopcloud.tech/abra/pkg/web" "coopcloud.tech/abra/pkg/web"
charmLog "github.com/charmbracelet/log" charmLog "github.com/charmbracelet/log"
"github.com/spf13/cobra"
"github.com/urfave/cli" "github.com/urfave/cli"
) )
@ -112,38 +113,30 @@ source /etc/fish/completions/abra
} }
// UpgradeCommand upgrades abra in-place. // UpgradeCommand upgrades abra in-place.
var UpgradeCommand = cli.Command{ var UpgradeCommand = &cobra.Command{
Name: "upgrade", Use: "upgrade",
Aliases: []string{"u"}, Aliases: []string{"u"},
Usage: "Upgrade abra", Short: "Upgrade abra",
Description: ` Example: "abra upgrade",
Upgrade abra in-place with the latest stable or release candidate. Long: `Upgrade abra in-place with the latest stable or release candidate.
Use "-r/--rc" to install the latest release candidate. Please bear in mind that Use "-r/--rc" to install the latest release candidate. Please bear in mind that
it may contain absolutely catastrophic deal-breaker bugs. Thank you very much it may contain absolutely catastrophic deal-breaker bugs. Thank you very much
for the testing efforts 💗 for the testing efforts 💗`,
Run: func(cmd *cobra.Command, args []string) {
EXAMPLE:
abra upgrade
abra upgrade --rc`,
Flags: []cli.Flag{internal.RCFlag},
Action: func(c *cli.Context) error {
mainURL := "https://install.abra.coopcloud.tech" mainURL := "https://install.abra.coopcloud.tech"
cmd := exec.Command("bash", "-c", fmt.Sprintf("wget -q -O- %s | bash", mainURL)) comm := exec.Command("bash", "-c", fmt.Sprintf("wget -q -O- %s | bash", mainURL))
if internal.RC { if internal.RC {
releaseCandidateURL := "https://git.coopcloud.tech/coop-cloud/abra/raw/branch/main/scripts/installer/installer" 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)) comm = 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", cmd)
if err := internal.RunCmd(cmd); err != nil { if err := internal.RunCmd(comm); err != nil {
log.Fatal(err) log.Fatal(err)
} }
return nil
}, },
} }
@ -164,7 +157,6 @@ func newAbraApp(version, commit string) *cli.App {
server.ServerCommand, server.ServerCommand,
recipe.RecipeCommand, recipe.RecipeCommand,
catalogue.CatalogueCommand, catalogue.CatalogueCommand,
UpgradeCommand,
AutoCompleteCommand, AutoCompleteCommand,
}, },
BashComplete: autocomplete.SubcommandComplete, BashComplete: autocomplete.SubcommandComplete,
@ -209,3 +201,7 @@ func RunApp(version, commit string) {
log.Fatal(err) log.Fatal(err)
} }
} }
func init() {
UpgradeCommand.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}

46
cli/newcli.go Normal file
View File

@ -0,0 +1,46 @@
package cli
import (
"fmt"
"coopcloud.tech/abra/pkg/log"
"github.com/spf13/cobra"
)
var (
Debug bool
Offline bool
NoInput bool
)
func RunApp2(version, commit string) {
rootCmd := &cobra.Command{
Use: "abra",
Short: "The Co-op Cloud command-line utility belt 🎩🐇",
Version: fmt.Sprintf("%s-%s", version, commit[:7]),
PreRun: func(cmd *cobra.Command, args []string) {
log.Info("HELLO LOGGING")
},
}
rootCmd.PersistentFlags().BoolVarP(
&Debug, "debug", "d", false,
"show debug messages",
)
rootCmd.PersistentFlags().BoolVarP(
&NoInput, "no-input", "n", false,
"toggle non-interactive mode",
)
rootCmd.PersistentFlags().BoolVarP(
&Offline, "offline", "o", false,
"prefer offline & filesystem access",
)
rootCmd.AddCommand(UpgradeCommand)
if err := rootCmd.Execute(); err != nil {
log.Fatal(err)
}
}

View File

@ -19,5 +19,5 @@ func main() {
Commit = " " Commit = " "
} }
cli.RunApp(Version, Commit) cli.RunApp2(Version, Commit)
} }

2
go.mod
View File

@ -130,7 +130,7 @@ require (
github.com/opencontainers/image-spec v1.1.0 // indirect github.com/opencontainers/image-spec v1.1.0 // indirect
github.com/prometheus/client_golang v1.19.1 // indirect github.com/prometheus/client_golang v1.19.1 // indirect
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
github.com/spf13/cobra v1.8.1 // indirect github.com/spf13/cobra v1.8.1
github.com/stretchr/testify v1.9.0 github.com/stretchr/testify v1.9.0
github.com/theupdateframework/notary v0.7.0 // indirect github.com/theupdateframework/notary v0.7.0 // indirect
github.com/urfave/cli v1.22.15 github.com/urfave/cli v1.22.15