cmd/dlv: improve positional argument completion (#3699)

Avoid default filename completions when not applicable.
This commit is contained in:
Ville Skyttä 2024-04-18 18:57:33 +03:00 committed by GitHub
parent 95e2a57b92
commit 3f280259ad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -183,6 +183,12 @@ option to let the process continue or kill it.
return nil return nil
}, },
Run: attachCmd, Run: attachCmd,
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) != 1 {
return nil, cobra.ShellCompDirectiveNoFileComp
}
return nil, cobra.ShellCompDirectiveDefault
},
} }
attachCommand.Flags().BoolVar(&continueOnStart, "continue", false, "Continue the debugged process on start.") attachCommand.Flags().BoolVar(&continueOnStart, "continue", false, "Continue the debugged process on start.")
attachCommand.Flags().StringVar(&attachWaitFor, "waitfor", "", "Wait for a process with a name beginning with this prefix") attachCommand.Flags().StringVar(&attachWaitFor, "waitfor", "", "Wait for a process with a name beginning with this prefix")
@ -204,7 +210,8 @@ option to let the process continue or kill it.
} }
return nil return nil
}, },
Run: connectCmd, Run: connectCmd,
ValidArgsFunction: cobra.NoFileCompletions,
} }
rootCommand.AddCommand(connectCommand) rootCommand.AddCommand(connectCommand)
@ -233,7 +240,8 @@ execution is resumed at the start of the debug session.
The --client-addr flag is a special flag that makes the server initiate a debug session The --client-addr flag is a special flag that makes the server initiate a debug session
by dialing in to the host:port where a DAP client is waiting. This server process by dialing in to the host:port where a DAP client is waiting. This server process
will exit when the debug session ends.`, will exit when the debug session ends.`,
Run: dapCmd, Run: dapCmd,
ValidArgsFunction: cobra.NoFileCompletions,
} }
dapCommand.Flags().StringVar(&dapClientAddr, "client-addr", "", "host:port where the DAP client is waiting for the DAP server to dial in") dapCommand.Flags().StringVar(&dapClientAddr, "client-addr", "", "host:port where the DAP client is waiting for the DAP server to dial in")
must(dapCommand.RegisterFlagCompletionFunc("client-addr", cobra.NoFileCompletions)) must(dapCommand.RegisterFlagCompletionFunc("client-addr", cobra.NoFileCompletions))
@ -251,7 +259,8 @@ By default, with no arguments, Delve will compile the 'main' package in the
current directory, and begin to debug it. Alternatively you can specify a current directory, and begin to debug it. Alternatively you can specify a
package name and Delve will compile that package instead, and begin a new debug package name and Delve will compile that package instead, and begin a new debug
session.`, session.`,
Run: debugCmd, Run: debugCmd,
ValidArgsFunction: cobra.NoFileCompletions,
} }
debugCommand.Flags().String("output", "", "Output path for the binary.") debugCommand.Flags().String("output", "", "Output path for the binary.")
must(debugCommand.MarkFlagFilename("output")) must(debugCommand.MarkFlagFilename("output"))
@ -280,6 +289,12 @@ or later, -gcflags="-N -l" on earlier versions of Go.`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
os.Exit(execute(0, args, conf, "", debugger.ExecutingExistingFile, args, buildFlags)) os.Exit(execute(0, args, conf, "", debugger.ExecutingExistingFile, args, buildFlags))
}, },
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) != 0 {
return nil, cobra.ShellCompDirectiveNoFileComp
}
return nil, cobra.ShellCompDirectiveDefault
},
} }
execCommand.Flags().StringVar(&tty, "tty", "", "TTY to use for the target program") execCommand.Flags().StringVar(&tty, "tty", "", "TTY to use for the target program")
must(execCommand.MarkFlagFilename("tty")) must(execCommand.MarkFlagFilename("tty"))
@ -312,7 +327,8 @@ that package instead. Double-dashes ` + "`--`" + ` can be used to pass arguments
dlv test [package] -- -test.run TestSomething -test.v -other-argument dlv test [package] -- -test.run TestSomething -test.v -other-argument
See also: 'go help testflag'.`, See also: 'go help testflag'.`,
Run: testCmd, Run: testCmd,
ValidArgsFunction: cobra.NoFileCompletions,
} }
testCommand.Flags().String("output", "", "Output path for the binary.") testCommand.Flags().String("output", "", "Output path for the binary.")
must(testCommand.MarkFlagFilename("output")) must(testCommand.MarkFlagFilename("output"))
@ -334,6 +350,7 @@ only see the output of the trace operations you can redirect stdout.`,
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
os.Exit(traceCmd(cmd, args, conf)) os.Exit(traceCmd(cmd, args, conf))
}, },
ValidArgsFunction: cobra.NoFileCompletions,
} }
traceCommand.Flags().IntVarP(&traceAttachPid, "pid", "p", 0, "Pid to attach to.") traceCommand.Flags().IntVarP(&traceAttachPid, "pid", "p", 0, "Pid to attach to.")
must(traceCommand.RegisterFlagCompletionFunc("pid", cobra.NoFileCompletions)) must(traceCommand.RegisterFlagCompletionFunc("pid", cobra.NoFileCompletions))
@ -365,6 +382,12 @@ Currently supports linux/amd64 and linux/arm64 core files, windows/amd64 minidum
return nil return nil
}, },
Run: coreCmd, Run: coreCmd,
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) > 2 {
return nil, cobra.ShellCompDirectiveNoFileComp
}
return nil, cobra.ShellCompDirectiveDefault
},
} }
// -c is unused and exists so delve can be used with coredumpctl // -c is unused and exists so delve can be used with coredumpctl
core := false core := false
@ -383,6 +406,7 @@ Currently supports linux/amd64 and linux/arm64 core files, windows/amd64 minidum
fmt.Printf("Build Details: %s\n", version.BuildInfo()) fmt.Printf("Build Details: %s\n", version.BuildInfo())
} }
}, },
ValidArgsFunction: cobra.NoFileCompletions,
} }
versionCommand.Flags().BoolVarP(&versionVerbose, "verbose", "v", false, "print verbose version info") versionCommand.Flags().BoolVarP(&versionVerbose, "verbose", "v", false, "print verbose version info")
rootCommand.AddCommand(versionCommand) rootCommand.AddCommand(versionCommand)
@ -406,6 +430,12 @@ https://github.com/mozilla/rr
backend = "rr" backend = "rr"
os.Exit(execute(0, []string{}, conf, args[0], debugger.ExecutingOther, args, buildFlags)) os.Exit(execute(0, []string{}, conf, args[0], debugger.ExecutingOther, args, buildFlags))
}, },
ValidArgsFunction: func(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective) {
if len(args) > 2 {
return nil, cobra.ShellCompDirectiveNoFileComp
}
return nil, cobra.ShellCompDirectiveDefault
},
} }
replayCommand.Flags().IntVarP(&rrOnProcessPid, "onprocess", "p", 0, replayCommand.Flags().IntVarP(&rrOnProcessPid, "onprocess", "p", 0,