[lxc-devel] [lxd/master] lxc: Better handle arguments
stgraber on Github
lxc-bot at linuxcontainers.org
Wed Sep 16 20:30:39 UTC 2020
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 783 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200916/decc8bd6/attachment.bin>
-------------- next part --------------
From 50373fef4298d343ef64d8375c2706347f77b7de Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Wed, 16 Sep 2020 16:28:13 -0400
Subject: [PATCH] lxc: Better handle arguments
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This allows things like:
- lxc --project=blah shell abc
- lxc --debug shell abc
Not that it aliases cannot support leading flags with value separated by
spaces as the alias handling logic does not know what flag is a boolean
and what flag takes a value.
As a result, use `lxc --project=blah shell` and not `lxc --project blah shell`
as the latter cannot work and will lead to a confusing error.
Closes #7625
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
lxc/main_aliases.go | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/lxc/main_aliases.go b/lxc/main_aliases.go
index 6367d6ae55..fd37122339 100644
--- a/lxc/main_aliases.go
+++ b/lxc/main_aliases.go
@@ -48,7 +48,7 @@ func expandAlias(conf *config.Config, args []string) ([]string, bool) {
var newArgs []string
var origArgs []string
- for _, arg := range args {
+ for _, arg := range args[1:] {
if arg[0] != '-' {
break
}
@@ -56,7 +56,7 @@ func expandAlias(conf *config.Config, args []string) ([]string, bool) {
newArgs = append(newArgs, arg)
}
- origArgs = args[len(newArgs):]
+ origArgs = append([]string{args[0]}, args[len(newArgs)+1:]...)
aliasKey, aliasValue, foundAlias := findAlias(conf.Aliases, origArgs)
if !foundAlias {
@@ -67,7 +67,7 @@ func expandAlias(conf *config.Config, args []string) ([]string, bool) {
}
if !strings.HasPrefix(aliasValue[0], "/") {
- newArgs = append(newArgs, origArgs[0])
+ newArgs = append([]string{origArgs[0]}, newArgs...)
}
hasReplacedArgsVar := false
More information about the lxc-devel
mailing list