refactor: moved a lot of flags & added comments

Comments added to fix the golint errors on exported things need comments
This commit is contained in:
Roxie Gibson 2021-08-02 07:36:35 +01:00
parent 9070806f8d
commit 38d8b51bd5
Signed by untrusted user: roxxers
GPG Key ID: 5D0140EDEE123F4D
18 changed files with 330 additions and 248 deletions

View File

@ -22,6 +22,7 @@ type Image struct {
URL string `json:"url"`
}
// Feature represents a JSON struct for a recipes features
type Feature struct {
Backups string `json:"backups"`
Email string `json:"email"`
@ -31,6 +32,7 @@ type Feature struct {
Tests string `json:"tests"`
}
// Tag represents a git tag
type Tag = string
type Service = string
type ServiceMeta struct {
@ -39,6 +41,7 @@ type ServiceMeta struct {
Tag string `json:"tag"`
}
// App reprents an App in the abra catalogue
type App struct {
Category string `json:"category"`
DefaultBranch string `json:"default_branch"`
@ -51,6 +54,7 @@ type App struct {
Website string `json:"website"`
}
// EnsureExists checks the app has been cloned locally
func (a App) EnsureExists() error {
appDir := path.Join(config.ABRA_DIR, "apps", strings.ToLower(a.Name))
if _, err := os.Stat(appDir); os.IsNotExist(err) {
@ -63,6 +67,7 @@ func (a App) EnsureExists() error {
return nil
}
// EnsureVersion checks if an given version is used for the app
func (a App) EnsureVersion(version string) error {
appDir := path.Join(config.ABRA_DIR, "apps", strings.ToLower(a.Name))
@ -103,6 +108,7 @@ func (a App) EnsureVersion(version string) error {
return nil
}
// LatestVersion returns the latest version of the app
func (a App) LatestVersion() string {
var latestVersion string
for tag := range a.Versions {
@ -115,6 +121,7 @@ func (a App) LatestVersion() string {
type Name = string
type AppsCatalogue map[Name]App
// Flatten converts AppCatalogue to slice
func (a AppsCatalogue) Flatten() []App {
apps := make([]App, 0, len(a))
for name := range a {
@ -131,11 +138,11 @@ func (a ByAppName) Less(i, j int) bool {
return strings.ToLower(a[i].Name) < strings.ToLower(a[j].Name)
}
var AppsCatalogueURL = "https://apps.coopcloud.tech"
var appsCatalogueURL = "https://apps.coopcloud.tech"
func AppsCatalogueFSIsLatest() (bool, error) {
func appsCatalogueFSIsLatest() (bool, error) {
httpClient := &http.Client{Timeout: 5 * time.Second}
res, err := httpClient.Head(AppsCatalogueURL)
res, err := httpClient.Head(appsCatalogueURL)
if err != nil {
return false, err
}
@ -166,47 +173,47 @@ func AppsCatalogueFSIsLatest() (bool, error) {
func ReadAppsCatalogue() (AppsCatalogue, error) {
apps := make(AppsCatalogue)
appsFSIsLatest, err := AppsCatalogueFSIsLatest()
appsFSIsLatest, err := appsCatalogueFSIsLatest()
if err != nil {
return nil, err
}
if !appsFSIsLatest {
if err := ReadAppsCatalogueWeb(&apps); err != nil {
if err := readAppsCatalogueWeb(&apps); err != nil {
return nil, err
}
return apps, nil
}
if err := ReadAppsCatalogueFS(&apps); err != nil {
if err := readAppsCatalogueFS(&apps); err != nil {
return nil, err
}
return apps, nil
}
func ReadAppsCatalogueFS(target interface{}) error {
appsJsonFS, err := ioutil.ReadFile(config.APPS_JSON)
func readAppsCatalogueFS(target interface{}) error {
appsJSONFS, err := ioutil.ReadFile(config.APPS_JSON)
if err != nil {
return err
}
if err := json.Unmarshal(appsJsonFS, &target); err != nil {
if err := json.Unmarshal(appsJSONFS, &target); err != nil {
return err
}
return nil
}
func ReadAppsCatalogueWeb(target interface{}) error {
if err := readJson(AppsCatalogueURL, &target); err != nil {
func readAppsCatalogueWeb(target interface{}) error {
if err := readJson(appsCatalogueURL, &target); err != nil {
return err
}
appsJson, err := json.MarshalIndent(target, "", " ")
appsJSON, err := json.MarshalIndent(target, "", " ")
if err != nil {
return err
}
if err := ioutil.WriteFile(config.APPS_JSON, appsJson, 0644); err != nil {
if err := ioutil.WriteFile(config.APPS_JSON, appsJSON, 0644); err != nil {
return err
}

View File

@ -4,6 +4,7 @@ import (
"github.com/urfave/cli/v2"
)
// AppCommand defines the `abra app` command and ets subcommands
var AppCommand = &cli.Command{
Name: "app",
Usage: "Manage your apps",

View File

@ -1,11 +1,18 @@
package app
import (
"coopcloud.tech/abra/cli/internal"
"github.com/urfave/cli/v2"
)
var backupAllServices bool
var backupAllServicesFlag = &cli.BoolFlag{
Name: "all",
Value: false,
Destination: &backupAllServices,
Usage: "Backup all services",
}
var appBackupCommand = &cli.Command{
Name: "backup",
Flags: []cli.Flag{internal.AllFlag},
Flags: []cli.Flag{backupAllServicesFlag},
}

View File

@ -1,16 +1,44 @@
package app
import (
"coopcloud.tech/abra/cli/internal"
"github.com/urfave/cli/v2"
)
var force bool
var forceFlag = &cli.BoolFlag{
Name: "force",
Value: false,
Destination: &force,
}
var update bool
var updateFlag = &cli.BoolFlag{
Name: "update",
Value: false,
Destination: &update,
}
var noDomainPoll bool
var noDomainPollFlag = &cli.BoolFlag{
Name: "no-domain-poll",
Value: false,
Destination: &noDomainPoll,
}
// skipVersionCheck stores the variable from SkipVersionCheckFlag
var skipVersionCheck bool
var skipVersionCheckFlag = &cli.BoolFlag{
Name: "skip-version-check",
Value: false,
Destination: &skipVersionCheck,
}
var appDeployCommand = &cli.Command{
Name: "deploy",
Flags: []cli.Flag{
internal.UpdateFlag,
internal.ForceFlag,
internal.SkipVersionCheckFlag,
internal.NoDomainPollFlag,
updateFlag,
forceFlag,
skipVersionCheckFlag,
noDomainPollFlag,
},
}

View File

@ -4,12 +4,38 @@ import (
"sort"
abraFormatter "coopcloud.tech/abra/cli/formatter"
"coopcloud.tech/abra/cli/internal"
"coopcloud.tech/abra/config"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
)
var status bool
var statusFlag = &cli.BoolFlag{
Name: "status",
Aliases: []string{"S"},
Value: false,
Usage: "Show app deployment status",
Destination: &status,
}
var appType string
var typeFlag = &cli.StringFlag{
Name: "type",
Aliases: []string{"t"},
Value: "",
Usage: "Show apps of a specific type",
Destination: &appType,
}
var listAppServer string
var listAppServerFlag = &cli.StringFlag{
Name: "server",
Aliases: []string{"s"},
Value: "",
Usage: "Show apps of a specific server",
Destination: &listAppServer,
}
var appListCommand = &cli.Command{
Name: "list",
Usage: "List all managed apps",
@ -22,9 +48,13 @@ actual live deployment status. Depending on how many servers you manage, this
can take some time.
`,
Aliases: []string{"ls"},
Flags: []cli.Flag{internal.StatusFlag, internal.ServerFlag, internal.TypeFlag},
Flags: []cli.Flag{
statusFlag,
listAppServerFlag,
typeFlag,
},
Action: func(c *cli.Context) error {
appFiles, err := config.LoadAppFiles(internal.Server)
appFiles, err := config.LoadAppFiles(listAppServer)
if err != nil {
logrus.Fatal(err)
}
@ -37,7 +67,7 @@ can take some time.
statuses := map[string]string{}
tableCol := []string{"Server", "Type", "Domain"}
if internal.Status {
if status {
tableCol = append(tableCol, "Status")
statuses, err = config.GetAppStatuses(appFiles)
if err != nil {
@ -50,10 +80,10 @@ can take some time.
for _, app := range apps {
var tableRow []string
if app.Type == internal.Type || internal.Type == "" {
if app.Type == appType || appType == "" {
// If type flag is set, check for it, if not, Type == ""
tableRow = []string{app.File.Server, app.Type, app.Domain}
if internal.Status {
if status {
if status, ok := statuses[app.StackName()]; ok {
tableRow = append(tableRow, status)
} else {

View File

@ -15,7 +15,34 @@ import (
"github.com/urfave/cli/v2"
)
type Secrets map[string]string
type secrets map[string]string
var domain string
var domainFlag = &cli.StringFlag{
Name: "domain",
Aliases: []string{"d"},
Value: "",
Usage: "Choose a domain name",
Destination: &domain,
}
var newAppServer string
var newAppServerFlag = &cli.StringFlag{
Name: "server",
Aliases: []string{"s"},
Value: "",
Usage: "Show apps of a specific server",
Destination: &listAppServer,
}
var newAppName string
var newAppNameFlag = &cli.StringFlag{
Name: "app-name",
Aliases: []string{"a"},
Value: "",
Usage: "Choose an app name",
Destination: &newAppName,
}
var appNewDescription = `
This command takes an app recipe and uses it to create a new app. This new app
@ -42,9 +69,9 @@ var appNewCommand = &cli.Command{
Usage: "Create a new app",
Description: appNewDescription,
Flags: []cli.Flag{
internal.ServerFlag,
internal.DomainFlag,
internal.AppNameFlag,
newAppServerFlag,
domainFlag,
newAppNameFlag,
internal.PassFlag,
internal.SecretsFlag,
},
@ -70,11 +97,11 @@ func appLookup(appType string) (catalogue.App, error) {
// ensureDomainFlag checks if the domain flag was used. if not, asks the user for it
func ensureDomainFlag() error {
if internal.Domain == "" {
if domain == "" {
prompt := &survey.Input{
Message: "Specify app domain",
}
if err := survey.AskOne(prompt, &internal.Domain); err != nil {
if err := survey.AskOne(prompt, &domain); err != nil {
return err
}
}
@ -83,17 +110,17 @@ func ensureDomainFlag() error {
// ensureServerFlag checks if the server flag was used. if not, asks the user for it
func ensureServerFlag() error {
appFiles, err := config.LoadAppFiles(internal.Server)
appFiles, err := config.LoadAppFiles(newAppServer)
if err != nil {
return err
}
servers := appFiles.GetServers()
if internal.Server == "" {
if newAppServer == "" {
prompt := &survey.Select{
Message: "Select app server:",
Options: servers,
}
if err := survey.AskOne(prompt, &internal.Server); err != nil {
if err := survey.AskOne(prompt, &newAppServer); err != nil {
return err
}
}
@ -102,27 +129,27 @@ func ensureServerFlag() error {
// ensureServerFlag checks if the AppName flag was used. if not, asks the user for it
func ensureAppNameFlag() error {
if internal.AppName == "" {
if newAppName == "" {
prompt := &survey.Input{
Message: "Specify app name:",
Default: config.SanitiseAppName(internal.Domain),
Default: config.SanitiseAppName(domain),
}
if err := survey.AskOne(prompt, &internal.AppName); err != nil {
if err := survey.AskOne(prompt, &newAppName); err != nil {
return err
}
}
return nil
}
func createSecrets(sanitisedAppName string) (Secrets, error) {
appEnvPath := path.Join(config.ABRA_DIR, "servers", internal.Server, fmt.Sprintf("%s.env", sanitisedAppName))
func createSecrets(sanitisedAppName string) (secrets, error) {
appEnvPath := path.Join(config.ABRA_DIR, "servers", newAppServer, fmt.Sprintf("%s.env", sanitisedAppName))
appEnv, err := config.ReadEnv(appEnvPath)
if err != nil {
return nil, err
}
secretEnvVars := secret.ReadSecretEnvVars(appEnv)
secrets, err := secret.GenerateSecrets(secretEnvVars, sanitisedAppName, internal.Server)
secrets, err := secret.GenerateSecrets(secretEnvVars, sanitisedAppName, newAppServer)
if err != nil {
return nil, err
}
@ -130,7 +157,7 @@ func createSecrets(sanitisedAppName string) (Secrets, error) {
if internal.Pass {
for secretName := range secrets {
secretValue := secrets[secretName]
if err := secret.PassInsertSecret(secretValue, secretName, sanitisedAppName, internal.Server); err != nil {
if err := secret.PassInsertSecret(secretValue, secretName, sanitisedAppName, newAppServer); err != nil {
return nil, err
}
}
@ -171,12 +198,12 @@ func action(c *cli.Context) error {
logrus.Fatal(err)
}
sanitisedAppName := config.SanitiseAppName(internal.AppName)
sanitisedAppName := config.SanitiseAppName(newAppName)
if len(sanitisedAppName) > 45 {
logrus.Fatalf("'%s' cannot be longer than 45 characters", sanitisedAppName)
}
if err := config.CopyAppEnvSample(appType, internal.AppName, internal.Server); err != nil {
if err := config.CopyAppEnvSample(appType, newAppName, newAppServer); err != nil {
logrus.Fatal(err)
}
@ -197,7 +224,7 @@ func action(c *cli.Context) error {
tableCol := []string{"Name", "Domain", "Type", "Server"}
table := abraFormatter.CreateTable(tableCol)
table.Append([]string{sanitisedAppName, internal.Domain, appType, internal.Server})
table.Append([]string{sanitisedAppName, domain, appType, newAppServer})
defer table.Render()
return nil

View File

@ -5,7 +5,20 @@ import (
"github.com/urfave/cli/v2"
)
var appRemoveCommand = &cli.Command{
Name: "remove",
Flags: []cli.Flag{internal.VolumesFlag, internal.SecretsFlag},
// Volumes stores the variable from VolumesFlag
var Volumes bool
// VolumesFlag is used to specify if volumes should be deleted when deleting an app
var VolumesFlag = &cli.BoolFlag{
Name: "volumes",
Value: false,
Destination: &Volumes,
}
var appRemoveCommand = &cli.Command{
Name: "remove",
Flags: []cli.Flag{
VolumesFlag,
internal.SecretsFlag,
},
}

View File

@ -1,12 +1,19 @@
package app
import (
"coopcloud.tech/abra/cli/internal"
"github.com/urfave/cli/v2"
)
var restoreAllServices bool
var restoreAllServicesFlag = &cli.BoolFlag{
Name: "all",
Value: false,
Destination: &restoreAllServices,
Usage: "Restore all services",
}
var appRestoreCommand = &cli.Command{
Name: "restore",
Flags: []cli.Flag{internal.AllFlag},
Flags: []cli.Flag{restoreAllServicesFlag},
ArgsUsage: "<service> [<backup file>]",
}

View File

@ -1,15 +1,28 @@
package app
import (
"coopcloud.tech/abra/cli/internal"
"github.com/urfave/cli/v2"
)
var user string
var userFlag = &cli.StringFlag{
Name: "user",
Value: "",
Destination: &user,
}
var noTTY bool
var noTTYFlag = &cli.BoolFlag{
Name: "no-tty",
Value: false,
Destination: &noTTY,
}
var appRunCommand = &cli.Command{
Name: "run",
Flags: []cli.Flag{
internal.NoTTYFlag,
internal.UserFlag,
noTTYFlag,
userFlag,
},
ArgsUsage: "<service> <args>...",
}

View File

@ -9,11 +9,19 @@ import (
"github.com/urfave/cli/v2"
)
var allSecrets bool
var allSecretsFlag = &cli.BoolFlag{
Name: "all",
Value: false,
Destination: &allSecrets,
Usage: "Generate all secrets",
}
// TODO: Replicating what the bash abra does might be hard
// with the mix of subcommands and flags
var appSecretCommand = &cli.Command{
Name: "secret",
Flags: []cli.Flag{internal.AllFlag, internal.PassFlag},
Flags: []cli.Flag{allSecretsFlag, internal.PassFlag},
Action: func(c *cli.Context) error {
password, err := secret.GeneratePassphrases(1)
if err != nil {

View File

@ -12,6 +12,103 @@ import (
"github.com/urfave/cli/v2"
)
// Verbose stores the variable from VerboseFlag
var Verbose bool
// VerboseFlag turns on/off verbose logging down to the INFO level
var VerboseFlag = &cli.BoolFlag{
Name: "verbose",
Aliases: []string{"V"},
Value: false,
Destination: &Verbose,
Usage: "Show INFO messages",
}
// Debug stores the variable from DebugFlag
var Debug bool
// DebugFlag turns on/off verbose logging down to the DEBUG level
var DebugFlag = &cli.BoolFlag{
Name: "debug",
Aliases: []string{"d"},
Value: false,
Destination: &Debug,
Usage: "Show DEBUG messages",
}
// NoPrompt stores the variable from NoPromptFlag
var NoPrompt bool
// NoPromptFlag turns on/off non-interactive mode where no user input is required
var NoPromptFlag = &cli.BoolFlag{
Name: "no-prompt",
Aliases: []string{"n"},
Value: false,
Destination: &NoPrompt,
Usage: "Don't prompt for input and run non-interactively",
}
// Env stores the variable from EnvFlag
var Env string
// EnvFlag takes a path to an env file to load variables from for the abra cli cmd
var EnvFlag = &cli.PathFlag{
Name: "env",
Aliases: []string{"e"},
Value: "",
Destination: &Env,
Usage: "Environment variables to load",
}
// Branch stores the variable from BranchFlag
var Branch string
// BranchFlag takes the name of the git branch to use in app cloning
var BranchFlag = &cli.StringFlag{
Name: "branch",
Aliases: []string{"b"},
Value: "",
Destination: &Branch,
Usage: "Git branch to use while cloning app repos",
}
// SkipUpdate stores the variable from SkipUpdateFlag
var SkipUpdate bool
// SkipUpdateFlag allows users to skip updating recipe definitions
var SkipUpdateFlag = &cli.BoolFlag{
Name: "skip-update",
Aliases: []string{"U"},
Value: false,
Destination: &SkipUpdate,
Usage: "Don't pull latest app definitions",
}
// SkipCheck stores the variable from SkipCheckFlag
var SkipCheck bool
// SkipCheckFlag allows users to skip checking app vars
var SkipCheckFlag = &cli.BoolFlag{
Name: "skip-check",
Aliases: []string{"C"},
Value: false,
Destination: &SkipCheck,
Usage: "Don't verify app variables",
}
// Stack stores the variable from StackFlag
var Stack string
// StackFlag gets the name of the target stack to run commands against
var StackFlag = &cli.StringFlag{
Name: "stack",
Aliases: []string{"s"},
Value: "",
Destination: &Stack,
Usage: "Name of the target stack",
}
// RunApp runs CLI abra app
func RunApp(version, commit string) {
app := &cli.App{
Name: "abra",
@ -32,14 +129,14 @@ func RunApp(version, commit string) {
VersionCommand,
},
Flags: []cli.Flag{
internal.EnvFlag,
internal.StackFlag,
internal.SkipCheckFlag,
internal.SkipUpdateFlag,
internal.VerboseFlag,
internal.BranchFlag,
internal.NoPromptFlag,
internal.DebugFlag,
EnvFlag,
StackFlag,
SkipCheckFlag,
SkipUpdateFlag,
VerboseFlag,
BranchFlag,
NoPromptFlag,
DebugFlag,
internal.ContextFlag,
},
}

View File

@ -4,47 +4,14 @@ import (
"github.com/urfave/cli/v2"
)
const EmptyArgsUsage = " " // Removes "[arguments]" from help. Empty str's are ignored
// Flags
var Status bool
var StatusFlag = &cli.BoolFlag{
Name: "status",
Aliases: []string{"S"},
Value: false,
Usage: "Show app deployment status",
Destination: &Status,
}
var Domain string
var DomainFlag = &cli.StringFlag{
Name: "domain",
Aliases: []string{"d"},
Value: "",
Usage: "Choose a domain name",
Destination: &Domain,
}
var Server string
var ServerFlag = &cli.StringFlag{
Name: "server",
Aliases: []string{"s"},
Value: "",
Usage: "Show apps of a specific server",
Destination: &Server,
}
var AppName string
var AppNameFlag = &cli.StringFlag{
Name: "app-name",
Aliases: []string{"a"},
Value: "",
Usage: "Choose an app name",
Destination: &AppName,
}
// AppName stores the variable from AppNameFlag
// Secrets stores the variable from SecretsFlag
var Secrets bool
// SecretsFlag turns on/off automatically generating secrets
var SecretsFlag = &cli.BoolFlag{
Name: "secrets",
Aliases: []string{"S"},
@ -53,7 +20,10 @@ var SecretsFlag = &cli.BoolFlag{
Destination: &Secrets,
}
// Pass stores the variable from PassFlag
var Pass bool
// PassFlag turns on/off storing generated secrets in pass
var PassFlag = &cli.BoolFlag{
Name: "pass",
Aliases: []string{"P"},
@ -62,138 +32,10 @@ var PassFlag = &cli.BoolFlag{
Destination: &Pass,
}
var Force bool
var ForceFlag = &cli.BoolFlag{
Name: "force",
Value: false,
Destination: &Force,
}
var Update bool
var UpdateFlag = &cli.BoolFlag{
Name: "update",
Value: false,
Destination: &Update,
}
var NoDomainPoll bool
var NoDomainPollFlag = &cli.BoolFlag{
Name: "no-domain-poll",
Value: false,
Destination: &NoDomainPoll,
}
var SkipVersionCheck bool
var SkipVersionCheckFlag = &cli.BoolFlag{
Name: "skip-version-check",
Value: false,
Destination: &SkipVersionCheck,
}
var Volumes bool
var VolumesFlag = &cli.BoolFlag{
Name: "volumes",
Value: false,
Destination: &Volumes,
}
var All bool
var AllFlag = &cli.BoolFlag{
Name: "all",
Aliases: []string{"A"},
Value: false,
Usage: "Generate all secrets",
Destination: &All,
}
var NoTTY bool
var NoTTYFlag = &cli.BoolFlag{
Name: "no-tty",
Value: false,
Destination: &NoTTY,
}
var User string
var UserFlag = &cli.StringFlag{
Name: "user",
Value: "",
Destination: &User,
}
var Env string
var EnvFlag = &cli.PathFlag{
Name: "env",
Aliases: []string{"e"},
Value: "",
Destination: &Env,
}
var Verbose bool
var VerboseFlag = &cli.BoolFlag{
Name: "verbose",
Aliases: []string{"V"},
Value: false,
Destination: &Verbose,
}
var Debug bool
var DebugFlag = &cli.BoolFlag{
Name: "debug",
Aliases: []string{"d"},
Value: false,
Destination: &Debug,
}
var NoPrompt bool
var NoPromptFlag = &cli.BoolFlag{
Name: "no-prompt",
Aliases: []string{"n"},
Value: false,
Destination: &NoPrompt,
}
var Branch string
var BranchFlag = &cli.StringFlag{
Name: "branch",
Aliases: []string{"b"},
Value: "",
Destination: &Branch,
}
var SkipUpdate bool
var SkipUpdateFlag = &cli.BoolFlag{
Name: "skip-update",
Aliases: []string{"U"},
Value: false,
Destination: &SkipUpdate,
}
var SkipCheck bool
var SkipCheckFlag = &cli.BoolFlag{
Name: "skip-check",
Aliases: []string{"C"},
Value: false,
Destination: &SkipCheck,
}
var Stack string
var StackFlag = &cli.StringFlag{
Name: "stack",
Aliases: []string{"s"},
Value: "",
Destination: &Stack,
}
var Type string
var TypeFlag = &cli.StringFlag{
Name: "type",
Aliases: []string{"t"},
Value: "",
Usage: "Show apps of a specific type",
Destination: &Type,
}
// Context is temp
var Context string
// ContextFlag is temp
var ContextFlag = &cli.StringFlag{
Name: "context",
Value: "",

View File

@ -7,7 +7,7 @@ import (
"github.com/urfave/cli/v2"
)
// showSubcommandHelpAndError exits the program on error, logs the error to the terminal, and shows the help command.
// ShowSubcommandHelpAndError exits the program on error, logs the error to the terminal, and shows the help command.
func ShowSubcommandHelpAndError(c *cli.Context, err interface{}) {
if err2 := cli.ShowSubcommandHelp(c); err2 != nil {
// go-critic wants me to check this error but if this throws an error while we throw an error that would be annoying

View File

@ -142,6 +142,7 @@ var recipeCreateCommand = &cli.Command{
},
}
// RecipeCommand defines the `abra recipe` command and ets subcommands
var RecipeCommand = &cli.Command{
Name: "recipe",
Usage: "Manage app recipes",

View File

@ -14,10 +14,10 @@ var serverAddCommand = &cli.Command{
ArgsUsage: "<host> [<user>] [<port>]",
Description: "[<user>], [<port>] SSH connection details",
Action: func(c *cli.Context) error {
arg_len := c.Args().Len()
argLen := c.Args().Len()
args := c.Args().Slice()
if arg_len < 3 {
args = append(args, make([]string, 3-arg_len)...)
if argLen < 3 {
args = append(args, make([]string, 3-argLen)...)
}
if err := client.CreateContext(args[0], args[1], args[2]); err != nil {
logrus.Fatal(err)

View File

@ -8,11 +8,11 @@ import (
"github.com/urfave/cli/v2"
)
var HetznerCloudType string
var HetznerCloudImage string
var HetznerCloudSSHKeys cli.StringSlice
var HetznerCloudLocation string
var HetznerCloudAPIToken string
var hetznerCloudType string
var hetznerCloudImage string
var hetznerCloudSSHKeys cli.StringSlice
var hetznerCloudLocation string
var hetznerCloudAPIToken string
var serverNewHetznerCloudCommand = &cli.Command{
Name: "hetzner",
Usage: "Create a new Hetzner virtual server",
@ -32,7 +32,7 @@ environment variable or otherwise passing the "--env/-e" flag.
Name: "type",
Aliases: []string{"t"},
Usage: "Server type",
Destination: &HetznerCloudType,
Destination: &hetznerCloudType,
Value: "cx11",
},
&cli.StringFlag{
@ -40,27 +40,27 @@ environment variable or otherwise passing the "--env/-e" flag.
Aliases: []string{"i"},
Usage: "Image type",
Value: "debian-10",
Destination: &HetznerCloudImage,
Destination: &hetznerCloudImage,
},
&cli.StringSliceFlag{
Name: "ssh-keys",
Aliases: []string{"s"},
Usage: "SSH keys",
Destination: &HetznerCloudSSHKeys,
Destination: &hetznerCloudSSHKeys,
},
&cli.StringFlag{
Name: "location",
Aliases: []string{"l"},
Usage: "Server location",
Value: "hel1",
Destination: &HetznerCloudLocation,
Destination: &hetznerCloudLocation,
},
&cli.StringFlag{
Name: "token",
Aliases: []string{"T"},
Usage: "Hetzner Cloud API token",
EnvVars: []string{"HCLOUD_API_TOKEN"},
Destination: &HetznerCloudAPIToken,
Destination: &hetznerCloudAPIToken,
},
},
Action: func(c *cli.Context) error {
@ -70,7 +70,7 @@ environment variable or otherwise passing the "--env/-e" flag.
}
ctx := context.Background()
client := hcloud.NewClient(hcloud.WithToken(HetznerCloudAPIToken))
client := hcloud.NewClient(hcloud.WithToken(hetznerCloudAPIToken))
// var sshkeys []hcloud.SSHKey
// for _, sshkey := range HetznerCloudSSHKeys {
@ -80,8 +80,8 @@ environment variable or otherwise passing the "--env/-e" flag.
// TODO: finish passing arguments
serverOpts := hcloud.ServerCreateOpts{
Name: name,
ServerType: &hcloud.ServerType{Name: HetznerCloudType},
Image: &hcloud.Image{Name: HetznerCloudImage},
ServerType: &hcloud.ServerType{Name: hetznerCloudType},
Image: &hcloud.Image{Name: hetznerCloudImage},
// SSHKeys: HetznerCloudSSHKeys,
// Location: HetznerCloudLocation,
}

View File

@ -4,7 +4,7 @@ import (
"github.com/urfave/cli/v2"
)
// Reminder: The list commands are in is the order they appear in the help menu
// ServerCommand defines the `abra server` command and ets subcommands
var ServerCommand = &cli.Command{
Name: "server",
ArgsUsage: "<host>",

View File

@ -4,6 +4,7 @@ import (
"github.com/urfave/cli/v2"
)
// VersionCommand prints the version of abra
var VersionCommand = &cli.Command{
Name: "version",
Usage: "Print the version",