Files
ispctl/command/commands.go
T

65 lines
1.9 KiB
Go

package command
import (
"ispctl/command/utils"
"ispctl/model"
"github.com/txix-open/isp-kit/rc/schema"
"github.com/urfave/cli/v2"
)
type AutoComplete interface {
Complete(first string, second string) cli.BashCompleteFunc
}
type ConfigService interface {
Audit() ([]model.AuditViolation, error)
CreateUpdateConfig(stringToChange string, configuration *model.Config) (map[string]any, error)
CreateUpdateConfigV2(configuration *model.Config) (map[string]any, error)
DeleteVariable(variableName string) error
GetAllVariables() ([]model.Variable, error)
GetAvailableConfigs() ([]model.ModuleInfo, error)
GetConfigurationByModuleName(moduleName string) (*model.Config, error)
GetSchemaByModuleId(moduleId string) (schema.Schema, error)
GetVariableByName(variableName string) (*model.Variable, error)
UpsertVariables(vars []model.UpsertVariableRequest) error
}
type UpdateConfigService interface {
CreateUpdateConfig(stringToChange string, configuration *model.Config) (map[string]any, error)
}
func AllCommands(configService ConfigService, autoComplete AutoComplete) []*cli.Command {
status := NewStatus(configService)
get := NewGet(configService, autoComplete)
set := NewSet(configService, autoComplete)
delete := NewDelete(configService, autoComplete)
schema := NewSchema(configService, autoComplete)
merge := NewMerge(configService, autoComplete)
gitGet := NewGitGet()
variables := NewVariables(configService, autoComplete)
audit := NewAudit(configService)
return []*cli.Command{
status.Command(),
get.Command(),
set.Command(),
delete.Command(),
schema.Command(),
merge.Command(),
gitGet.Command(),
variables.Command(),
audit.Command(),
}
}
func CreateUpdateConfig(stringToChange string, configuration *model.Config, service UpdateConfigService) error {
answer, err := service.CreateUpdateConfig(stringToChange, configuration)
if err != nil {
return err
}
if answer != nil {
return utils.PrintAnswer(answer)
}
return nil
}