| 446 | } |
| 447 | |
| 448 | func adaptShellArgs(rootCmd *cobra.Command, currentPath string, args []string) []string { |
| 449 | if len(args) == 0 { |
| 450 | return args |
| 451 | } |
| 452 | |
| 453 | cmd, consumed := resolveCommand(rootCmd, args) |
| 454 | if consumed == 0 { |
| 455 | return args |
| 456 | } |
| 457 | |
| 458 | commandKey := canonicalCommandKey(rootCmd, cmd) |
| 459 | rest := append([]string{}, args[consumed:]...) |
| 460 | flags := inspectShellArgs(rest) |
| 461 | |
| 462 | switch commandKey { |
| 463 | case "ls", "empty", "rubbish": |
| 464 | rest = rewritePositionalPaths(rest, currentPath, 1) |
| 465 | if flags.positionals == 0 && !flags.hasPath && !flags.hasParentID { |
| 466 | rest = append([]string{"-p", currentPath}, rest...) |
| 467 | } |
| 468 | case "download": |
| 469 | rest = rewritePathFlagValues(rest, currentPath) |
| 470 | if flags.positionals > 0 && !flags.hasPath && !flags.hasParentID { |
| 471 | rest = append([]string{"-p", currentPath}, rest...) |
| 472 | } |
| 473 | case "upload": |
| 474 | rest = rewritePathFlagValues(rest, currentPath) |
| 475 | if flags.positionals > 0 && !flags.hasPath && !flags.hasParentID { |
| 476 | rest = append([]string{"-p", currentPath}, rest...) |
| 477 | } |
| 478 | case "share", "new folder", "new url", "new sha": |
| 479 | rest = rewritePathFlagValues(rest, currentPath) |
| 480 | if !flags.hasPath && !flags.hasParentID { |
| 481 | rest = append([]string{"-p", currentPath}, rest...) |
| 482 | } |
| 483 | case "delete": |
| 484 | if !flags.hasPath { |
| 485 | rest = rewritePositionalPaths(rest, currentPath, -1) |
| 486 | } |
| 487 | case "rename": |
| 488 | rest = rewritePositionalPaths(rest, currentPath, 1) |
| 489 | } |
| 490 | |
| 491 | return append(append([]string{}, args[:consumed]...), rest...) |
| 492 | } |
| 493 | |
| 494 | func canonicalCommandKey(rootCmd *cobra.Command, cmd *cobra.Command) string { |
| 495 | if cmd == nil { |