Skip to content

Commit 90074c8

Browse files
authored
Merge pull request #343 from bsinno/bug/#51_vorto_cli_cannot_download
Fixes #51 - vorto command line tool: No datatype could be defined as …
2 parents d3f4611 + f437b37 commit 90074c8

File tree

1 file changed

+8
-29
lines changed

1 file changed

+8
-29
lines changed

cli/command/download.go

+8-29
Original file line numberDiff line numberDiff line change
@@ -79,44 +79,25 @@ func NewDownloadCommand(commandValue string, commandArgs []string, cfg *config.C
7979
}
8080

8181
func (this *DownloadCommand) Execute() error {
82-
83-
var resolveAs string
84-
var datatype string
85-
86-
if this.IncludeDependencies == true {
87-
// if flag for -includeDependencies=true resolve all dependencies and download them
88-
resolveAs = "zip"
89-
datatype = "zip"
90-
} else {
91-
// if flag for -includeDependencies=false don't resolve all dependencies and don't download them
92-
resolveAs = "file"
93-
94-
switch {
95-
case strings.Contains(this.Namespace, "functionblockmodels"):
96-
datatype = "fbmodel"
97-
case strings.Contains(this.Namespace, "informationmodels"):
98-
datatype = "infomodel"
99-
case strings.Contains(this.Namespace, "type"):
100-
datatype = "type"
101-
default:
102-
return errorMessages.ERR_NO_DATATYPE
103-
}
104-
}
105-
106-
resp, err := this.Client.MyClient.Get(this.Repository + "/rest/model/file/" + this.Namespace + "/" + this.Name + "/" + this.Version + "?output=" + this.Output +"&includeDependencies="+this.IncludeDependencies)
82+
urlStr := fmt.Sprintf("%v/rest/model/file/%v/%v/%v?output=%v&includeDependencies=%v", this.Repository, this.Namespace, this.Name, this.Version, this.Output, this.IncludeDependencies);
83+
resp, err := this.Client.MyClient.Get(urlStr)
10784
if err != nil {
10885
return errorMessages.ERR_NO_VALID_ID
10986
} else {
11087
defer resp.Body.Close()
11188

89+
contentDisposition := resp.Header.Get("content-disposition")
90+
var filename string
91+
fmt.Sscanf(contentDisposition, "attachment; filename = %s", &filename)
92+
11293
// check directory spelling
11394
if !strings.HasSuffix(this.OutputPath, "\\") {
11495
this.OutputPath = this.OutputPath + "\\"
11596
}
11697

11798
exists(this.OutputPath)
11899

119-
file, err := os.Create(this.OutputPath + this.Name + "." + datatype)
100+
file, err := os.Create(this.OutputPath + filename)
120101
if err != nil {
121102
return err
122103
}
@@ -128,9 +109,7 @@ func (this *DownloadCommand) Execute() error {
128109
return err
129110
}
130111

131-
println()
132-
fmt.Printf("Message: Download successful, %swith %v bytes", this.OutputPath+this.Name+"."+datatype+" ", size)
133-
println()
112+
fmt.Printf("\nMessage: Download successful, %s with %v bytes\n", this.OutputPath + filename, size)
134113
}
135114

136115
return nil

0 commit comments

Comments
 (0)