Lxc alias doesn't work with @ARGS@

Following this discussion, I am trying to set up the following alias in order to list the snapshots of a given container (without using lxc info, which is too verbose):

$ lxc alias add snaps 'query /1.0/instances/@ARGS@/snapshots'

However, it doesn’t work:

$ lxc snaps foo
[...]
Error: Invalid number of arguments

The problem seems to be with the @ARGS@ placeholder. I tried to “escape” it in various ways, all without success:

lxc alias add snaps "query /1.0/instances/'@ARGS@'/snapshots"
lxc alias add snaps 'query /1.0/instances/"@ARGS@"/snapshots'
lxc alias add snaps 'query "/1.0/instances/@ARGS@/snapshots"'
lxc alias add snaps "query '/1.0/instances/@ARGS@/snapshots'"
lxc alias add snaps "query /1.0/instances/\@ARGS\@/snapshots"
lxc alias add snaps 'query /1.0/instances/\@ARGS\@/snapshots'
lxc alias add snaps "query /1.0/instances/\\@ARGS\\@/snapshots"

I am running out of ideas :frowning:

I would be grateful for any help/suggestion

Ah yeah, @ARGS@ is not meant to be used like that.

It’s supposed to be used as an argument itself (not part of one) and causes that argument to be replaced by all other arguments passed by the user.

What we could do is introduce additional placeholders like @ARG1@ which would work within arguments themselves.

Thanks Stéphane. Having real positional arguments would be great: imagine all the aliases based on API query we could add!

I’ve asked @markylaing to take a look when he has a minute, hopefully something reasonably easy to add.

1 Like

Many thanks.

Just upgraded to lxd 4.22 and it works now! Thanks a lot

$ pacman -Q lxd
lxd 4.22-1
$ lxc alias add snaps 'query /1.0/instances/@ARG1@/snapshots'
$ lxc snaps eurts
[
        "/1.0/instances/eurts/snapshots/snap0",
        "/1.0/instances/eurts/snapshots/snap1",
        "/1.0/instances/eurts/snapshots/snap2"
]
2 Likes

Excellent!