diff --git a/client/config/dfget.go b/client/config/dfget.go index 4f47d8483..3031d6c5b 100644 --- a/client/config/dfget.go +++ b/client/config/dfget.go @@ -163,12 +163,22 @@ func (cfg *ClientOption) Validate() error { } func (cfg *ClientOption) Convert(args []string) error { - var err error - - if cfg.Output, err = filepath.Abs(cfg.Output); err != nil { - return err + if stringutils.IsBlank(cfg.Output) { + url := strings.TrimRight(cfg.URL, "/") + idx := strings.LastIndexByte(url, '/') + if idx < 0 { + return fmt.Errorf("get output from url[%s] error", cfg.URL) + } + cfg.Output = url[idx+1:] } + if !filepath.IsAbs(cfg.Output) { + absPath, err := filepath.Abs(cfg.Output) + if err != nil { + return fmt.Errorf("get absolute path[%s] error: %v", cfg.Output, err) + } + cfg.Output = absPath + } if cfg.URL == "" && len(args) > 0 { cfg.URL = args[0] } @@ -180,7 +190,6 @@ func (cfg *ClientOption) Convert(args []string) error { if cfg.Console { cfg.ShowProgress = false } - return nil } @@ -191,23 +200,9 @@ func (cfg *ClientOption) String() string { // This function must be called after checkURL func (cfg *ClientOption) checkOutput() error { - if stringutils.IsBlank(cfg.Output) { - url := strings.TrimRight(cfg.URL, "/") - idx := strings.LastIndexByte(url, '/') - if idx < 0 { - return fmt.Errorf("get output from url[%s] error", cfg.URL) - } - cfg.Output = url[idx+1:] - } - if !filepath.IsAbs(cfg.Output) { - absPath, err := filepath.Abs(cfg.Output) - if err != nil { - return fmt.Errorf("get absolute path[%s] error: %v", cfg.Output, err) - } - cfg.Output = absPath + return fmt.Errorf("path[%s] is not absolute path", cfg.Output) } - outputDir, _ := path.Split(cfg.Output) if err := MkdirAll(outputDir, 0777, basic.UserID, basic.UserGroup); err != nil { return err