refactor: domainName as arg and doc strings
continuous-integration/drone/push Build is passing Details

See coop-cloud/organising#163.
This commit is contained in:
decentral1se 2021-09-10 15:04:01 +02:00
parent 683ef0c3de
commit 99160967a8
No known key found for this signature in database
GPG Key ID: 5E2EF5A63E3718CC
4 changed files with 20 additions and 21 deletions

View File

@ -2,7 +2,6 @@ package server
import (
"context"
"errors"
"fmt"
"net"
"time"
@ -20,7 +19,7 @@ var serverInitCommand = &cli.Command{
Usage: "Initialise server for deploying apps",
Aliases: []string{"i"},
HideHelp: true,
ArgsUsage: "<server>",
ArgsUsage: "<domain>",
Description: `
Initialise swarm mode on the target <server>.
@ -29,12 +28,9 @@ the default IPv4 address as the advertising address. This can be re-configured
later for more advanced use cases.
`,
Action: func(c *cli.Context) error {
server := c.Args().First()
if server == "" {
internal.ShowSubcommandHelpAndError(c, errors.New("no server provided"))
}
domainName := internal.ValidateDomain(c)
cl, err := client.New(server)
cl, err := client.New(domainName)
if err != nil {
return err
}
@ -51,13 +47,13 @@ later for more advanced use cases.
}
ctx := context.Background()
ips, err := resolver.LookupIPAddr(ctx, server)
ips, err := resolver.LookupIPAddr(ctx, domainName)
if err != nil {
logrus.Fatal(err)
}
if len(ips) == 0 {
return fmt.Errorf("unable to retrieve ipv4 address for %s", server)
return fmt.Errorf("unable to retrieve ipv4 address for %s", domainName)
}
ipv4 := ips[0].IP.To4().String()

View File

@ -13,7 +13,7 @@ import (
var serverListCommand = &cli.Command{
Name: "list",
Aliases: []string{"ls"},
Usage: "List locally-defined servers.",
Usage: "List managed servers",
ArgsUsage: " ",
HideHelp: true,
Action: func(c *cli.Context) error {

View File

@ -241,10 +241,14 @@ environment variable or otherwise passing the "--env/-e" flag.
}
var serverNewCommand = &cli.Command{
Name: "new",
Usage: "Create a new server using a 3rd party provider",
Description: "Use a provider plugin to create a new server which can then be used to house a new Co-op Cloud installation.",
ArgsUsage: "<provider>",
Name: "new",
Aliases: []string{"n"},
Usage: "Create a new server using a 3rd party provider",
Description: `
Use a provider plugin to create a new server which can then be used to house a
new Co-op Cloud installation.
`,
ArgsUsage: "<provider>",
Subcommands: []*cli.Command{
serverNewHetznerCloudCommand,
serverNewCapsulCommand,

View File

@ -1,8 +1,6 @@
package server
import (
"errors"
"coopcloud.tech/abra/cli/internal"
"coopcloud.tech/abra/pkg/client"
"github.com/sirupsen/logrus"
@ -19,13 +17,14 @@ internal bookkeeping so that it is not managed any more.
`,
HideHelp: true,
Action: func(c *cli.Context) error {
server := c.Args().First()
if server == "" {
internal.ShowSubcommandHelpAndError(c, errors.New("no server provided"))
}
if err := client.DeleteContext(server); err != nil {
domainName := internal.ValidateDomain(c)
if err := client.DeleteContext(domainName); err != nil {
logrus.Fatal(err)
}
logrus.Infof("Server at '%s' has been forgotten", domainName)
return nil
},
}