Skip to content

Commit

Permalink
chore: cmd tidy up (#159)
Browse files Browse the repository at this point in the history
  • Loading branch information
joeylichang committed Mar 4, 2023
1 parent 6e5fcd8 commit e156476
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 60 deletions.
52 changes: 52 additions & 0 deletions cmd/conf/conf.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package conf

import (
"gopkg.in/urfave/cli.v1"

"github.com/bnb-chain/greenfield-storage-provider/cmd/utils"
"github.com/bnb-chain/greenfield-storage-provider/config"
)

var ConfigDumpCmd = cli.Command{
Action: dumpConfigAction,
Name: "config.dump",
Usage: "Dump default configuration to file for editing",
Category: "CONFIG COMMANDS",
Description: `
The config.dump command writes default configuration
values to ./config.toml file for editing.`,
}

// dumpConfigAction is the dump.config command.
func dumpConfigAction(ctx *cli.Context) error {
return config.SaveConfig("./config.toml", config.DefaultStorageProviderConfig)
}

var ConfigUploadCmd = cli.Command{
Action: configUploadAction,
Name: "config.upload",
Usage: "Upload the config file to db",
Flags: []cli.Flag{
utils.ConfigFileFlag,
utils.DBUserFlag,
utils.DBPasswordFlag,
},
Category: "CONFIG COMMANDS",
Description: `
The config.upload command upload the file to db for sp to load`,
}

// configUploadAction is the config.upload command.
func configUploadAction(ctx *cli.Context) error {
//var configFile string
//if ctx.GlobalIsSet(utils.ConfigFileFlag.Name) {
// configFile = ctx.GlobalString(utils.ConfigFileFlag.Name)
//} else {
// configFile = "./config.toml"
//}
//cfg := config.LoadConfig(configFile)

// TODO:: new sp db, and upload
// replace by env vars
return nil
}
44 changes: 0 additions & 44 deletions cmd/conf/dump_config.go

This file was deleted.

26 changes: 10 additions & 16 deletions cmd/storage_provider/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (
"os"
"syscall"

"github.com/bnb-chain/greenfield-storage-provider/cmd/conf"
"gopkg.in/urfave/cli.v1"

"github.com/bnb-chain/greenfield-storage-provider/cmd/conf"
"github.com/bnb-chain/greenfield-storage-provider/cmd/utils"
"github.com/bnb-chain/greenfield-storage-provider/config"
"github.com/bnb-chain/greenfield-storage-provider/pkg/lifecycle"
"github.com/bnb-chain/greenfield-storage-provider/pkg/log"
Expand All @@ -22,19 +23,12 @@ var (
var app *cli.App

var (
configFlag = cli.StringFlag{
Name: "config",
Usage: "File path for storage provider configuration",
}
versionFlag = cli.BoolFlag{
Name: "version",
Usage: "Show the storage provider version information",
}

// flags that configure the storage provider
spFlags = []cli.Flag{
configFlag,
versionFlag,
utils.VersionFlag,
utils.ConfigFileFlag,
utils.DBUserFlag,
utils.DBUserFlag,
}
)

Expand All @@ -48,7 +42,7 @@ func init() {
app.Commands = []cli.Command{
// config category commands
conf.ConfigDumpCmd,
conf.ListEnvCmd,
conf.ConfigUploadCmd,
}
}

Expand All @@ -60,15 +54,15 @@ func main() {
}

func storageProvider(ctx *cli.Context) error {
if ctx.GlobalIsSet(versionFlag.Name) {
if ctx.GlobalIsSet(utils.VersionFlag.Name) {
fmt.Print(DumpLogo() + DumpVersion())
return nil
}
if !ctx.GlobalIsSet(configFlag.Name) {
if !ctx.GlobalIsSet(utils.ConfigFileFlag.Name) {
return fmt.Errorf("invalid params")
}

cfg := config.LoadConfig(configFlag.Value)
cfg := config.LoadConfig(ctx.GlobalString(utils.ConfigFileFlag.Name))
slc := lifecycle.NewServiceLifecycle()
for _, serviceName := range cfg.Service {
// 1. init service instance.
Expand Down
29 changes: 29 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package utils

import (
"gopkg.in/urfave/cli.v1"

"github.com/bnb-chain/greenfield-storage-provider/model"
)

var (
VersionFlag = cli.BoolFlag{
Name: "version",
Usage: "Show the storage provider version information",
}
ConfigFileFlag = cli.StringFlag{
Name: "config",
Usage: "Config file path for uploading to db",
Value: "./config.toml",
}
DBUserFlag = cli.StringFlag{
Name: "user",
Usage: "DB user name",
EnvVar: model.SpDBUser,
}
DBPasswordFlag = cli.StringFlag{
Name: "password",
Usage: "DB password",
EnvVar: model.SpDBPasswd,
}
)
7 changes: 7 additions & 0 deletions cmd/utils/flags_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package utils

import "testing"

func Test_EnvFlag(t *testing.T) {

}

0 comments on commit e156476

Please sign in to comment.