Skip to content
This repository was archived by the owner on Jan 21, 2020. It is now read-only.

Commit d19f017

Browse files
author
David Chung
authored
Misc bug fixes for CLI remote and var template function (#727)
Signed-off-by: David Chung <[email protected]>
1 parent c220c4e commit d19f017

File tree

2 files changed

+14
-36
lines changed

2 files changed

+14
-36
lines changed

cmd/infrakit/remote/remote.go

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
3333

3434
bastionAddr := ""
3535
user := ""
36-
add := &cobra.Command{
37-
Use: "add <name> <url_list>",
38-
Short: "Add a remote",
36+
set := &cobra.Command{
37+
Use: "set <name> <url_list>",
38+
Short: "Set a remote",
3939
RunE: func(cmd *cobra.Command, args []string) error {
4040

4141
if len(args) != 2 {
@@ -60,28 +60,25 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
6060
return hosts.Save()
6161
},
6262
}
63-
add.Flags().StringVar(&bastionAddr, "ssh-addr", bastionAddr, "The public host to tunnel")
64-
add.Flags().StringVar(&user, "ssh-user", user, "The ssh user")
63+
set.Flags().StringVar(&bastionAddr, "ssh-addr", bastionAddr, "The public host to tunnel")
64+
set.Flags().StringVar(&user, "ssh-user", user, "The ssh user")
6565

6666
remove := &cobra.Command{
6767
Use: "rm <name>",
6868
Short: "Remove a remote",
6969
RunE: func(cmd *cobra.Command, args []string) error {
7070

71-
if len(args) != 1 {
71+
if len(args) == 0 {
7272
cmd.Usage()
7373
os.Exit(1)
7474
}
75-
76-
name := args[0]
77-
7875
hosts, err := cli.LoadHosts()
7976
if err != nil {
8077
return err
8178
}
82-
83-
delete(hosts, name)
84-
79+
for _, name := range args {
80+
delete(hosts, name)
81+
}
8582
return hosts.Save()
8683
},
8784
}
@@ -134,6 +131,6 @@ func Command(plugins func() discovery.Plugins) *cobra.Command {
134131
}
135132
list.Flags().AddFlagSet(outputFlags)
136133

137-
cmd.AddCommand(add, remove, list, current)
134+
cmd.AddCommand(set, remove, list, current)
138135
return cmd
139136
}

pkg/run/template/std.go

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package template
22

33
import (
4-
"fmt"
5-
"strings"
6-
74
"github.com/docker/infrakit/pkg/discovery"
85
metadata_template "github.com/docker/infrakit/pkg/plugin/metadata/template"
96
"github.com/docker/infrakit/pkg/template"
@@ -30,27 +27,11 @@ func StdFunctions(engine *template.Template, plugins func() discovery.Plugins) *
3027
// returns nil if it's a read and unresolved
3128
// or if it's a write, returns a void value that is not nil (an empty string)
3229
v := engine.Var(name, optional...)
33-
switch {
34-
case len(optional) > 0: // writing
35-
return v, nil
36-
case v != nil && !engine.Options().MultiPass: // reading, resolved
37-
return v, nil
38-
}
39-
// Check to see if the value is resolved... in the case of multipass, we can get `{{ var foo }}` back
40-
if engine.Options().MultiPass {
41-
delim := `{{`
42-
if engine.Options().DelimLeft != "" {
43-
delim = engine.Options().DelimLeft
44-
}
45-
if strings.Index(fmt.Sprintf("%v", v), delim) < 0 {
46-
return v, nil
47-
}
48-
// If it's multipass and we have a template expression returned, then the value is not resolved.
49-
// continue to look up as metadata
30+
if v == nil {
31+
// If not resolved, try to interpret the path as a path for metadata...
32+
return metadata_template.MetadataFunc(plugins)(name, optional...)
5033
}
51-
52-
// If not resolved, try to interpret the path as a path for metadata...
53-
return metadata_template.MetadataFunc(plugins)(name, optional...)
34+
return v, nil
5435
},
5536
},
5637
}

0 commit comments

Comments
 (0)