feat: support local server with --local
continuous-integration/drone/push Build is failing Details

This commit is contained in:
3wc 2021-10-01 11:59:17 +02:00
parent 7c4cdc530c
commit 3688ea9d69
1 changed files with 39 additions and 1 deletions

View File

@ -1,16 +1,30 @@
package server
import (
"errors"
"context"
"os"
"os/user"
"path"
"strings"
"coopcloud.tech/abra/cli/internal"
"coopcloud.tech/abra/pkg/client"
"coopcloud.tech/abra/pkg/config"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
)
var local bool
var localFlag = &cli.BoolFlag{
Name: "local",
Aliases: []string{"L"},
Value: false,
Usage: "Set up the local server",
Destination: &local,
}
var serverAddCommand = &cli.Command{
Name: "add",
Usage: "Add a new server",
@ -32,11 +46,33 @@ Abra will construct the following SSH connection string then:
All communication between Abra and the server will use this SSH connection.
NOTE: If you specify --local, none of the above applies 🙃
`,
Aliases: []string{"a"},
Flags: []cli.Flag{
localFlag,
},
ArgsUsage: "<domain> [<user>] [<port>]",
Action: func(c *cli.Context) error {
domainName := internal.ValidateDomain(c)
if c.Args().Len() == 1 && !local {
err := errors.New("missing arguments <domain> or '--local'")
internal.ShowSubcommandHelpAndError(c, err)
}
if c.Args().Get(1) != "" && local {
err := errors.New("cannot use '<domain>' and '--local' together")
internal.ShowSubcommandHelpAndError(c, err)
}
domainName := "default"
if local {
os.Mkdir(path.Join(config.ABRA_DIR, "servers", domainName), 0755)
return nil
}
domainName = internal.ValidateDomain(c)
var username string
var port string
@ -91,6 +127,8 @@ All communication between Abra and the server will use this SSH connection.
logrus.Debugf("remote connection to '%s' is definitely up", domainName)
logrus.Infof("server at '%s' has been added", domainName)
os.Mkdir(path.Join(config.ABRA_DIR, "servers", domainName), 0755)
return nil
},
}