refactor: domainName as arg and doc strings
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
See coop-cloud/organising#163.
This commit is contained in:
parent
683ef0c3de
commit
99160967a8
|
@ -2,7 +2,6 @@ package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"time"
|
"time"
|
||||||
|
@ -20,7 +19,7 @@ var serverInitCommand = &cli.Command{
|
||||||
Usage: "Initialise server for deploying apps",
|
Usage: "Initialise server for deploying apps",
|
||||||
Aliases: []string{"i"},
|
Aliases: []string{"i"},
|
||||||
HideHelp: true,
|
HideHelp: true,
|
||||||
ArgsUsage: "<server>",
|
ArgsUsage: "<domain>",
|
||||||
Description: `
|
Description: `
|
||||||
Initialise swarm mode on the target <server>.
|
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.
|
later for more advanced use cases.
|
||||||
`,
|
`,
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
server := c.Args().First()
|
domainName := internal.ValidateDomain(c)
|
||||||
if server == "" {
|
|
||||||
internal.ShowSubcommandHelpAndError(c, errors.New("no server provided"))
|
|
||||||
}
|
|
||||||
|
|
||||||
cl, err := client.New(server)
|
cl, err := client.New(domainName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -51,13 +47,13 @@ later for more advanced use cases.
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
ips, err := resolver.LookupIPAddr(ctx, server)
|
ips, err := resolver.LookupIPAddr(ctx, domainName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(ips) == 0 {
|
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()
|
ipv4 := ips[0].IP.To4().String()
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ import (
|
||||||
var serverListCommand = &cli.Command{
|
var serverListCommand = &cli.Command{
|
||||||
Name: "list",
|
Name: "list",
|
||||||
Aliases: []string{"ls"},
|
Aliases: []string{"ls"},
|
||||||
Usage: "List locally-defined servers.",
|
Usage: "List managed servers",
|
||||||
ArgsUsage: " ",
|
ArgsUsage: " ",
|
||||||
HideHelp: true,
|
HideHelp: true,
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
|
|
|
@ -241,10 +241,14 @@ environment variable or otherwise passing the "--env/-e" flag.
|
||||||
}
|
}
|
||||||
|
|
||||||
var serverNewCommand = &cli.Command{
|
var serverNewCommand = &cli.Command{
|
||||||
Name: "new",
|
Name: "new",
|
||||||
Usage: "Create a new server using a 3rd party provider",
|
Aliases: []string{"n"},
|
||||||
Description: "Use a provider plugin to create a new server which can then be used to house a new Co-op Cloud installation.",
|
Usage: "Create a new server using a 3rd party provider",
|
||||||
ArgsUsage: "<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{
|
Subcommands: []*cli.Command{
|
||||||
serverNewHetznerCloudCommand,
|
serverNewHetznerCloudCommand,
|
||||||
serverNewCapsulCommand,
|
serverNewCapsulCommand,
|
||||||
|
|
|
@ -1,8 +1,6 @@
|
||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
|
||||||
|
|
||||||
"coopcloud.tech/abra/cli/internal"
|
"coopcloud.tech/abra/cli/internal"
|
||||||
"coopcloud.tech/abra/pkg/client"
|
"coopcloud.tech/abra/pkg/client"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
@ -19,13 +17,14 @@ internal bookkeeping so that it is not managed any more.
|
||||||
`,
|
`,
|
||||||
HideHelp: true,
|
HideHelp: true,
|
||||||
Action: func(c *cli.Context) error {
|
Action: func(c *cli.Context) error {
|
||||||
server := c.Args().First()
|
domainName := internal.ValidateDomain(c)
|
||||||
if server == "" {
|
|
||||||
internal.ShowSubcommandHelpAndError(c, errors.New("no server provided"))
|
if err := client.DeleteContext(domainName); err != nil {
|
||||||
}
|
|
||||||
if err := client.DeleteContext(server); err != nil {
|
|
||||||
logrus.Fatal(err)
|
logrus.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
logrus.Infof("Server at '%s' has been forgotten", domainName)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue