@@ -79,44 +79,25 @@ func NewDownloadCommand(commandValue string, commandArgs []string, cfg *config.C
79
79
}
80
80
81
81
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 )
107
84
if err != nil {
108
85
return errorMessages .ERR_NO_VALID_ID
109
86
} else {
110
87
defer resp .Body .Close ()
111
88
89
+ contentDisposition := resp .Header .Get ("content-disposition" )
90
+ var filename string
91
+ fmt .Sscanf (contentDisposition , "attachment; filename = %s" , & filename )
92
+
112
93
// check directory spelling
113
94
if ! strings .HasSuffix (this .OutputPath , "\\ " ) {
114
95
this .OutputPath = this .OutputPath + "\\ "
115
96
}
116
97
117
98
exists (this .OutputPath )
118
99
119
- file , err := os .Create (this .OutputPath + this . Name + "." + datatype )
100
+ file , err := os .Create (this .OutputPath + filename )
120
101
if err != nil {
121
102
return err
122
103
}
@@ -128,9 +109,7 @@ func (this *DownloadCommand) Execute() error {
128
109
return err
129
110
}
130
111
131
- println ()
132
- fmt .Printf ("Message: Download successful, %swith %v bytes" , this .OutputPath + this .Name + "." + datatype + " " , size )
133
- println ()
112
+ fmt .Printf ("\n Message: Download successful, %s with %v bytes\n " , this .OutputPath + filename , size )
134
113
}
135
114
136
115
return nil
0 commit comments