diff --git a/internal/hook/aliases.go b/internal/hook/aliases.go index 9984147..e0bfc68 100644 --- a/internal/hook/aliases.go +++ b/internal/hook/aliases.go @@ -172,7 +172,8 @@ func BuildAliasEntries(entries []cache.Entry, cfg config.Config) []AliasEntry { hostname = instance instance = "" } - hostMetadata[e.Name] = config.SSHHost{Instance: instance, Name: hostname, Kind: e.Kind, Tags: e.Tags} + hostMetadata[e.Name] = config.SSHHost{Instance: instance, Name: hostname, Kind: e.Kind, Tags: e.Tags, Status: e.Status, + Site: cache.RefOf(e.Site), Role: cache.RefOf(e.Role), Platform: cache.RefOf(e.Platform), Tenant: cache.RefOf(e.Tenant)} } var commands []string for name := range cfg.Commands { diff --git a/internal/hook/aliases_test.go b/internal/hook/aliases_test.go index 5a17f9a..c21a5f4 100644 --- a/internal/hook/aliases_test.go +++ b/internal/hook/aliases_test.go @@ -416,3 +416,22 @@ func TestCustomAliasShellArgumentQuoting(t *testing.T) { }) } } + +func TestCommandAliasesHonourNetBoxAttributes(t *testing.T) { + cfg := config.Config{Commands: map[string]config.HostCommand{ + "cli": {AliasPrefix: "c", Args: []string{"cli", "{address}"}, Match: config.SSHMatch{Platform: "junos"}}, + }} + entries := []cache.Entry{ + {Name: "sw1", Kind: "device", Platform: &config.Ref{Name: "Junos", Slug: "junos"}}, + {Name: "web1", Kind: "vm", Platform: &config.Ref{Slug: "ubuntu"}}, + } + var got []string + for _, a := range hook.BuildAliasEntries(entries, cfg) { + if a.Command == "cli" { + got = append(got, a.Name) + } + } + if len(got) != 1 || got[0] != "csw1" { + t.Fatalf("command aliases %v", got) + } +}