this is my first question here and I hope I get it right and don't come across as overly stupid immediately.
I am currently working on an existing CLI tool which I hope to convert into a more generic version of what it currently is. This is mostly so I learn the ropes with Rust.
I was scouring the documentation for clap (I'm using 3.0.0-beta.2 as per the README) and wasn't able to find what I am looking for.
With clap subcommands by default seem to behave similar to how git <subcommand> works and I think I even saw that example mentioned. I would like for that to work as well. However, if the binary exists under a basename that corresponds to a subcommand, I'd like it to behave as if I had invoked basename subcommand, where basename is the name of the binary (minus .exe file extension on Windows). On unixoid systems that could be in the form of a hardlink or a symlink and on Windows it could be a hardlink.
In essence I'd like it to behave similar to how Busybox behaves. I found and briefly looked at Rustybox but that appears to be mostly an automatically translated version of the C version of Busybox, which doesn't help me figure out how to do it in Rust, though.
I am aware that under Linux conventionally I'd be able to look at /proc/self/exe and in Win32 I could use GetModuleFileName to read the path to the binary that started the process. Is there a more cross-platform way to do that in Rust itself, or is this an example of having to implement this for each individual platform within a crate?
Thanks for the multiple ways. @ZiCog arguably this isn't hard for you. But everything is hard until it gets easy. And I am still in that phase where it hasn't gotten easy. So thanks for lending a hand!
And moreover thanks to everyone for providing variations on what I am trying to do. This is the best way of learning: reading code, wondering what its parts do and then reading up on those points.
(I'll test them one by one before marking one as the solution. But not tonight )