wip: refactor!: migrate to cobra #443
34
cli/cli.go
34
cli/cli.go
@ -18,6 +18,7 @@ import (
|
||||
"coopcloud.tech/abra/pkg/log"
|
||||
"coopcloud.tech/abra/pkg/web"
|
||||
charmLog "github.com/charmbracelet/log"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
@ -112,38 +113,30 @@ source /etc/fish/completions/abra
|
||||
}
|
||||
|
||||
// UpgradeCommand upgrades abra in-place.
|
||||
var UpgradeCommand = cli.Command{
|
||||
Name: "upgrade",
|
||||
var UpgradeCommand = &cobra.Command{
|
||||
Use: "upgrade",
|
||||
Aliases: []string{"u"},
|
||||
Usage: "Upgrade abra",
|
||||
Description: `
|
||||
Upgrade abra in-place with the latest stable or release candidate.
|
||||
Short: "Upgrade abra",
|
||||
Example: "abra upgrade",
|
||||
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
|
||||
it may contain absolutely catastrophic deal-breaker bugs. Thank you very much
|
||||
for the testing efforts 💗
|
||||
|
||||
EXAMPLE:
|
||||
|
||||
abra upgrade
|
||||
abra upgrade --rc`,
|
||||
Flags: []cli.Flag{internal.RCFlag},
|
||||
Action: func(c *cli.Context) error {
|
||||
for the testing efforts 💗`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
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 {
|
||||
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)
|
||||
|
||||
if err := internal.RunCmd(cmd); err != nil {
|
||||
if err := internal.RunCmd(comm); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
|
||||
@ -164,7 +157,6 @@ func newAbraApp(version, commit string) *cli.App {
|
||||
server.ServerCommand,
|
||||
recipe.RecipeCommand,
|
||||
catalogue.CatalogueCommand,
|
||||
UpgradeCommand,
|
||||
AutoCompleteCommand,
|
||||
},
|
||||
BashComplete: autocomplete.SubcommandComplete,
|
||||
@ -209,3 +201,7 @@ func RunApp(version, commit string) {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
UpgradeCommand.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
||||
}
|
||||
|
46
cli/newcli.go
Normal file
46
cli/newcli.go
Normal 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)
|
||||
}
|
||||
}
|
@ -19,5 +19,5 @@ func main() {
|
||||
Commit = " "
|
||||
}
|
||||
|
||||
cli.RunApp(Version, Commit)
|
||||
cli.RunApp2(Version, Commit)
|
||||
}
|
||||
|
2
go.mod
2
go.mod
@ -130,7 +130,7 @@ require (
|
||||
github.com/opencontainers/image-spec v1.1.0 // indirect
|
||||
github.com/prometheus/client_golang v1.19.1 // 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/theupdateframework/notary v0.7.0 // indirect
|
||||
github.com/urfave/cli v1.22.15
|
||||
|
Loading…
x
Reference in New Issue
Block a user