Reimplement

This commit is contained in:
d1slike committed 2023-06-09 17:25:12 +03:00
1 parent d4d7c679aa
commit df259e3f78
36 files changed
+559 -1135

No files matched your search

+2 -1
View File
@@ -2,8 +2,9 @@ package command
import (
"fmt"
"github.com/urfave/cli/v2"
"isp-ctl/command/common_config"
"ispctl/command/common_config"
)
func CommonConfig() *cli.Command {
+4 -3
View File
@@ -2,11 +2,12 @@ package common_config
import (
"fmt"
"github.com/pkg/errors"
"github.com/urfave/cli/v2"
"isp-ctl/bash"
"isp-ctl/flag"
"isp-ctl/service"
"ispctl/bash"
"ispctl/flag"
"ispctl/service"
)
func Contain() *cli.Command {
+5 -4
View File
@@ -2,13 +2,14 @@ package common_config
import (
"encoding/json"
"github.com/pkg/errors"
"github.com/tidwall/sjson"
"github.com/urfave/cli/v2"
"isp-ctl/bash"
"isp-ctl/command/utils"
"isp-ctl/flag"
"isp-ctl/service"
"ispctl/bash"
"ispctl/command/utils"
"ispctl/flag"
"ispctl/service"
)
func Delete() *cli.Command {
+5 -4
View File
@@ -3,12 +3,13 @@ package common_config
import (
"encoding/json"
"fmt"
"github.com/pkg/errors"
"github.com/urfave/cli/v2"
"isp-ctl/bash"
"isp-ctl/command/utils"
"isp-ctl/flag"
"isp-ctl/service"
"ispctl/bash"
"ispctl/command/utils"
"ispctl/flag"
"ispctl/service"
)
func Get() *cli.Command {
+3 -3
View File
@@ -2,9 +2,9 @@ package common_config
import (
"github.com/urfave/cli/v2"
"isp-ctl/bash"
"isp-ctl/flag"
"isp-ctl/service"
"ispctl/bash"
"ispctl/flag"
"ispctl/service"
)
func Link() *cli.Command {
+4 -3
View File
@@ -2,11 +2,12 @@ package common_config
import (
"fmt"
"github.com/pkg/errors"
"github.com/urfave/cli/v2"
"isp-ctl/bash"
"isp-ctl/flag"
"isp-ctl/service"
"ispctl/bash"
"ispctl/flag"
"ispctl/service"
)
func Remove() *cli.Command {
+6 -5
View File
@@ -2,14 +2,15 @@ package common_config
import (
"encoding/json"
"github.com/pkg/errors"
"github.com/tidwall/sjson"
"github.com/urfave/cli/v2"
"isp-ctl/bash"
"isp-ctl/cfg"
"isp-ctl/command/utils"
"isp-ctl/flag"
"isp-ctl/service"
"ispctl/bash"
"ispctl/cfg"
"ispctl/command/utils"
"ispctl/flag"
"ispctl/service"
)
func Set() *cli.Command {
+3 -3
View File
@@ -2,9 +2,9 @@ package common_config
import (
"github.com/urfave/cli/v2"
"isp-ctl/bash"
"isp-ctl/flag"
"isp-ctl/service"
"ispctl/bash"
"ispctl/flag"
"ispctl/service"
)
func UnLink() *cli.Command {
+5 -4
View File
@@ -2,12 +2,13 @@ package command
import (
"encoding/json"
"github.com/tidwall/sjson"
"github.com/urfave/cli/v2"
"isp-ctl/bash"
"isp-ctl/command/utils"
"isp-ctl/flag"
"isp-ctl/service"
"ispctl/bash"
"ispctl/command/utils"
"ispctl/flag"
"ispctl/service"
)
func Delete() *cli.Command {
+5 -4
View File
@@ -2,11 +2,12 @@ package command
import (
"encoding/json"
"github.com/urfave/cli/v2"
"isp-ctl/bash"
"isp-ctl/command/utils"
"isp-ctl/flag"
"isp-ctl/service"
"ispctl/bash"
"ispctl/command/utils"
"ispctl/flag"
"ispctl/service"
)
func Get() *cli.Command {
+60
View File
@@ -0,0 +1,60 @@
package command
import (
"io"
"os"
"github.com/go-git/go-billy/v5/memfs"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/storage/memory"
"github.com/pkg/errors"
"github.com/urfave/cli/v2"
)
func GitGet() *cli.Command {
return &cli.Command{
Name: "gitget",
Usage: "gitget [repository] [file] (commit)",
Description: "clone and print specified file from specified repository and specified commit hash",
Action: func(context *cli.Context) error {
storage := memory.NewStorage()
repo := context.Args().Get(0)
file := context.Args().Get(1)
commit := context.Args().Get(2)
repository, err := git.Clone(storage, memfs.New(), &git.CloneOptions{
URL: repo,
})
if err != nil {
return errors.WithMessagef(err, "clone %s", repo)
}
tree, err := repository.Worktree()
if err != nil {
return errors.WithMessage(err, "get worktree")
}
if commit != "" {
err = tree.Checkout(&git.CheckoutOptions{
Hash: plumbing.NewHash(commit),
})
if err != nil {
return errors.WithMessagef(err, "checkout: %s", commit)
}
}
f, err := tree.Filesystem.Open(file)
if err != nil {
return errors.WithMessagef(err, "open %s", file)
}
_, err = io.Copy(os.Stdout, f)
if err != nil {
return err
}
return nil
},
}
}
+49
View File
@@ -0,0 +1,49 @@
package command
import (
"encoding/json"
"os"
"github.com/pkg/errors"
"github.com/urfave/cli/v2"
"ispctl/bash"
"ispctl/command/utils"
"ispctl/flag"
"ispctl/service"
)
func Merge() *cli.Command {
return &cli.Command{
Name: "merge",
Usage: "merge actual config with config from stdin",
BashComplete: bash.Get(bash.CommonConfigName, bash.Empty).Complete,
Action: func(context *cli.Context) error {
err := flag.CheckGlobal(context)
if err != nil {
return err
}
moduleName := context.Args().First()
config, err := service.Config.GetConfigurationByModuleName(moduleName)
if err != nil {
return errors.WithMessagef(err, "get module config '%s'", moduleName)
}
inputConfig := make(map[string]any)
err = json.NewDecoder(os.Stdin).Decode(&inputConfig)
if err != nil {
return errors.WithMessage(err, "json unmarshal input config")
}
for key, value := range inputConfig {
config.Data[key] = value
}
result, err := service.Config.CreateUpdateConfigV2(config)
if err != nil {
return errors.WithMessagef(err, "update module config '%s'", moduleName)
}
utils.PrintAnswer(result)
return nil
},
}
}
+8 -7
View File
@@ -1,15 +1,16 @@
package command
import (
"html/template"
"os"
"github.com/pkg/errors"
"github.com/urfave/cli/v2"
"html/template"
"isp-ctl/bash"
"isp-ctl/command/utils"
"isp-ctl/flag"
"isp-ctl/service"
"isp-ctl/tmpl"
"os"
"ispctl/bash"
"ispctl/command/utils"
"ispctl/flag"
"ispctl/service"
"ispctl/tmpl"
)
func Schema() *cli.Command {
+5 -4
View File
@@ -2,12 +2,13 @@ package command
import (
"encoding/json"
"github.com/tidwall/sjson"
"github.com/urfave/cli/v2"
"isp-ctl/bash"
"isp-ctl/command/utils"
"isp-ctl/flag"
"isp-ctl/service"
"ispctl/bash"
"ispctl/command/utils"
"ispctl/flag"
"ispctl/service"
)
func Set() *cli.Command {
+7 -6
View File
@@ -2,13 +2,14 @@ package command
import (
"fmt"
"github.com/olekukonko/tablewriter"
"github.com/urfave/cli/v2"
"isp-ctl/command/utils"
"isp-ctl/flag"
"isp-ctl/service"
"os"
"strings"
"github.com/olekukonko/tablewriter"
"github.com/urfave/cli/v2"
"ispctl/command/utils"
"ispctl/flag"
"ispctl/service"
)
const (
@@ -54,7 +55,7 @@ func (statusCommand) action(ctx *cli.Context) error {
connection := tableNotConnectedStatus
instanceList := make([]string, 0, len(module.Status))
for _, value := range module.Status {
instanceList = append(instanceList, fmt.Sprintf("%s %s", value.Address.GetAddress(), value.Version))
instanceList = append(instanceList, fmt.Sprintf("%s:%s %s", value.Address.IP, value.Address.Port, value.Version))
}
addresses = strings.Join(instanceList, "\n")
if addresses != "" {
+5 -9
View File
@@ -1,15 +1,14 @@
package utils
import (
"bytes"
"encoding/json"
"fmt"
"github.com/pkg/errors"
"github.com/tidwall/gjson"
"io/ioutil"
"isp-ctl/service"
"os"
"strings"
"github.com/integration-system/isp-kit/json"
"github.com/pkg/errors"
"github.com/tidwall/gjson"
)
func CheckPath(pathObject string) (string, error) {
@@ -47,14 +46,11 @@ func CheckChangeObject(changeObject string) (string, error) {
}
func PrintAnswer(data interface{}) {
buffer := bytes.NewBuffer(make([]byte, 0, 1024))
encoder := json.NewEncoder(buffer)
encoder := json.NewEncoder(os.Stdout)
encoder.SetEscapeHTML(false)
encoder.SetIndent("", " ")
if err := encoder.Encode(data); err != nil {
PrintError(err)
} else {
service.ColorService.Print(buffer.Bytes())
}
}
+2 -2
View File
@@ -1,8 +1,8 @@
package utils
import (
"isp-ctl/cfg"
"isp-ctl/service"
"ispctl/cfg"
"ispctl/service"
)
func CreateUpdateCommonConfig(stringToChange string, configuration cfg.CommonConfig) error {
+2 -2
View File
@@ -1,8 +1,8 @@
package utils
import (
"isp-ctl/cfg"
"isp-ctl/service"
"ispctl/cfg"
"ispctl/service"
)
func CreateUpdateConfig(stringToChange string, configuration *cfg.Config) error {