Skip to content

Commit 5f0ace7

Browse files
committed
client/cordium - add GetResourceShortName
1 parent 67aff89 commit 5f0ace7

4 files changed

Lines changed: 62 additions & 7 deletions

File tree

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright Octelium Labs, LLC. All rights reserved.
3+
*
4+
* This program is free software: you can redistribute it and/or modify
5+
* it under the terms of the GNU Affero General Public License version 3,
6+
* as published by the Free Software Foundation of the License.
7+
*
8+
* This program is distributed in the hope that it will be useful,
9+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11+
* GNU Affero General Public License for more details.
12+
*
13+
* You should have received a copy of the GNU Affero General Public License
14+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
15+
*/
16+
17+
package ccommon
18+
19+
import (
20+
"strings"
21+
22+
"github.com/octelium/octelium/apis/main/metav1"
23+
"github.com/octelium/octelium/pkg/apiutils/umetav1"
24+
)
25+
26+
func GetResourceShortName(rsc umetav1.ResourceObjectI) string {
27+
if rsc == nil || rsc.GetMetadata() == nil {
28+
return ""
29+
}
30+
31+
return doGetShortName(rsc.GetMetadata().Name)
32+
}
33+
34+
func GetResourceRefShortName(itm *metav1.ObjectReference) string {
35+
if itm == nil {
36+
return ""
37+
}
38+
39+
return doGetShortName(itm.Name)
40+
}
41+
42+
func doGetShortName(arg string) string {
43+
if arg == "" {
44+
return ""
45+
}
46+
return strings.Split(arg, ".")[0]
47+
}

client/cordium/commands/get/space/cmd.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package space
1919
import (
2020
"fmt"
2121

22+
"github.com/octelium/cordium/client/cordium/commands/ccommon"
2223
pb "github.com/octelium/octelium/apis/main/cordiumv1"
2324
"github.com/octelium/octelium/apis/main/metav1"
2425
"github.com/octelium/octelium/client/common/client"
@@ -99,9 +100,10 @@ func doCmd(cmd *cobra.Command, args []string) error {
99100
return nil
100101
}
101102

102-
p := printer.NewPrinter("Name", "Description")
103-
for _, net := range itmList.Items {
104-
p.AppendRow(net.Metadata.Name, net.Metadata.Description)
103+
p := printer.NewPrinter("Name", "Created")
104+
for _, itm := range itmList.Items {
105+
p.AppendRow(ccommon.GetResourceShortName(itm),
106+
cliutils.GetResourceAge(itm))
105107
}
106108

107109
p.Render()

client/cordium/commands/get/template/cmd.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package template
1919
import (
2020
"fmt"
2121

22+
"github.com/octelium/cordium/client/cordium/commands/ccommon"
2223
pb "github.com/octelium/octelium/apis/main/cordiumv1"
2324
"github.com/octelium/octelium/apis/main/metav1"
2425
"github.com/octelium/octelium/client/common/client"
@@ -110,9 +111,11 @@ func doCmd(cmd *cobra.Command, args []string) error {
110111
return nil
111112
}
112113

113-
p := printer.NewPrinter("Name", "Description")
114-
for _, net := range itmList.Items {
115-
p.AppendRow(net.Metadata.Name, net.Metadata.Description)
114+
p := printer.NewPrinter("Name", "Created", "Space")
115+
for _, itm := range itmList.Items {
116+
p.AppendRow(ccommon.GetResourceShortName(itm),
117+
cliutils.GetResourceAge(itm),
118+
ccommon.GetResourceRefShortName(itm.Status.SpaceRef))
116119
}
117120

118121
p.Render()

client/cordium/commands/get/workspace/cmd.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"fmt"
2121
"time"
2222

23+
"github.com/octelium/cordium/client/cordium/commands/ccommon"
2324
pb "github.com/octelium/octelium/apis/main/cordiumv1"
2425
"github.com/octelium/octelium/apis/main/metav1"
2526
"github.com/octelium/octelium/client/common/client"
@@ -122,10 +123,12 @@ func doCmd(cmd *cobra.Command, args []string) error {
122123
return nil
123124
}
124125

125-
p := printer.NewPrinter("Name", "Created", "State", "Last Started")
126+
p := printer.NewPrinter("Name", "Created", "Template", "Space", "State", "Last Started")
126127
for _, itm := range itmList.Items {
127128
p.AppendRow(itm.Metadata.Name,
128129
cliutils.GetResourceAge(itm),
130+
ccommon.GetResourceRefShortName(itm.Status.TemplateRef),
131+
ccommon.GetResourceRefShortName(itm.Status.SpaceRef),
129132
itm.Status.State.String(),
130133
cliutils.GetAgeFromTimestampMust(itm.Status.LastInitializedAt.AsTime().Format(time.RFC3339Nano)))
131134
}

0 commit comments

Comments
 (0)