diff --git a/cli/app.go b/cli/app.go new file mode 100644 index 00000000..790ba57e --- /dev/null +++ b/cli/app.go @@ -0,0 +1,74 @@ +package cli + +import "github.com/urfave/cli/v2" + +var appNewCommand = &cli.Command{ + Name: "new", +} +var appDeployCommand = &cli.Command{ + Name: "deploy", +} +var appUndeployCommand = &cli.Command{ + Name: "undeploy", +} +var appBackupCommand = &cli.Command{ + Name: "backup", +} +var appRestoreCommand = &cli.Command{ + Name: "restore", +} +var appListCommand = &cli.Command{ + Name: "list", +} +var appCheckCommand = &cli.Command{ + Name: "check", +} +var appCpCommand = &cli.Command{ + Name: "cp", +} +var appConfigCommand = &cli.Command{ + Name: "config", +} +var appLogsCommand = &cli.Command{ + Name: "logs", +} + +var appPsCommand = &cli.Command{ + Name: "ps", +} +var appRemoveCommand = &cli.Command{ + Name: "remove", +} +var appRunCommand = &cli.Command{ + Name: "run", +} + +var appRollbackCommand = &cli.Command{ + Name: "rollback", +} + +var appSecretCommand = &cli.Command{ + Name: "secret", +} + +var AppCommand = &cli.Command{ + Name: "app", + HideHelp: true, + Subcommands: []*cli.Command{ + appNewCommand, + appConfigCommand, + appDeployCommand, + appUndeployCommand, + appBackupCommand, + appRestoreCommand, + appRemoveCommand, + appCheckCommand, + appListCommand, + appPsCommand, + appLogsCommand, + appCpCommand, + appRunCommand, + appRollbackCommand, + appSecretCommand, + }, +} diff --git a/cli/cli.go b/cli/cli.go new file mode 100644 index 00000000..dece786e --- /dev/null +++ b/cli/cli.go @@ -0,0 +1,39 @@ +package cli + +import ( + "fmt" + "log" + "os" + + "github.com/urfave/cli/v2" +) + +func RunApp(version, commit string) { + app := &cli.App{ + Name: "abra", + Usage: "The cooperative cloud utility belt 🎩🐇", + Version: fmt.Sprintf("%s-%s", version, commit[:7]), + Commands: []*cli.Command{ + AppCommand, + ServerCommand, + { + + Name: "recipe", + HideHelp: true, + Subcommands: []*cli.Command{ + { + Name: "list", + }, + { + Name: "create", + }, + }, + }, + }, + } + + err := app.Run(os.Args) + if err != nil { + log.Fatal(err) + } +} diff --git a/cli/common.go b/cli/common.go new file mode 100644 index 00000000..adb0dd55 --- /dev/null +++ b/cli/common.go @@ -0,0 +1,3 @@ +package cli + +const emptyArgsUsage = " " // Removes "[arguments]" from help. Empty str's are ignored diff --git a/cli/server.go b/cli/server.go new file mode 100644 index 00000000..24055078 --- /dev/null +++ b/cli/server.go @@ -0,0 +1,81 @@ +package cli + +import ( + "fmt" + + "github.com/urfave/cli/v2" +) + +var serverListCommand = &cli.Command{ + Name: "list", + Aliases: []string{"ls"}, + Usage: "List locally-defined servers.", + ArgsUsage: emptyArgsUsage, + HideHelp: true, +} + +var serverAddCommand = &cli.Command{ + Name: "add", + Usage: "Add a server, reachable on .", + ArgsUsage: " [] []", + Description: "[], [] SSH connection details", +} + +var serverNewCommand = &cli.Command{ + Name: "new", + Usage: "Creates a VPS from a provider in your terminal!", + Description: "Use a provider plugin to create an actual new server resource (VPS or otherwise) which can then be used to house a new Co-op Cloud installation.", + ArgsUsage: "", + HideHelp: true, +} + +var serverRemoveCommand = &cli.Command{ + Name: "remove", + Aliases: []string{"rm"}, + Usage: "Remove server ", + HideHelp: true, +} + +var serverInitCommand = &cli.Command{ + Name: "init", + Usage: "Set up a server for Docker swarm", + HideHelp: true, + ArgsUsage: "", + Description: `This initialisation explicitly chooses the "single host swarm" mode +which uses the default IPv4 address as the advertising address. This +can be re-configured later for more advanced use cases. + +POWERED BY +docker swarm init +docker network create ...`, +} + +var serverAppsCommand = &cli.Command{ + Name: "apps", + Usage: `Alias for "abra app ls --server "`, + HideHelp: true, + ArgsUsage: " ", // Removes "[arguments]" from help. Empty str's are ignored + Flags: []cli.Flag{ + &cli.BoolFlag{ + Name: "status", + Value: false, + }, + }, +} + +// Reminder: The list commands are in is the order they appear in the help menu +var ServerCommand = &cli.Command{ + Name: "server", + ArgsUsage: "", + Usage: "Interact with the servers hosting your Coop-Cloud apps", + HideHelp: true, + Subcommands: []*cli.Command{ + serverNewCommand, + serverInitCommand, + serverAddCommand, + serverListCommand, + serverRemoveCommand, + serverAppsCommand, + }, + Action: func(c *cli.Context) error { fmt.Println("server"); return nil }, +} diff --git a/cmd/abra/main.go b/cmd/abra/main.go index 9382aac9..686f5e5c 100644 --- a/cmd/abra/main.go +++ b/cmd/abra/main.go @@ -1,87 +1,19 @@ package main -import ( - "fmt" - "log" - "os" - - "github.com/urfave/cli/v2" -) +import "coopcloud.tech/abra/cli" var Version string var Commit string func main() { - app := &cli.App{ - Name: "abra", - Usage: "The cooperative cloud utility belt 🎩🐇", - Version: fmt.Sprintf("%s-%s", Version, Commit[:7]), - Commands: []*cli.Command{ - { - Name: "server", - ArgsUsage: "", - Usage: "Interact with the servers hosting your Coop-Cloud apps", - Subcommands: []*cli.Command{ - { - Name: "list", - Aliases: []string{"ls"}, - Usage: "List locally-defined servers.", - ArgsUsage: " ", // Removes "[arguments]" from help. Empty str's are ignored - HideHelp: true, - }, - { - Name: "add", - Usage: "Add a server, reachable on .", - ArgsUsage: " [] []", - Description: "[], [] SSH connection details", - HideHelp: true, - }, - { - Name: "new", - Usage: "Creates a VPS from a provider in your terminal!", - Description: "Use a provider plugin to create an actual new server resource (VPS or otherwise) which can then be used to house a new Co-op Cloud installation.", - ArgsUsage: "", - HideHelp: true, - }, - { - Name: "remove", - Aliases: []string{"rm"}, - Usage: "Remove server ", - HideHelp: true, - }, - { - Name: "init", - Usage: "Set up a server for Docker swarm", - HideHelp: true, - ArgsUsage: "", - Description: `This initialisation explicitly chooses the "single host swarm" mode -which uses the default IPv4 address as the advertising address. This -can be re-configured later for more advanced use cases. - -POWERED BY - docker swarm init - docker network create ...`, - }, - { - Name: "apps", - Usage: `Alias for "abra app ls --server "`, - HideHelp: true, - ArgsUsage: " ", // Removes "[arguments]" from help. Empty str's are ignored - Flags: []cli.Flag{ - &cli.BoolFlag{ - Name: "status", - Value: false, - }, - }, - }, - }, - Action: func(c *cli.Context) error { fmt.Println("server"); return nil }, - }, - }, + // If not set in the ld-flags + if Version == "" { + Version = "dev" + } + if Commit == "" { + Commit = " " } - err := app.Run(os.Args) - if err != nil { - log.Fatal(err) - } + cli.RunApp(Version, Commit) + }