MSP-5014 Try get rid of global service and autocomplete

This commit is contained in:
Синельник Тимур Романович committed 2025-03-24 11:30:39 +03:00
1 parent 84f639a9d3
commit c267b1ae6e
15 files changed
+468 -335

No files matched your search

+24 -17
View File
@@ -4,35 +4,42 @@ import (
"encoding/json"
"ispctl/bash"
"ispctl/command/flag"
"ispctl/command/utils"
"ispctl/service"
"ispctl/model"
"github.com/urfave/cli/v2"
)
func Get() *cli.Command {
return &cli.Command{
Name: "get",
Usage: "get configuration by module_name",
Before: flag.ApplyGlobalFlags,
Action: get.action,
BashComplete: bash.Get(bash.ModuleName, bash.ModuleData).Complete,
type GetService interface {
GetConfigurationByModuleName(moduleName string) (*model.Config, error)
}
type Get struct {
service SetService
autoComplete AutoComplete
}
func NewGet(service SetService, autoComplete AutoComplete) Get {
return Get{
service: service,
autoComplete: autoComplete,
}
}
var get getCommand
type getCommand struct{}
func (g getCommand) action(ctx *cli.Context) error {
if err := flag.ApplyGlobalFlags(ctx); err != nil {
return err
func (c Get) Command() *cli.Command {
return &cli.Command{
Name: "get",
Usage: "get configuration by module_name",
Action: c.action,
BashComplete: c.autoComplete.Complete(bash.ModuleName, bash.ModuleData),
}
}
func (c Get) action(ctx *cli.Context) error {
moduleName := ctx.Args().First()
pathObject := ctx.Args().Get(1)
config, err := service.Config.GetConfigurationByModuleName(moduleName)
config, err := c.service.GetConfigurationByModuleName(moduleName)
if err != nil {
return err
}