first commit
This commit is contained in:
70
cmd/space.go
Normal file
70
cmd/space.go
Normal file
@@ -0,0 +1,70 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
_ "embed"
|
||||
"errors"
|
||||
"github.com/spf13/cobra"
|
||||
"path/filepath"
|
||||
sc "playbookctl/internal/space_creator"
|
||||
"playbookctl/internal/utils/logger"
|
||||
)
|
||||
|
||||
var (
|
||||
flagName string
|
||||
flagHost string
|
||||
flagPort uint16
|
||||
flagUser string
|
||||
)
|
||||
|
||||
func NewCommandSpace() *cobra.Command {
|
||||
spaceCmd := &cobra.Command{
|
||||
Use: "space",
|
||||
Short: "работа с пространствами",
|
||||
RunE: func(cmd *cobra.Command, _ []string) error {
|
||||
return cmd.Help()
|
||||
},
|
||||
}
|
||||
|
||||
spaceCmd.AddCommand(newCommandSpaceCreate())
|
||||
|
||||
return spaceCmd
|
||||
}
|
||||
|
||||
func newCommandSpaceCreate() *cobra.Command {
|
||||
createCmd := &cobra.Command{
|
||||
Use: "create <name>",
|
||||
Aliases: []string{"new"},
|
||||
Short: "создать пространство",
|
||||
Args: spaceCreateCheckArgsE,
|
||||
RunE: spaceCreateRunE,
|
||||
}
|
||||
|
||||
createCmd.Flags().StringVar(&flagName, "name", "default", "псевдоним сервера")
|
||||
createCmd.Flags().StringVar(&flagHost, "host", "127.0.0.1", "SSH адрес")
|
||||
createCmd.Flags().Uint16Var(&flagPort, "port", 22, "SSH порт")
|
||||
createCmd.Flags().StringVar(&flagUser, "user", "root", "SSH пользователь")
|
||||
|
||||
return createCmd
|
||||
}
|
||||
|
||||
func spaceCreateCheckArgsE(_ *cobra.Command, args []string) error {
|
||||
if len(args) != 1 {
|
||||
return errors.New("должен быть указан один аргумент")
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func spaceCreateRunE(_ *cobra.Command, args []string) error {
|
||||
workDir, err := filepath.Abs(flagWorkdir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
spaceCreator := sc.NewSpaceCreator(logger.LogVerbose(flagVerbose), workDir)
|
||||
return spaceCreator.CreateSpace(args[0], &sc.ServerProps{
|
||||
Name: flagName,
|
||||
Host: flagHost,
|
||||
Port: flagPort,
|
||||
User: flagUser,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user