简体   繁体   中英

Named argument for fish function with argparse

The fish function builtin has the option -a/--argument-names which allows binding an argument to a name.

Is it still possible to do this while also using the argparse builtin? If so, how?

I designed and implemented argparse . Yes, technically you can use the --argument flag and argparse in the same function but doing so makes no sense. The --argument option operates completely independently of argparse and has no knowledge of flags. Create the following function:

function x -a arg1 -a arg2
    set --show arg1 arg2 argv
end

Now invoke it thusly: x --flag val arg . Notice that --flag is bound to arg1 and val is bound to arg2 and argv still contains all of the arguments passed to the function. If your function has flags you shouldn't use --argument . If it doesn't then there isn't any point in using argparse .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM