From 3688ea9d69de559de8f76c408207e7d419630c4c Mon Sep 17 00:00:00 2001 From: 3wc <3wc@doesthisthing.work> Date: Fri, 1 Oct 2021 11:59:17 +0200 Subject: [PATCH] feat: support local server with --local --- cli/server/add.go | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/cli/server/add.go b/cli/server/add.go index bdcc4b59c..6febae48e 100644 --- a/cli/server/add.go +++ b/cli/server/add.go @@ -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: " [] []", Action: func(c *cli.Context) error { - domainName := internal.ValidateDomain(c) + if c.Args().Len() == 1 && !local { + err := errors.New("missing arguments or '--local'") + internal.ShowSubcommandHelpAndError(c, err) + } + + if c.Args().Get(1) != "" && local { + err := errors.New("cannot use '' 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 }, }