Skip to content

Commit

Permalink
feat: add display name to project get output
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrox committed Feb 6, 2024
1 parent 44df2a1 commit 67ccdfb
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 15 deletions.
9 changes: 7 additions & 2 deletions get/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

management "github.com/ninech/apis/management/v1alpha1"
"github.com/ninech/nctl/api"
"github.com/ninech/nctl/api/util"
"github.com/ninech/nctl/internal/format"
)

Expand Down Expand Up @@ -60,11 +61,15 @@ func printProject(projects []management.Project, get Cmd, out io.Writer, header
// for projects
if header {
get.AllProjects = false
get.writeHeader(w, "NAME")
get.writeHeader(w, "NAME", "DISPLAY NAME")
}

for _, proj := range projects {
get.writeTabRow(w, "", proj.Name)
displayName := proj.Spec.DisplayName
if len(displayName) == 0 {
displayName = util.NoneText
}
get.writeTabRow(w, "", proj.Name, displayName)
}

return w.Flush()
Expand Down
36 changes: 23 additions & 13 deletions get/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,36 +23,38 @@ func TestProject(t *testing.T) {

for name, testCase := range map[string]struct {
projects []client.Object
displayNames []string
name string
outputFormat output
allProjects bool
output string
}{
"projects exist, full format": {
projects: test.Projects(organization, "dev", "staging", "prod"),
displayNames: []string{"Development", "", "Production"},
outputFormat: full,
output: `NAME
dev
prod
staging
output: `NAME DISPLAY NAME
dev Development
prod Production
staging <none>
`,
},
"projects exist, no header format": {
projects: test.Projects(organization, "dev", "staging", "prod"),
outputFormat: noHeader,
output: `dev
prod
staging
output: `dev <none>
prod <none>
staging <none>
`,
},
"projects exist and allProjects is set": {
projects: test.Projects(organization, "dev", "staging", "prod"),
outputFormat: full,
allProjects: true,
output: `NAME
dev
prod
staging
output: `NAME DISPLAY NAME
dev <none>
prod <none>
staging <none>
`,
},
"no projects exist": {
Expand All @@ -69,8 +71,8 @@ staging
projects: test.Projects(organization, "dev", "staging"),
name: "dev",
outputFormat: full,
output: `NAME
dev
output: `NAME DISPLAY NAME
dev <none>
`,
},
"specific project requested, but does not exist": {
Expand Down Expand Up @@ -99,6 +101,14 @@ dev
t.Fatal(err)
}

projects := testCase.projects
for i, proj := range projects {
if len(projects) != len(testCase.displayNames) {
break
}
proj.(*management.Project).Spec.DisplayName = testCase.displayNames[i]
}

client := fake.NewClientBuilder().
WithScheme(scheme).
WithIndex(&management.Project{}, "metadata.name", func(o client.Object) []string {
Expand Down

0 comments on commit 67ccdfb

Please sign in to comment.