As far as I understand the code (just skimmed through the repo), there are two ways to proceed here:
Write a xtask,
Hook into the build script.
Also, the clap_complete examples show how to generate those completions files in the OUT_DIR (meaning target/$profile/build/app-$hash/.
I'd rather have them generated in the CARGO_MANIFEST_DIR i.e. at the project's root.
It seems to me that for security reasons the build script can only write to OUT_DIR.
So, if you want to write the autocompletion script elsewhere, you may need to write a xtask instead.
But xtask must be very fast to compile, and to generate the auto-completion script you need the whole node as a dependency, right? If this is the case then it can't be in xtask.
It seems to me that for security reasons the build script can only write to OUT_DIR.
Ho, you may have done some stuff like that.
Using CARGO_MANIFEST_DIR works for my personal projects.
Anyway: xtask it will be.
In term of dependencies, there are approximately none.The preferred way (says the clap_complete documentation) is even ton include! the cli.rs file using its relative path from the xtask code.So, no dependency to the node AFAIK.
I looked a bit more at the code and I was clearly wrong.
There will be some dependency here.
But it'll also be fast.
I'll give it a go in the coming days when I find the time and submit a MR.
you may have done some stuff like that. Using CARGO_MANIFEST_DIR works for my personal projects.
Yes, I did that in the past and it worked. But I thought I read in the docs that it was not recommended, and that in the future the write power of the build.rs script could be restricted for security.
The preferred way (says the clap_complete documentation) is even ton include! the cli.rs file using its relative path
The problem is that our cli.rs file contains only a small part of our options and flags, most of them being imported from substrate.
I don't know how clap_complete work, I just saw that it existed, and created this issue for later.
It's up to you to test it, but I don't understand how you can have an autocomplete of all the flags without the substrate dependencies :)
xtask must be fast so depending on duniter is not a viable option,
build.rs has this path limitation (and will also depend on substrate if it has to generate completion at build time).
What about, the simplest approach of all: adding an option to duniter like in the clap_complete basic example?
It can be a subcommand as there are already plenty.
The downside is that it adds clap_complete as a duniter dependency.
What about, the simplest approach of all: adding an option to duniter like in the clap_complete basic example? It can be a subcommand as there are already plenty.
I like this solution
The downside is that it adds clap_complete as a duniter dependency.
It's not a problem, it's a much less annoying inconvenience than the other 2 solutions.
I don't have enough right to push my (wip) branch on the repo.
I saw nothing about forking in the contribution guidelines but I might be wrong.
For now I can generate the completions on release only.
See _duniter for zsh and duniter.bash for bash.
There is an issue when on debug I yet have to investigate.