diff --git a/Dockerfile b/Dockerfile index 11ffd40..1a62bae 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM golang:1 as builder +FROM golang:1 AS builder COPY . /app WORKDIR /app diff --git a/cmd/certs/generate.go b/cmd/certs/generate.go index b6060a1..031a55e 100644 --- a/cmd/certs/generate.go +++ b/cmd/certs/generate.go @@ -9,8 +9,8 @@ import ( // generateCmd represents the generate command var generateCmd = &cobra.Command{ - Use: "generate", - Short: "Generates a full set of certificates for chia-blockchain", + Use: "generate", + Short: "Generates a full set of certificates for chia-blockchain", Example: "chia-tools certs generate --output ~/.chia/mainnet/config/ssl", Run: func(cmd *cobra.Command, args []string) { err := tls.GenerateAllCerts(viper.GetString("cert-output")) diff --git a/cmd/config/edit.go b/cmd/config/edit.go new file mode 100644 index 0000000..382c4fe --- /dev/null +++ b/cmd/config/edit.go @@ -0,0 +1,82 @@ +package config + +import ( + "os" + "path" + + "github.com/chia-network/go-chia-libs/pkg/config" + "github.com/chia-network/go-modules/pkg/slogs" + "github.com/spf13/cobra" + "github.com/spf13/viper" + "gopkg.in/yaml.v3" +) + +// editCmd generates a new chia config +var editCmd = &cobra.Command{ + Use: "edit", + Short: "Edit an existing chia configuration file", + Example: `chia-tools config edit ~/.chia/mainnet/config/config.yaml --set full_node.port=58444 --set full_node.target_peer_count=10 + +# The following version will discover the config file by inspecting CHIA_ROOT or using the default CHIA_ROOT +chia-tools config edit --set full_node.port=58444 --set full_node.target_peer_count=10`, + Run: func(cmd *cobra.Command, args []string) { + var cfgPath string + + chiaRoot, err := config.GetChiaRootPath() + if err != nil { + slogs.Logr.Fatal("Unable to determine CHIA_ROOT", "error", err) + } + + if len(args) > 1 { + slogs.Logr.Fatal("Unexpected number of arguments provided") + } else if len(args) == 1 { + // Use the provided config path + cfgPath = args[0] + } else { + // Use default chia root + cfgPath = path.Join(chiaRoot, "config", "config.yaml") + } + + cfg, err := config.LoadConfigAtRoot(cfgPath, chiaRoot) + if err != nil { + slogs.Logr.Fatal("error loading chia config", "error", err) + } + + err = cfg.FillValuesFromEnvironment() + if err != nil { + slogs.Logr.Fatal("error filling values from environment", "error", err) + } + + valuesToSet := viper.GetStringMapString("edit-set") + for path, value := range valuesToSet { + pathMap := config.ParsePathsFromStrings([]string{path}, false) + var key string + var pathSlice []string + for key, pathSlice = range pathMap { + break + } + err = cfg.SetFieldByPath(pathSlice, value) + if err != nil { + slogs.Logr.Fatal("error setting path in config", "key", key, "value", value, "error", err) + } + } + + out, err := yaml.Marshal(cfg) + if err != nil { + slogs.Logr.Fatal("error marshalling config", "error", err) + } + + err = os.WriteFile(cfgPath, out, 0655) + if err != nil { + slogs.Logr.Fatal("error writing output file", "error", err) + } + }, +} + +func init() { + editCmd.PersistentFlags().StringToStringP("set", "s", nil, "Paths and values to set in the config") + + cobra.CheckErr(viper.BindPFlag("edit-set", editCmd.PersistentFlags().Lookup("set"))) + + configCmd.AddCommand(editCmd) +} diff --git a/cmd/datalayer/deletemirrors.go b/cmd/datalayer/deletemirrors.go index 5573c7c..4eced40 100644 --- a/cmd/datalayer/deletemirrors.go +++ b/cmd/datalayer/deletemirrors.go @@ -12,8 +12,8 @@ import ( // deleteMirrorsCmd Deletes all owned mirrors for all datalayer subscriptions var deleteMirrorsCmd = &cobra.Command{ - Use: "delete-mirrors", - Short: "Deletes all owned mirrors for all datalayer subscriptions", + Use: "delete-mirrors", + Short: "Deletes all owned mirrors for all datalayer subscriptions", Example: "chia-tools data delete-mirrors --all\nchia-tools data delete-mirrors --id abcd1234", PreRunE: func(cmd *cobra.Command, args []string) error { all := viper.GetBool("delete-mirror-all") diff --git a/go.mod b/go.mod index 38b5d25..c1001aa 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/chia-network/chia-tools go 1.22.4 require ( - github.com/chia-network/go-chia-libs v0.9.1 + github.com/chia-network/go-chia-libs v0.9.2 github.com/chia-network/go-modules v0.0.5 github.com/spf13/cobra v1.8.1 github.com/spf13/viper v1.19.0 diff --git a/go.sum b/go.sum index 45237b3..121fe4b 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/chia-network/go-chia-libs v0.9.1 h1:RAoCnnAl0hccUw6ue/9OsoYxFLlUiXpNy5OPDUDqUQQ= -github.com/chia-network/go-chia-libs v0.9.1/go.mod h1:npTqaFSjTdMxE7hc0LOmWJmWGqcs+IERarK5fDxXk/I= +github.com/chia-network/go-chia-libs v0.9.2 h1:WWfiKoCA9zpoq4JgbX/l9cCcdJ4wQeWdc1iG29Fa8/E= +github.com/chia-network/go-chia-libs v0.9.2/go.mod h1:npTqaFSjTdMxE7hc0LOmWJmWGqcs+IERarK5fDxXk/I= github.com/chia-network/go-modules v0.0.5 h1:5luTVlP6RgBXodnFcWFBk2sLdJn+6vQ4wObim683C7c= github.com/chia-network/go-modules v0.0.5/go.mod h1:5AiYBxQSvf2aFSOizTqFXXSeb9AucZWrWmRCVwUMO3A= github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=