Skip to content

Commit

Permalink
provide default config
Browse files Browse the repository at this point in the history
  • Loading branch information
storybehind committed Aug 20, 2024
1 parent 0a71b0d commit 5c4c4ef
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 72 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ jobs:
- name: Setup
run : |
mkdir -p ${{ env.OUTPUT_DIR }}
cp ${{ env.SRC_DIR }}/network/config.yaml ${{ env.OUTPUT_DIR }}
cp ${{ env.SRC_DIR }}/cmd/config.yaml ${{ env.OUTPUT_DIR }}
- name: Build Docker image for linux/amd64
run: |
Expand Down Expand Up @@ -170,8 +170,8 @@ jobs:
run : |
mkdir -p ${{ env.OUTPUT_DIR }}/amd64
mkdir -p ${{ env.OUTPUT_DIR }}/arm64
cp ${{ env.SRC_DIR }}/network/config.yaml ${{ env.OUTPUT_DIR }}/amd64/
cp ${{ env.SRC_DIR }}/network/config.yaml ${{ env.OUTPUT_DIR }}/arm64/
cp ${{ env.SRC_DIR }}/cmd/config.yaml ${{ env.OUTPUT_DIR }}/amd64/
cp ${{ env.SRC_DIR }}/cmd/config.yaml ${{ env.OUTPUT_DIR }}/arm64/
- name: Build Docker image
run: |
Expand Down
File renamed without changes.
21 changes: 20 additions & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
package cmd

import (
_ "embed"
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"

"github.com/0chain/gosdk/core/conf"
"github.com/0chain/gosdk/core/logger"

"github.com/spf13/cobra"
"github.com/spf13/viper"

"github.com/0chain/gosdk/zboxcore/blockchain"
"github.com/0chain/zboxcli/util"
Expand All @@ -34,6 +37,9 @@ var allocUnderRepair bool

var walletJSON string

//go:embed config.yaml
var configStr string

var rootCmd = &cobra.Command{
Use: "zbox",
Short: "zbox is a decentralized storage application written on the 0Chain platform",
Expand Down Expand Up @@ -77,7 +83,20 @@ func initConfig() {
cfg, err := conf.LoadConfigFile(filepath.Join(configDir, cfgFile))
if err != nil {
fmt.Println("Can't read config:", err)
os.Exit(1)
fmt.Println("WARNING: using default config...")
fmt.Printf("config: %v", configStr)
v := viper.New()
v.SetConfigType("yaml")
err := v.ReadConfig(strings.NewReader(configStr))
if err != nil {
fmt.Println("error reading default config:", err)
os.Exit(1)
}
cfg, err = conf.LoadConfig(v)
if err != nil {
fmt.Println("error loading default config:", err)
os.Exit(1)
}
}

if networkFile == "" {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ require (
github.com/olekukonko/tablewriter v0.0.5
github.com/spf13/cobra v1.6.0
github.com/spf13/pflag v1.0.5
github.com/spf13/viper v1.15.0
gopkg.in/cheggaaa/pb.v1 v1.0.28
)

Expand Down Expand Up @@ -57,7 +58,6 @@ require (
github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/viper v1.15.0 // indirect
github.com/subosito/gotenv v1.4.2 // indirect
github.com/tinylib/msgp v1.1.6 // indirect
github.com/tklauser/go-sysconf v0.3.11 // indirect
Expand Down
29 changes: 0 additions & 29 deletions scripts/darwin/build.sh

This file was deleted.

38 changes: 0 additions & 38 deletions scripts/darwin/build2.sh

This file was deleted.

0 comments on commit 5c4c4ef

Please sign in to comment.