adjust the configuration check sequence (#1467)

Signed-off-by: zc <zc2638@qq.com>
This commit is contained in:
zc 2022-07-21 10:42:03 +08:00 committed by Gaius
parent 96e62223b4
commit 1936acfd07
No known key found for this signature in database
GPG Key ID: 8B4E5D1290FA2FFB
5 changed files with 37 additions and 40 deletions

View File

@ -112,6 +112,15 @@ func initDfcacheDfpath(cfg *config.CacheOption) (dfpath.Dfpath, error) {
// runDfcache does some init operations and starts to download.
func runDfcacheSubcmd(cmdName string, args []string) error {
// Convert config
if err := dfcacheConfig.Convert(cmdName, args); err != nil {
return err
}
// Validate config
if err := dfcacheConfig.Validate(cmdName); err != nil {
return err
}
var (
daemonClient client.DaemonClient
err error
@ -129,16 +138,6 @@ func runDfcacheSubcmd(cmdName string, args []string) error {
}
logger.Infof("Version:\n%s", version.Version())
// Convert config
if err := dfcacheConfig.Convert(cmdName, args); err != nil {
return err
}
// Validate config
if err := dfcacheConfig.Validate(cmdName); err != nil {
return err
}
// Dfcache config values
s, _ := yaml.Marshal(dfcacheConfig)
logger.Infof("client dfcache configuration:\n%s", string(s))

View File

@ -55,6 +55,15 @@ it supports container engine, wget and other downloading tools through proxy fun
SilenceUsage: true,
FParseErrWhitelist: cobra.FParseErrWhitelist{UnknownFlags: true},
RunE: func(cmd *cobra.Command, args []string) error {
// Convert config
if err := cfg.Convert(); err != nil {
return err
}
// Validate config
if err := cfg.Validate(); err != nil {
return err
}
// Initialize daemon dfpath
d, err := initDaemonDfpath(cfg)
if err != nil {
@ -67,16 +76,6 @@ it supports container engine, wget and other downloading tools through proxy fun
}
logger.RedirectStdoutAndStderr(cfg.Console, path.Join(d.LogDir(), "daemon"))
// Convert config
if err := cfg.Convert(); err != nil {
return err
}
// Validate config
if err := cfg.Validate(); err != nil {
return err
}
return runDaemon(d)
},
}

View File

@ -69,6 +69,15 @@ var rootCmd = &cobra.Command{
RunE: func(cmd *cobra.Command, args []string) error {
start := time.Now()
// Convert config
if err := dfgetConfig.Convert(args); err != nil {
return err
}
// Validate config
if err := dfgetConfig.Validate(); err != nil {
return err
}
// Initialize daemon dfpath
d, err := initDfgetDfpath(dfgetConfig)
if err != nil {
@ -83,16 +92,6 @@ var rootCmd = &cobra.Command{
// update plugin directory
source.UpdatePluginDir(d.PluginDir())
// Convert config
if err := dfgetConfig.Convert(args); err != nil {
return err
}
// Validate config
if err := dfgetConfig.Validate(); err != nil {
return err
}
fmt.Printf("--%s-- %s\n", start.Format("2006-01-02 15:04:05"), dfgetConfig.URL)
fmt.Printf("dfget version: %s\n", version.GitVersion)
fmt.Printf("current user: %s, default peer ip: %s\n", basic.Username, ip.IPv4)

View File

@ -46,6 +46,11 @@ for managing schedulers and seed peers, offering http apis and portal, etc.`,
DisableAutoGenTag: true,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
// Validate config
if err := cfg.Validate(); err != nil {
return err
}
// Initialize dfpath
d, err := initDfpath(cfg.Server)
if err != nil {
@ -58,11 +63,6 @@ for managing schedulers and seed peers, offering http apis and portal, etc.`,
}
logger.RedirectStdoutAndStderr(cfg.Console, path.Join(d.LogDir(), "manager"))
// Validate config
if err := cfg.Validate(); err != nil {
return err
}
return runManager(d)
},
}

View File

@ -47,6 +47,11 @@ generate and maintain a P2P network during the download process, and push suitab
DisableAutoGenTag: true,
SilenceUsage: true,
RunE: func(cmd *cobra.Command, args []string) error {
// Validate config
if err := cfg.Validate(); err != nil {
return err
}
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
@ -62,11 +67,6 @@ generate and maintain a P2P network during the download process, and push suitab
}
logger.RedirectStdoutAndStderr(cfg.Console, path.Join(d.LogDir(), "scheduler"))
// Validate config
if err := cfg.Validate(); err != nil {
return err
}
return runScheduler(ctx, d)
},
}