There are "three" completion tests that multiply with the large number of
variatns present in the suite. The "simple" test is unsual and I don't fully
understand how it works because it does not install the test-snapd-complexion
snap at all. Instead it relies on running the completion script directly,
without the snap complete/etelpmoc script pair working across the sandbox.
Signed-off-by: Zygmunt Krynicki <zygmunt.krynicki@canonical.com>
Snapd installs bash completion files from snaps in
`/usr/share/bash-completion/completions` which in some distributions
is a read-only filesystem.
Instead of installing them in `/usr` we can install them within
`/var/lib/snapd` which should always be writable.
Because `/var/lib/snapd/desktop` is already in `XDG_DATA_DIRS`, we can
save the files there.
Because bash-completion 2.1 and prior do not support `XDG_DATA_DIRS`,
on older distributions, the legacy path
`/usr/share/bash-completion/completions` will still be used.
LP#1948838: moved files that cause an issue during git module download to tar files in the corresponding folders
Add spread test for validating snaps can be packed and installed (as well as `snap try`'d) with various circular symlinks.
completion functions (and commands, which we treat the same way) are
documented as receiving three arguments. I hadn't noticed, as almost
nobody uses them because most everything you need is in the different
COMP_ variables, but python's argcomplete module uses it.
This fixes that, and adds a spread test just in case.
This makes the code that manages command aliases aware of completion
support needs. That is: on alias CRUD, also CRUD the appropriate
symlinks for the completion snippets of the aliases.
For example, if you have a snap foo that has an app bar, and
foo.bar has a completer keyword in the yaml, then typing
foo.bar <tab> in bash will offer you completion via that snippet. If
you then snap alias foo.bar bar you'd expect to see the same
completion suggestions. This PR hooks things up so that you would, in
fact, get them.
This is invisible to the snap author -- the command completer
gets the original, unaliased completion request.
This also modifies complete.sh to support this, as well as some minor
changes to dirs and snap to accommodate.
Symlinking the snippets is itself simple enough that I didn't think it
was worth creating an ad-hoc helper, so it's just a few lines glommed
onto the end of the existing wrapper funcs (and tests).
To be clear, I did write the helper, but between it being very few
lines of code, it needing to return enough information to the
caller to clean up behind it if something else went wrong, and
especially as the other user of that helper would be the aliases
and they don't have access to the AppInfo (which would be the
obvious thing to pass to such helpers), I decided against it.
How aliases are going to play into completion is still an open
question on the implementation side, which I need to look into soon,
but this is not that work.
/etc/bash_completion does not exist on all distributions but
/usr/share/bash-completion does we so we can use this instead
in the test case to let it pass everywhere.