[lxc-devel] [lxd/master] lxc/main_alias: Handle leading arguments
stgraber on Github
lxc-bot at linuxcontainers.org
Mon Jul 6 18:48:22 UTC 2020
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 370 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200706/1a52d08d/attachment.bin>
-------------- next part --------------
From 8c62fcd457017fd94946c369af4cc21425d6a2a6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Mon, 6 Jul 2020 14:47:41 -0400
Subject: [PATCH] lxc/main_alias: Handle leading arguments
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Closes #7625
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
lxc/main_aliases.go | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/lxc/main_aliases.go b/lxc/main_aliases.go
index dc35a3140e..6367d6ae55 100644
--- a/lxc/main_aliases.go
+++ b/lxc/main_aliases.go
@@ -44,7 +44,20 @@ func findAlias(aliases map[string]string, origArgs []string) ([]string, []string
return aliasKey, aliasValue, foundAlias
}
-func expandAlias(conf *config.Config, origArgs []string) ([]string, bool) {
+func expandAlias(conf *config.Config, args []string) ([]string, bool) {
+ var newArgs []string
+ var origArgs []string
+
+ for _, arg := range args {
+ if arg[0] != '-' {
+ break
+ }
+
+ newArgs = append(newArgs, arg)
+ }
+
+ origArgs = args[len(newArgs):]
+
aliasKey, aliasValue, foundAlias := findAlias(conf.Aliases, origArgs)
if !foundAlias {
aliasKey, aliasValue, foundAlias = findAlias(defaultAliases, origArgs)
@@ -53,7 +66,6 @@ func expandAlias(conf *config.Config, origArgs []string) ([]string, bool) {
}
}
- var newArgs []string
if !strings.HasPrefix(aliasValue[0], "/") {
newArgs = append(newArgs, origArgs[0])
}
More information about the lxc-devel
mailing list