99 "path"
1010 "path/filepath"
1111 "reflect"
12+ "sort"
1213 "strings"
1314
1415 osh "github.com/Kubuxu/go-os-helper"
@@ -236,7 +237,8 @@ func parseArgs(req *cmds.Request, root *cmds.Command, stdin *os.File) error {
236237 }
237238
238239 stringArgs := make ([]string , 0 , numInputs )
239- fileArgs := make (map [string ]files.Node )
240+ fileArgs := make ([]files.DirEntry , 0 )
241+ var fileStdin files.Node
240242
241243 // the index of the current argument definition
242244 iArgDef := 0
@@ -266,7 +268,7 @@ func parseArgs(req *cmds.Request, root *cmds.Command, stdin *os.File) error {
266268 stringArgs , inputs = append (stringArgs , inputs [0 ]), inputs [1 :]
267269 } else if stdin != nil && argDef .SupportsStdin && ! fillingVariadic {
268270 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 )
270272 if err != nil {
271273 return err
272274 }
@@ -291,17 +293,7 @@ func parseArgs(req *cmds.Request, root *cmds.Command, stdin *os.File) error {
291293 return err
292294 }
293295 } 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 )
305297 file = files .NewWebFile (u )
306298 } else {
307299 fpath = filepath .Clean (fpath )
@@ -336,15 +328,15 @@ func parseArgs(req *cmds.Request, root *cmds.Command, stdin *os.File) error {
336328 file = nf
337329 }
338330
339- fileArgs [ fpath ] = file
331+ fileArgs = append ( fileArgs , files . FileEntry ( fpath , file ))
340332 } else if stdin != nil && argDef .SupportsStdin &&
341333 argDef .Required && ! fillingVariadic {
342334 r , err := maybeWrapStdin (stdin , msgStdinInfo )
343335 if err != nil {
344336 return err
345337 }
346338
347- fileArgs [ stdinName ( req )] , err = files .NewReaderPathFile (stdin .Name (), r , nil )
339+ fileStdin , err = files .NewReaderPathFile (stdin .Name (), r , nil )
348340 if err != nil {
349341 return err
350342 }
@@ -370,8 +362,14 @@ func parseArgs(req *cmds.Request, root *cmds.Command, stdin *os.File) error {
370362 }
371363
372364 req .Arguments = stringArgs
365+ if fileStdin != nil {
366+ fileArgs = append (fileArgs , files .FileEntry (stdinName (req ), fileStdin ))
367+ }
373368 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 )
375373 }
376374
377375 return nil
0 commit comments