Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CLI command to save default config in a file #976

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions app/client/cli/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package cli

import (
"github.com/pokt-network/pocket/runtime/configs"
"github.com/spf13/cobra"
)

func init() {
rootCmd.AddCommand(saveDefaultConf)
}

var saveDefaultConf = &cobra.Command{
Use: "save_default_config",
Short: "Save the default config in a file",
Long: "The default config generated during application start is saved in a config file path passed in the argument",
Run: func(cmd *cobra.Command, args []string) {
configs.SaveConfig(args[0])
},
}
4 changes: 4 additions & 0 deletions app/client/doc/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [0.0.0.37] - 2023-08-19

- Add cli to generate the default config and save it to a file.

## [0.0.0.36] - 2023-06-19

- Add a new trustless relay sub-command to servicer command
Expand Down
17 changes: 17 additions & 0 deletions runtime/configs/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package configs

import (
"encoding/json"
"fmt"
"log"
"os"
"path/filepath"
"strings"

"github.com/mitchellh/mapstructure"
Expand Down Expand Up @@ -243,3 +245,18 @@ func defaultServicerConfig() *ServicerConfig {
},
}
}

func SaveConfig(path string) {
filePath, err := filepath.Abs(path)
if err != nil {
log.Fatalf("[ERROR] failed to resolve config path, %s", err.Error())
}

NewDefaultConfig()
err = viper.WriteConfigAs(filePath)
if err != nil {
log.Fatalf("[ERROR] failed to write config to file, error: %s", err.Error())
}

fmt.Printf("save_default_config: saved default config at %v", filePath)
}