You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2021/07/14 08:56:04 UTC
[skywalking-cli] branch master updated: Optimize output by adding
color to help information (#99)
This is an automated email from the ASF dual-hosted git repository.
wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking-cli.git
The following commit(s) were added to refs/heads/master by this push:
new 8898c9c Optimize output by adding color to help information (#99)
8898c9c is described below
commit 8898c9cd08304d63bb0831ff94ef17b234e05250
Author: Team317 <52...@users.noreply.github.com>
AuthorDate: Wed Jul 14 16:55:57 2021 +0800
Optimize output by adding color to help information (#99)
---
cmd/swctl/main.go | 4 ++
pkg/util/template.go | 103 +++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 107 insertions(+)
diff --git a/cmd/swctl/main.go b/cmd/swctl/main.go
index 679e62a..d430416 100644
--- a/cmd/swctl/main.go
+++ b/cmd/swctl/main.go
@@ -47,6 +47,10 @@ func init() {
}
func main() {
+ cli.AppHelpTemplate = util.AppHelpTemplate
+ cli.CommandHelpTemplate = util.CommandHelpTemplate
+ cli.SubcommandHelpTemplate = util.SubcommandHelpTemplate
+
app := cli.NewApp()
app.Usage = "The CLI (Command Line Interface) for Apache SkyWalking."
app.Version = version
diff --git a/pkg/util/template.go b/pkg/util/template.go
new file mode 100644
index 0000000..614a913
--- /dev/null
+++ b/pkg/util/template.go
@@ -0,0 +1,103 @@
+// 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 util
+
+// TextFormat defines variables of style and colors.
+const TextFormat = `
+{{- $bold :="\x1b[1m" -}}
+{{- $black :="\x1b[0;30m" -}} {{- $Black :="\x1b[1;30m" -}}
+{{- $red :="\x1b[0;31m" -}} {{- $Red :="\x1b[1;31m" -}}
+{{- $green :="\x1b[0;32m" -}} {{- $Green :="\x1b[1;32m" -}}
+{{- $yellow :="\x1b[0;33m" -}} {{- $Yellow :="\x1b[1;33m" -}}
+{{- $blue :="\x1b[0;34m" -}} {{- $Blue :="\x1b[1;34m" -}}
+{{- $pruple :="\x1b[0;35m" -}} {{- $Pruple :="\x1b[1;35m" -}}
+{{- $cyan :="\x1b[0;36m" -}} {{- $Cyan :="\x1b[1;36m" -}}
+{{- $white :="\x1b[0;37m" -}} {{- $White :="\x1b[1;37m" -}}
+{{- $plain :="\x1b[0m" -}}
+`
+
+const AppHelpTemplate = TextFormat + `{{$Green -}}
+NAME:
+ {{$green}}{{.Name}}{{if .Usage}} - {{.Usage}}{{end}}{{$Green}}
+
+USAGE:
+ {{$green}}{{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}}
+ {{- if .VisibleFlags}}[global options]{{end}}{{if .Commands}} command [command options]{{end}}
+ {{- if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{$Yellow}}{{if .Version}}{{if not .HideVersion}}
+
+VERSION:
+ {{$yellow}}{{.Version}}{{end}}{{end}}{{$Yellow}}{{if .Description}}
+
+DESCRIPTION:
+ {{$yellow}}{{.Description}}{{end}}{{$Yellow}}{{if len .Authors}}
+
+AUTHOR{{with $length := len .Authors}}{{if ne 1 $length}}S{{end}}{{end}}:
+ {{$yellow}}{{range $index, $author := .Authors}}{{if $index}}
+ {{end}}{{$author}}{{end}}{{end}}{{$Blue}}{{if .VisibleCommands}}
+
+COMMANDS:{{range .VisibleCategories}}{{if .Name}}
+
+ {{.Name}}:{{range .VisibleCommands}}
+ {{$Blue}}{{join .Names ", "}}{{"\t\t\t\t"}}{{$blue}}{{.Usage}}{{end}}{{else}}{{range .VisibleCommands}}
+ {{$Blue}}{{join .Names ", "}}{{"\t\t\t\t"}}{{$blue}}{{.Usage}}{{$plain}}{{end}}{{end}}{{end}}{{end}}{{if .VisibleFlags}}{{$Cyan}}
+
+GLOBAL OPTIONS:
+ {{range $index, $option := .VisibleFlags}}{{if $index}}
+ {{end}}{{$cyan}}{{$option}}{{$plain}}{{end}}{{end}}{{$Green}}{{if .Copyright}}
+
+COPYRIGHT:
+ {{$green}}{{.Copyright}}{{end}}{{$plain}}
+`
+
+const CommandHelpTemplate = TextFormat + `{{$Green -}}
+NAME:
+ {{$green}}{{.HelpName}} - {{.Usage}}{{$Green}}
+
+USAGE:
+ {{$green}}{{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}}{{if .VisibleFlags}} [command options]{{end}}
+ {{- if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{$Green}}{{if .Category}}
+
+CATEGORY:
+ {{$green}}{{.Category}}{{end}}{{$Blue}}{{if .Description}}
+
+DESCRIPTION:
+ {{$blue}}{{.Description}}{{end}}{{$Cyan}}{{if .VisibleFlags}}
+
+OPTIONS:
+ {{$cyan}}{{range .VisibleFlags}}{{.}}
+ {{end}}{{end}}{{$plain}}
+`
+
+const SubcommandHelpTemplate = TextFormat + `{{$Green -}}
+NAME:
+ {{$green}}{{.HelpName}} - {{if .Description}}{{.Description}}{{else}}{{.Usage}}{{end}}{{$Green}}
+
+USAGE:
+ {{$green}}{{if .UsageText}}{{.UsageText}}{{else}}{{.HelpName}} command{{if .VisibleFlags}} [command options]{{end}}
+ {{- if .ArgsUsage}}{{.ArgsUsage}}{{else}}[arguments...]{{end}}{{end}}{{$Blue}}
+
+COMMANDS:{{range .VisibleCategories}}{{if .Name}}
+
+ {{.Name}}:{{range .VisibleCommands}}
+ {{$Blue}}{{join .Names ", "}}{{$blue}}{{"\t"}}{{.Usage}}{{end}}{{else}}{{range .VisibleCommands}}
+ {{$Blue}}{{join .Names ", "}}{{$blue}}{{"\t"}}{{.Usage}}{{end}}{{end}}{{end}}{{if .VisibleFlags}}{{$Cyan}}
+
+OPTIONS:
+ {{$cyan}}{{range .VisibleFlags}}{{.}}
+ {{end}}{{end}}{{$plain}}
+`