feat: support local server with --local
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
parent
7c4cdc530c
commit
3688ea9d69
@ -1,16 +1,30 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"context"
|
"context"
|
||||||
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"coopcloud.tech/abra/cli/internal"
|
"coopcloud.tech/abra/cli/internal"
|
||||||
"coopcloud.tech/abra/pkg/client"
|
"coopcloud.tech/abra/pkg/client"
|
||||||
|
"coopcloud.tech/abra/pkg/config"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/urfave/cli/v2"
|
"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{
|
var serverAddCommand = &cli.Command{
|
||||||
Name: "add",
|
Name: "add",
|
||||||
Usage: "Add a new server",
|
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.
|
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"},
|
Aliases: []string{"a"},
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
localFlag,
|
||||||
|
},
|
||||||
ArgsUsage: "<domain> [<user>] [<port>]",
|
ArgsUsage: "<domain> [<user>] [<port>]",
|
||||||
Action: func(c *cli.Context) error {
|
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 username string
|
||||||
var port 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.Debugf("remote connection to '%s' is definitely up", domainName)
|
||||||
logrus.Infof("server at '%s' has been added", domainName)
|
logrus.Infof("server at '%s' has been added", domainName)
|
||||||
|
|
||||||
|
os.Mkdir(path.Join(config.ABRA_DIR, "servers", domainName), 0755)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user