complete icon indicating copy to clipboard operation
complete copied to clipboard

Bring flag arguments to subcommand?

Open Arneball opened this issue 3 years ago • 7 comments

Is there any way for a subcommands' prediction to get its parents flags?

For example

adb -s FA81Y1A02186 uninstall com.blabla

-s flag correctly predicts FA81Y1A02186.

However, if i in the handler want to predict what packages to uninstall, i need the predicted flag value from before. Because i want to query the specific device for packages that are installed. Currently i can't. Maybe i've missed something.

Arneball avatar Apr 13 '21 10:04 Arneball

Hi, Sorry, I don't understand the question. In the above example, what is the flag, the subcommand and the predication? What is currently possible and what would you like to be able to do?

The current behavior is that flags in a command will be available in all the subcommands and not the other way around. Does it make sense?

posener avatar Apr 15 '21 19:04 posener

  • The flag for "install" is "-s", "FA81Y1A02186"
  • I want to bring FA81Y1A02186 to the subcommand "install"'s prediction function. Hope it clarifies a bit, can share a snippet otherwise.

Arneball avatar Apr 15 '21 19:04 Arneball

If -s is a flag of the root command, then it should be also completed for all sub commands. So adb uninstall com.blabla -s <tab> should complete in the same manner as adb -s <tab>. If this is not working for you, it is a bug. Can you provide some code that is not working and we can try and understand what is the issue?

posener avatar Apr 15 '21 20:04 posener

Check this branch https://github.com/Arneball/adb_bash_completions/tree/posener Screenshot 2021-04-15 at 22 44 35

COMP_LINE="adb -s 192.168.1.64 uninstall " go run .

Arneball avatar Apr 15 '21 20:04 Arneball

https://github.com/Arneball/complete/commit/a6a001178d79f5ec7c2d977de90ca6cf52923250

Could this be something?

Arneball avatar Apr 15 '21 22:04 Arneball

Oh, I see, so you want that the root "args" will be completed in a subcommand "args". This is a bit problematic - what happens when both the root command and the sub command have args. Usually the args will be a sub-command depended. And if they are common to two subcommands, they can share the same object in their Args vaule. Does this make sense?

posener avatar Apr 17 '21 16:04 posener

I don't think we have a mutual understanding :D

$ birdfeeder -type scavanger feed [cursor]
func getFood(a Args) []string {
	// Completion command for different food. Having the type of bird would be nice
}

Your issue is that feed subcommand could possibly define a type argument itself, thus polluting the prediction for the subcommand?

Arneball avatar Apr 18 '21 18:04 Arneball