Trim license headers in query string (#160)
diff --git a/assets/assets.go b/assets/assets.go
index 5265f03..29352f4 100644
--- a/assets/assets.go
+++ b/assets/assets.go
@@ -19,6 +19,7 @@
import (
"embed"
+ "strings"
"github.com/apache/skywalking-cli/internal/logger"
)
@@ -26,11 +27,22 @@
//go:embed *
var assets embed.FS
-// Read reads all content from a file under assets, which is packed in to the binary
+// Read reads all content from a file under assets, which is packed in to the binary.
+// It will also trim the consecutive lines starting with #.
func Read(filename string) string {
content, err := assets.ReadFile(filename)
if err != nil {
logger.Log.Fatalln("failed to read asset: ", filename, err)
}
- return string(content)
+ var lines []string
+ stop := false
+ for _, line := range strings.Split(string(content), "\n") {
+ if !stop && strings.HasPrefix(line, "#") {
+ continue
+ }
+ stop = true
+ lines = append(lines, line)
+ }
+
+ return strings.Join(lines, "\n")
}
diff --git a/assets/assets_test.go b/assets/assets_test.go
new file mode 100644
index 0000000..6b87025
--- /dev/null
+++ b/assets/assets_test.go
@@ -0,0 +1,65 @@
+// Licensed to Apache Software Foundation (ASF) under one or more contributor
+// license agreements. See the NOTICE file distributed with
+// this work for additional information regarding copyright
+// ownership. Apache Software Foundation (ASF) licenses this file to you under
+// the Apache License, Version 2.0 (the "License"); you may
+// not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+package assets
+
+import "testing"
+
+func TestRead(t *testing.T) {
+ type args struct {
+ filename string
+ }
+ tests := []struct {
+ name string
+ args args
+ want string
+ }{
+ {
+ name: "Trim license header",
+ args: args{
+ filename: "graphqls/dependency/EndpointDependency.graphql",
+ },
+ want: `
+query ($endpointId:ID!, $duration: Duration!) {
+ result: getEndpointDependencies(duration: $duration, endpointId: $endpointId) {
+ nodes {
+ id
+ name
+ serviceId
+ serviceName
+ type
+ isReal
+ }
+ calls {
+ id
+ source
+ target
+ detectPoints
+ }
+ }
+}
+`,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ if got := Read(tt.args.filename); got != tt.want {
+ t.Errorf("Read() = %v, want %v", got, tt.want)
+ }
+ })
+ }
+}
diff --git a/go.mod b/go.mod
index 89b1960..5267337 100644
--- a/go.mod
+++ b/go.mod
@@ -20,6 +20,7 @@
golang.org/x/net v0.0.0-20220421235706-1d1ef9303861 // indirect
golang.org/x/sys v0.0.0-20220422013727-9388b58f7150 // indirect
golang.org/x/term v0.0.0-20220411215600-e5f449aeb171 // indirect
+ golang.org/x/text v0.3.7
google.golang.org/grpc v1.40.0
gopkg.in/yaml.v2 v2.4.0
k8s.io/apimachinery v0.21.1
diff --git a/internal/commands/interceptor/duration.go b/internal/commands/interceptor/duration.go
index ea9f291..85ed591 100644
--- a/internal/commands/interceptor/duration.go
+++ b/internal/commands/interceptor/duration.go
@@ -83,11 +83,11 @@
// ParseDuration parses the `start` and `end` to a triplet, (startTime, endTime, step),
// based on the given `timezone`, however, if the given `timezone` is empty, UTC becomes the default timezone.
// if --start and --end are both absent,
-// then: start := now - 30min; end := now
+// then: start := now - 30min; end := now
// if --start is given, --end is absent,
-// then: end := now + 30 units, where unit is the precision of `start`, (hours, minutes, etc.)
+// then: end := now + 30 units, where unit is the precision of `start`, (hours, minutes, etc.)
// if --start is absent, --end is given,
-// then: start := end - 30 units, where unit is the precision of `end`, (hours, minutes, etc.)
+// then: start := end - 30 units, where unit is the precision of `end`, (hours, minutes, etc.)
func ParseDuration(start, end string, userStep api.Step) (startTime, endTime time.Time, step api.Step, dt utils.DurationType) {
logger.Log.Debugln("Start time:", start, "end time:", end, "timezone:", time.Local)
diff --git a/pkg/graphql/dashboard/global.go b/pkg/graphql/dashboard/global.go
index 13b1aad..cb3327f 100644
--- a/pkg/graphql/dashboard/global.go
+++ b/pkg/graphql/dashboard/global.go
@@ -23,6 +23,8 @@
"strings"
"sync"
+ "golang.org/x/text/cases"
+ "golang.org/x/text/language"
api "skywalking.apache.org/repo/goapi/query"
"github.com/spf13/viper"
@@ -134,7 +136,7 @@
for s := range c {
if s != "style" {
- ret = append(ret, strings.Title(s))
+ ret = append(ret, cases.Title(language.Und).String(s))
}
}
return ret, nil