Skip to content

Commit faa4794

Browse files
authored
Add get menu items command (#187)
1 parent 6b496a0 commit faa4794

10 files changed

Lines changed: 160 additions & 9 deletions

File tree

CHANGES.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,15 @@ Changes by Version
22
==================
33
Release Notes.
44

5-
0.11.0
5+
0.13.0
6+
------------------
7+
8+
### Features
9+
## What's Changed
10+
11+
* Add the sub-command `menu get` for get the ui menu items by @mrproliu in https://github.com/apache/skywalking-cli/pull/187
12+
13+
0.12.0
614
------------------
715

816
### Features

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@ SkyWalking CLI and SkyWalking OAP communicate with different query version, here
163163
| \> = 0.11.0 | \> = 9.2.0 |
164164
| \> = 0.12.0 | \> = 9.3.0 |
165165
| \> = 0.12.0 | \> = 9.5.0 |
166+
| \> = 0.13.0 | \> = 9.6.0 |
166167

167168
# Contributing
168169

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Licensed to Apache Software Foundation (ASF) under one or more contributor
2+
# license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright
4+
# ownership. Apache Software Foundation (ASF) licenses this file to you under
5+
# the Apache License, Version 2.0 (the "License"); you may
6+
# not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
query {
19+
result: getMenuItems {
20+
name
21+
icon
22+
path
23+
activate
24+
subItems {
25+
name
26+
icon
27+
path
28+
activate
29+
}
30+
}
31+
}

cmd/swctl/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535
"github.com/apache/skywalking-cli/internal/commands/interceptor"
3636
"github.com/apache/skywalking-cli/internal/commands/layer"
3737
"github.com/apache/skywalking-cli/internal/commands/logs"
38+
"github.com/apache/skywalking-cli/internal/commands/menu"
3839
"github.com/apache/skywalking-cli/internal/commands/metrics"
3940
"github.com/apache/skywalking-cli/internal/commands/process"
4041
"github.com/apache/skywalking-cli/internal/commands/profiling"
@@ -106,6 +107,7 @@ services, service instances, etc.`
106107
process.Command,
107108
profiling.Command,
108109
records.Command,
110+
menu.Command,
109111
}
110112

111113
app.Before = interceptor.BeforeChain(

dist/LICENSE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ The text of each license is also included at licenses/license-[project].txt.
213213
k8s.io/utils v0.0.0-20210802155522-efc7438f0176 Apache-2.0
214214
sigs.k8s.io/controller-runtime v0.10.0 Apache-2.0
215215
sigs.k8s.io/structured-merge-diff/v4 v4.1.2 Apache-2.0
216-
skywalking.apache.org/repo/goapi v0.0.0-20230612142312-4a524db7a92c Apache-2.0
216+
skywalking.apache.org/repo/goapi v0.0.0-20230627041834-548963a0d5d7 Apache-2.0
217217

218218
========================================================================
219219
BSD-2-Clause licenses
@@ -250,7 +250,7 @@ The text of each license is also included at licenses/license-[project].txt.
250250
golang.org/x/term v0.5.0 BSD-3-Clause
251251
golang.org/x/text v0.7.0 BSD-3-Clause
252252
golang.org/x/time v0.0.0-20210723032227-1f47c861a9ac BSD-3-Clause
253-
google.golang.org/protobuf v1.30.0 BSD-3-Clause
253+
google.golang.org/protobuf v1.31.0 BSD-3-Clause
254254
gopkg.in/inf.v0 v0.9.1 BSD-3-Clause
255255

256256
========================================================================

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ require (
2020
gopkg.in/yaml.v2 v2.4.0
2121
k8s.io/apimachinery v0.22.1
2222
sigs.k8s.io/controller-runtime v0.10.0
23-
skywalking.apache.org/repo/goapi v0.0.0-20230612142312-4a524db7a92c
23+
skywalking.apache.org/repo/goapi v0.0.0-20230627041834-548963a0d5d7
2424
)
2525

2626
require (
@@ -77,7 +77,7 @@ require (
7777
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
7878
google.golang.org/appengine v1.6.7 // indirect
7979
google.golang.org/genproto v0.0.0-20210624195500-8bfb893ecb84 // indirect
80-
google.golang.org/protobuf v1.30.0 // indirect
80+
google.golang.org/protobuf v1.31.0 // indirect
8181
gopkg.in/inf.v0 v0.9.1 // indirect
8282
gopkg.in/ini.v1 v1.51.0 // indirect
8383
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -789,8 +789,8 @@ google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGj
789789
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
790790
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
791791
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
792-
google.golang.org/protobuf v1.30.0 h1:kPPoIgf3TsEvrm0PFe15JQ+570QVxYzEvvHqChK+cng=
793-
google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
792+
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
793+
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
794794
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
795795
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
796796
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
@@ -864,5 +864,5 @@ sigs.k8s.io/structured-merge-diff/v4 v4.1.2 h1:Hr/htKFmJEbtMgS/UD0N+gtgctAqz81t3
864864
sigs.k8s.io/structured-merge-diff/v4 v4.1.2/go.mod h1:j/nl6xW8vLS49O8YvXW1ocPhZawJtm+Yrr7PPRQ0Vg4=
865865
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
866866
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
867-
skywalking.apache.org/repo/goapi v0.0.0-20230612142312-4a524db7a92c h1:5ZqcUo6Uevrvlj4T2KV9XS/bRcmpfIEAGRaxDOf9Zr4=
868-
skywalking.apache.org/repo/goapi v0.0.0-20230612142312-4a524db7a92c/go.mod h1:bW4dg0GUN4rMCMS8DLlaY3ZiKUAJ1fQYKoZ91Bl0kTk=
867+
skywalking.apache.org/repo/goapi v0.0.0-20230627041834-548963a0d5d7 h1:ohL/krc7Pi032rl4zuYdzsS2R/HXcwGWY9UnW3JcvL0=
868+
skywalking.apache.org/repo/goapi v0.0.0-20230627041834-548963a0d5d7/go.mod h1:onFubXaIoY/2FTRVrLMqCTlaNq4SilAEwF/2G0IcaBw=

internal/commands/menu/get.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Licensed to Apache Software Foundation (ASF) under one or more contributor
2+
// license agreements. See the NOTICE file distributed with
3+
// this work for additional information regarding copyright
4+
// ownership. Apache Software Foundation (ASF) licenses this file to you under
5+
// the Apache License, Version 2.0 (the "License"); you may
6+
// not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package menu
19+
20+
import (
21+
"github.com/apache/skywalking-cli/pkg/display"
22+
"github.com/apache/skywalking-cli/pkg/display/displayable"
23+
"github.com/apache/skywalking-cli/pkg/graphql/menu"
24+
25+
"github.com/urfave/cli/v2"
26+
)
27+
28+
var Get = &cli.Command{
29+
Name: "get",
30+
Usage: "Get the UI menu items",
31+
UsageText: `Get the UI menu items.
32+
33+
Examples:
34+
1. Get the UI menu items:
35+
$swctl menu get`,
36+
Action: func(ctx *cli.Context) error {
37+
menuItems, err := menu.GetItems(ctx)
38+
if err != nil {
39+
return err
40+
}
41+
return display.Display(ctx, &displayable.Displayable{Data: menuItems})
42+
},
43+
}

internal/commands/menu/menu.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Licensed to Apache Software Foundation (ASF) under one or more contributor
2+
// license agreements. See the NOTICE file distributed with
3+
// this work for additional information regarding copyright
4+
// ownership. Apache Software Foundation (ASF) licenses this file to you under
5+
// the Apache License, Version 2.0 (the "License"); you may
6+
// not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package menu
19+
20+
import "github.com/urfave/cli/v2"
21+
22+
var Command = &cli.Command{
23+
Name: "menu",
24+
Usage: "Management the UI menu",
25+
Subcommands: cli.Commands{
26+
Get,
27+
},
28+
}

pkg/graphql/menu/menu.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Licensed to Apache Software Foundation (ASF) under one or more contributor
2+
// license agreements. See the NOTICE file distributed with
3+
// this work for additional information regarding copyright
4+
// ownership. Apache Software Foundation (ASF) licenses this file to you under
5+
// the Apache License, Version 2.0 (the "License"); you may
6+
// not use this file except in compliance with the License.
7+
// You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package menu
19+
20+
import (
21+
"github.com/apache/skywalking-cli/assets"
22+
"github.com/apache/skywalking-cli/pkg/graphql/client"
23+
24+
"github.com/machinebox/graphql"
25+
26+
"github.com/urfave/cli/v2"
27+
28+
api "skywalking.apache.org/repo/goapi/query"
29+
)
30+
31+
func GetItems(ctx *cli.Context) ([]*api.MenuItem, error) {
32+
var response map[string][]*api.MenuItem
33+
34+
request := graphql.NewRequest(assets.Read("graphqls/menu/GetItems.graphql"))
35+
36+
err := client.ExecuteQuery(ctx, request, &response)
37+
return response["result"], err
38+
}

0 commit comments

Comments
 (0)