Archived
1
This repository has been archived on 2025-08-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
playbookctl/cmd/space.go
2024-12-23 01:55:48 +03:00

71 lines
1.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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,
})
}