MCPcopy Create free account
hub / github.com/52funny/pikpakcli / adaptShellArgs

Function adaptShellArgs

internal/shell/shell.go:448–492  ·  view source on GitHub ↗
(rootCmd *cobra.Command, currentPath string, args []string)

Source from the content-addressed store, hash-verified

446}
447
448func 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
494func canonicalCommandKey(rootCmd *cobra.Command, cmd *cobra.Command) string {
495 if cmd == nil {

Callers 5

StartFunction · 0.85
TestAdaptShellArgsFunction · 0.85

Calls 5

resolveCommandFunction · 0.85
canonicalCommandKeyFunction · 0.85
inspectShellArgsFunction · 0.85
rewritePositionalPathsFunction · 0.85
rewritePathFlagValuesFunction · 0.85

Tested by 4

TestAdaptShellArgsFunction · 0.68