9
9
"path"
10
10
"path/filepath"
11
11
"reflect"
12
+ "sort"
12
13
"strings"
13
14
14
15
osh "github.com/Kubuxu/go-os-helper"
@@ -236,7 +237,8 @@ func parseArgs(req *cmds.Request, root *cmds.Command, stdin *os.File) error {
236
237
}
237
238
238
239
stringArgs := make ([]string , 0 , numInputs )
239
- fileArgs := make (map [string ]files.Node )
240
+ fileArgs := make ([]files.DirEntry , 0 )
241
+ var fileStdin files.Node
240
242
241
243
// the index of the current argument definition
242
244
iArgDef := 0
@@ -266,7 +268,7 @@ func parseArgs(req *cmds.Request, root *cmds.Command, stdin *os.File) error {
266
268
stringArgs , inputs = append (stringArgs , inputs [0 ]), inputs [1 :]
267
269
} else if stdin != nil && argDef .SupportsStdin && ! fillingVariadic {
268
270
if r , err := maybeWrapStdin (stdin , msgStdinInfo ); err == nil {
269
- fileArgs [ "stdin" ] , err = files .NewReaderPathFile (stdin .Name (), r , nil )
271
+ fileStdin , err = files .NewReaderPathFile (stdin .Name (), r , nil )
270
272
if err != nil {
271
273
return err
272
274
}
@@ -291,17 +293,7 @@ func parseArgs(req *cmds.Request, root *cmds.Command, stdin *os.File) error {
291
293
return err
292
294
}
293
295
} else if u := isURL (fpath ); u != nil {
294
- base := urlBase (u )
295
- fpath = base
296
- if _ , ok := fileArgs [fpath ]; ok {
297
- // Ensure a unique fpath by suffixing ' (n)'.
298
- for i := 1 ; ; i ++ {
299
- fpath = fmt .Sprintf ("%s (%d)" , base , i )
300
- if _ , ok := fileArgs [fpath ]; ! ok {
301
- break
302
- }
303
- }
304
- }
296
+ fpath = urlBase (u )
305
297
file = files .NewWebFile (u )
306
298
} else {
307
299
fpath = filepath .Clean (fpath )
@@ -336,15 +328,15 @@ func parseArgs(req *cmds.Request, root *cmds.Command, stdin *os.File) error {
336
328
file = nf
337
329
}
338
330
339
- fileArgs [ fpath ] = file
331
+ fileArgs = append ( fileArgs , files . FileEntry ( fpath , file ))
340
332
} else if stdin != nil && argDef .SupportsStdin &&
341
333
argDef .Required && ! fillingVariadic {
342
334
r , err := maybeWrapStdin (stdin , msgStdinInfo )
343
335
if err != nil {
344
336
return err
345
337
}
346
338
347
- fileArgs [ stdinName ( req )] , err = files .NewReaderPathFile (stdin .Name (), r , nil )
339
+ fileStdin , err = files .NewReaderPathFile (stdin .Name (), r , nil )
348
340
if err != nil {
349
341
return err
350
342
}
@@ -370,8 +362,14 @@ func parseArgs(req *cmds.Request, root *cmds.Command, stdin *os.File) error {
370
362
}
371
363
372
364
req .Arguments = stringArgs
365
+ if fileStdin != nil {
366
+ fileArgs = append (fileArgs , files .FileEntry (stdinName (req ), fileStdin ))
367
+ }
373
368
if len (fileArgs ) > 0 {
374
- req .Files = files .NewMapDirectory (fileArgs )
369
+ sort .Slice (fileArgs , func (i , j int ) bool {
370
+ return fileArgs [i ].Name () < fileArgs [j ].Name ()
371
+ })
372
+ req .Files = files .NewSliceDirectory (fileArgs )
375
373
}
376
374
377
375
return nil
0 commit comments