refactor: NewClientWithContext -> New, and use server only

This commit is contained in:
2021-09-05 00:41:31 +02:00
parent dac679db48
commit 07a43cb314
14 changed files with 55 additions and 54 deletions

View File

@ -19,21 +19,21 @@ var serverInitCommand = &cli.Command{
Name: "init",
Usage: "Initialise server for deploying apps",
HideHelp: true,
ArgsUsage: "<host>",
ArgsUsage: "<server>",
Description: `
Initialise swarm mode on the target <host>.
Initialise swarm mode on the target <server>.
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.
`,
Action: func(c *cli.Context) error {
host := c.Args().First()
if host == "" {
internal.ShowSubcommandHelpAndError(c, errors.New("no host provided"))
server := c.Args().First()
if server == "" {
internal.ShowSubcommandHelpAndError(c, errors.New("no server provided"))
}
cl, err := client.NewClientWithContext(host)
cl, err := client.New(server)
if err != nil {
return err
}
@ -50,13 +50,13 @@ later for more advanced use cases.
}
ctx := context.Background()
ips, err := resolver.LookupIPAddr(ctx, host)
ips, err := resolver.LookupIPAddr(ctx, server)
if err != nil {
logrus.Fatal(err)
}
if len(ips) == 0 {
return fmt.Errorf("unable to retrieve ipv4 address for %s", host)
return fmt.Errorf("unable to retrieve ipv4 address for %s", server)
}
ipv4 := ips[0].IP.To4().String()