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

View File

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

View File

@ -1,11 +1,18 @@
package app package app
import ( import (
"coopcloud.tech/abra/cli/internal"
"github.com/urfave/cli/v2" "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{ var appBackupCommand = &cli.Command{
Name: "backup", Name: "backup",
Flags: []cli.Flag{internal.AllFlag}, Flags: []cli.Flag{backupAllServicesFlag},
} }

View File

@ -1,16 +1,44 @@
package app package app
import ( import (
"coopcloud.tech/abra/cli/internal"
"github.com/urfave/cli/v2" "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{ var appDeployCommand = &cli.Command{
Name: "deploy", Name: "deploy",
Flags: []cli.Flag{ Flags: []cli.Flag{
internal.UpdateFlag, updateFlag,
internal.ForceFlag, forceFlag,
internal.SkipVersionCheckFlag, skipVersionCheckFlag,
internal.NoDomainPollFlag, noDomainPollFlag,
}, },
} }

View File

@ -4,12 +4,38 @@ import (
"sort" "sort"
abraFormatter "coopcloud.tech/abra/cli/formatter" abraFormatter "coopcloud.tech/abra/cli/formatter"
"coopcloud.tech/abra/cli/internal"
"coopcloud.tech/abra/config" "coopcloud.tech/abra/config"
"github.com/sirupsen/logrus" "github.com/sirupsen/logrus"
"github.com/urfave/cli/v2" "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{ var appListCommand = &cli.Command{
Name: "list", Name: "list",
Usage: "List all managed apps", 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. can take some time.
`, `,
Aliases: []string{"ls"}, Aliases: []string{"ls"},
Flags: []cli.Flag{internal.StatusFlag, internal.ServerFlag, internal.TypeFlag}, Flags: []cli.Flag{
statusFlag,
listAppServerFlag,
typeFlag,
},
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
appFiles, err := config.LoadAppFiles(internal.Server) appFiles, err := config.LoadAppFiles(listAppServer)
if err != nil { if err != nil {
logrus.Fatal(err) logrus.Fatal(err)
} }
@ -37,7 +67,7 @@ can take some time.
statuses := map[string]string{} statuses := map[string]string{}
tableCol := []string{"Server", "Type", "Domain"} tableCol := []string{"Server", "Type", "Domain"}
if internal.Status { if status {
tableCol = append(tableCol, "Status") tableCol = append(tableCol, "Status")
statuses, err = config.GetAppStatuses(appFiles) statuses, err = config.GetAppStatuses(appFiles)
if err != nil { if err != nil {
@ -50,10 +80,10 @@ can take some time.
for _, app := range apps { for _, app := range apps {
var tableRow []string 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 == "" // If type flag is set, check for it, if not, Type == ""
tableRow = []string{app.File.Server, app.Type, app.Domain} tableRow = []string{app.File.Server, app.Type, app.Domain}
if internal.Status { if status {
if status, ok := statuses[app.StackName()]; ok { if status, ok := statuses[app.StackName()]; ok {
tableRow = append(tableRow, status) tableRow = append(tableRow, status)
} else { } else {

View File

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

View File

@ -5,7 +5,20 @@ import (
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
) )
var appRemoveCommand = &cli.Command{ // Volumes stores the variable from VolumesFlag
Name: "remove", var Volumes bool
Flags: []cli.Flag{internal.VolumesFlag, internal.SecretsFlag},
// 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 package app
import ( import (
"coopcloud.tech/abra/cli/internal"
"github.com/urfave/cli/v2" "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{ var appRestoreCommand = &cli.Command{
Name: "restore", Name: "restore",
Flags: []cli.Flag{internal.AllFlag}, Flags: []cli.Flag{restoreAllServicesFlag},
ArgsUsage: "<service> [<backup file>]", ArgsUsage: "<service> [<backup file>]",
} }

View File

@ -1,15 +1,28 @@
package app package app
import ( import (
"coopcloud.tech/abra/cli/internal"
"github.com/urfave/cli/v2" "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{ var appRunCommand = &cli.Command{
Name: "run", Name: "run",
Flags: []cli.Flag{ Flags: []cli.Flag{
internal.NoTTYFlag, noTTYFlag,
internal.UserFlag, userFlag,
}, },
ArgsUsage: "<service> <args>...", ArgsUsage: "<service> <args>...",
} }

View File

@ -9,11 +9,19 @@ import (
"github.com/urfave/cli/v2" "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 // TODO: Replicating what the bash abra does might be hard
// with the mix of subcommands and flags // with the mix of subcommands and flags
var appSecretCommand = &cli.Command{ var appSecretCommand = &cli.Command{
Name: "secret", Name: "secret",
Flags: []cli.Flag{internal.AllFlag, internal.PassFlag}, Flags: []cli.Flag{allSecretsFlag, internal.PassFlag},
Action: func(c *cli.Context) error { Action: func(c *cli.Context) error {
password, err := secret.GeneratePassphrases(1) password, err := secret.GeneratePassphrases(1)
if err != nil { if err != nil {

View File

@ -12,6 +12,103 @@ import (
"github.com/urfave/cli/v2" "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) { func RunApp(version, commit string) {
app := &cli.App{ app := &cli.App{
Name: "abra", Name: "abra",
@ -32,14 +129,14 @@ func RunApp(version, commit string) {
VersionCommand, VersionCommand,
}, },
Flags: []cli.Flag{ Flags: []cli.Flag{
internal.EnvFlag, EnvFlag,
internal.StackFlag, StackFlag,
internal.SkipCheckFlag, SkipCheckFlag,
internal.SkipUpdateFlag, SkipUpdateFlag,
internal.VerboseFlag, VerboseFlag,
internal.BranchFlag, BranchFlag,
internal.NoPromptFlag, NoPromptFlag,
internal.DebugFlag, DebugFlag,
internal.ContextFlag, internal.ContextFlag,
}, },
} }

View File

@ -4,47 +4,14 @@ import (
"github.com/urfave/cli/v2" "github.com/urfave/cli/v2"
) )
const EmptyArgsUsage = " " // Removes "[arguments]" from help. Empty str's are ignored
// Flags // Flags
var Status bool // AppName stores the variable from AppNameFlag
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,
}
// Secrets stores the variable from SecretsFlag
var Secrets bool var Secrets bool
// SecretsFlag turns on/off automatically generating secrets
var SecretsFlag = &cli.BoolFlag{ var SecretsFlag = &cli.BoolFlag{
Name: "secrets", Name: "secrets",
Aliases: []string{"S"}, Aliases: []string{"S"},
@ -53,7 +20,10 @@ var SecretsFlag = &cli.BoolFlag{
Destination: &Secrets, Destination: &Secrets,
} }
// Pass stores the variable from PassFlag
var Pass bool var Pass bool
// PassFlag turns on/off storing generated secrets in pass
var PassFlag = &cli.BoolFlag{ var PassFlag = &cli.BoolFlag{
Name: "pass", Name: "pass",
Aliases: []string{"P"}, Aliases: []string{"P"},
@ -62,138 +32,10 @@ var PassFlag = &cli.BoolFlag{
Destination: &Pass, Destination: &Pass,
} }
var Force bool // Context is temp
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,
}
var Context string var Context string
// ContextFlag is temp
var ContextFlag = &cli.StringFlag{ var ContextFlag = &cli.StringFlag{
Name: "context", Name: "context",
Value: "", Value: "",

View File

@ -7,7 +7,7 @@ import (
"github.com/urfave/cli/v2" "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{}) { func ShowSubcommandHelpAndError(c *cli.Context, err interface{}) {
if err2 := cli.ShowSubcommandHelp(c); err2 != nil { 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 // 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{ var RecipeCommand = &cli.Command{
Name: "recipe", Name: "recipe",
Usage: "Manage app recipes", Usage: "Manage app recipes",

View File

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

View File

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

View File

@ -4,7 +4,7 @@ import (
"github.com/urfave/cli/v2" "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{ var ServerCommand = &cli.Command{
Name: "server", Name: "server",
ArgsUsage: "<host>", ArgsUsage: "<host>",

View File

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