The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/4883

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
Closes #3233 

Signed-off-by: Thomas Hipp <thomas.h...@canonical.com>
From 42c494e6fa7bc1371577ab7a999f918c03c3675b Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.h...@canonical.com>
Date: Tue, 7 Aug 2018 10:07:46 +0200
Subject: [PATCH] lxc: Allow aliases to external commands

Signed-off-by: Thomas Hipp <thomas.h...@canonical.com>
---
 lxc/main_aliases.go | 7 +++++--
 lxc/main_test.go    | 5 +++++
 2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/lxc/main_aliases.go b/lxc/main_aliases.go
index 83c8e76faf..3865b3a6fa 100644
--- a/lxc/main_aliases.go
+++ b/lxc/main_aliases.go
@@ -54,7 +54,10 @@ func expandAlias(conf *config.Config, origArgs []string) 
([]string, bool) {
                }
        }
 
-       newArgs := []string{origArgs[0]}
+       var newArgs []string
+       if !strings.HasPrefix(aliasValue[0], "/") {
+               newArgs = append(newArgs, origArgs[0])
+       }
        hasReplacedArgsVar := false
 
        for i, aliasArg := range aliasValue {
@@ -118,7 +121,7 @@ func execIfAliases() {
        }
 
        // Look for the executable
-       path, err := exec.LookPath(args[0])
+       path, err := exec.LookPath(newArgs[0])
        if err != nil {
                fmt.Fprintf(os.Stderr, i18n.G("Processing aliases failed: 
%s\n"), err)
                os.Exit(1)
diff --git a/lxc/main_test.go b/lxc/main_test.go
index 4e42e01be7..9165bc26a3 100644
--- a/lxc/main_test.go
+++ b/lxc/main_test.go
@@ -37,6 +37,7 @@ func TestExpandAliases(t *testing.T) {
        aliases := map[string]string{
                "tester 12": "list",
                "foo":       "list @ARGS@ -c n",
+               "ssh":       "/usr/bin/ssh @ARGS@",
        }
 
        testcases := []aliasTestcase{
@@ -52,6 +53,10 @@ func TestExpandAliases(t *testing.T) {
                        input:    []string{"lxc", "foo", "asdf"},
                        expected: []string{"lxc", "list", "asdf", "-c", "n"},
                },
+               {
+                       input:    []string{"lxc", "ssh", "c1"},
+                       expected: []string{"/usr/bin/ssh", "c1"},
+               },
        }
 
        conf := &config.Config{Aliases: aliases}
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to