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 2019/11/09 14:12:55 UTC

[skywalking-cli] 01/25: Initialization project

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

commit a289a59a2f3b62cbfe3e084f16081bec5b1a7090
Author: heyanlong <ya...@gmail.com>
AuthorDate: Wed Nov 6 12:05:58 2019 +0800

    Initialization project
---
 .gitignore               |  2 ++
 Makefile                 |  9 +++++++++
 README.md                |  6 ++++++
 cmd/main.go              | 32 ++++++++++++++++++++++++++++++++
 cmd/service.go           | 24 ++++++++++++++++++++++++
 go.mod                   |  9 +++++++++
 go.sum                   | 22 ++++++++++++++++++++++
 logger/log.go            | 20 ++++++++++++++++++++
 scripts/build            | 11 +++++++++++
 swctl/service/list.go    |  5 +++++
 swctl/service/service.go | 24 ++++++++++++++++++++++++
 11 files changed, 164 insertions(+)

diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..25c3120
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,2 @@
+.idea
+bin
\ No newline at end of file
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..aa368e7
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,9 @@
+# Example:
+#   make build
+#   make install
+
+.PHONY: build install
+
+build:
+	GO_BUILD_FLAGS="-v" ./scripts/build
+	./bin/swctl --version
\ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..eaf2c6a
--- /dev/null
+++ b/README.md
@@ -0,0 +1,6 @@
+Apache SkyWalking CLI
+===============
+
+<img src="http://skywalking.apache.org/assets/logo.svg" alt="Sky Walking logo" height="90px" align="right" />
+
+The CLI for [Apache SkyWalking](https://github.com/apache/skywalking).
\ No newline at end of file
diff --git a/cmd/main.go b/cmd/main.go
new file mode 100644
index 0000000..e4969db
--- /dev/null
+++ b/cmd/main.go
@@ -0,0 +1,32 @@
+package main
+
+import (
+	"os"
+
+	"github.com/sirupsen/logrus"
+	"github.com/urfave/cli"
+
+	"github.com/apache/skywalking-cli/logger"
+)
+
+var log *logrus.Logger
+
+func init() {
+	log = logger.Log
+}
+
+func main() {
+	app := cli.NewApp()
+	app.Flags = []cli.Flag{
+		cli.StringFlag{
+			Name:  "config, c",
+			Usage: "path of settings.yml config. Use the file in the same folder as default.",
+		},
+	}
+	app.Commands = []cli.Command{serviceCmd}
+
+	err := app.Run(os.Args)
+	if err != nil {
+		log.Fatal(err)
+	}
+}
diff --git a/cmd/service.go b/cmd/service.go
new file mode 100644
index 0000000..36c9e5e
--- /dev/null
+++ b/cmd/service.go
@@ -0,0 +1,24 @@
+package main
+
+import (
+	"github.com/apache/skywalking-cli/swctl/service"
+	"github.com/urfave/cli"
+)
+
+var serviceCmd = cli.Command{
+	Name: "service",
+	Flags: []cli.Flag{
+		cli.BoolFlag{
+			Name:  "list",
+			Usage: "list all available services.",
+		},
+	},
+	Action: func(c *cli.Context) {
+		ctl := service.NewService(c)
+
+		err := ctl.Exec()
+		if err != nil {
+			log.Fatal(err)
+		}
+	},
+}
diff --git a/go.mod b/go.mod
new file mode 100644
index 0000000..8d79e73
--- /dev/null
+++ b/go.mod
@@ -0,0 +1,9 @@
+module github.com/apache/skywalking-cli
+
+go 1.13
+
+require (
+	github.com/lytics/logrus v0.0.0-20170528191427-4389a17ed024 // indirect
+	github.com/sirupsen/logrus v1.4.2
+	github.com/urfave/cli v1.22.1
+)
diff --git a/go.sum b/go.sum
new file mode 100644
index 0000000..7860264
--- /dev/null
+++ b/go.sum
@@ -0,0 +1,22 @@
+github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
+github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
+github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
+github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
+github.com/lytics/logrus v0.0.0-20170528191427-4389a17ed024 h1:QaKVrqyQRNPbdBNCpiU0Ei3iDQko3qoiUUXMiTWhzZM=
+github.com/lytics/logrus v0.0.0-20170528191427-4389a17ed024/go.mod h1:SkQviJ2s7rFyzyuxdVp6osZceHOabU91ZhKsEXF0RWg=
+github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
+github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
+github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
+github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
+github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
+github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
+github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
+github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
+github.com/urfave/cli v1.22.1 h1:+mkCCcOFKPnCmVYVcURKps1Xe+3zP90gSYGNfRkjoIY=
+github.com/urfave/cli v1.22.1/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
+golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc=
+golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
+gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
diff --git a/logger/log.go b/logger/log.go
new file mode 100644
index 0000000..039bdec
--- /dev/null
+++ b/logger/log.go
@@ -0,0 +1,20 @@
+package logger
+
+import (
+	"os"
+
+	"github.com/sirupsen/logrus"
+)
+
+var Log *logrus.Logger
+
+func init() {
+	if Log == nil {
+		Log = logrus.New()
+	}
+	Log.SetOutput(os.Stdout)
+	Log.SetFormatter(&logrus.TextFormatter{
+		FullTimestamp:   true,
+		TimestampFormat: "2006-01-02 15:04:05",
+	})
+}
diff --git a/scripts/build b/scripts/build
new file mode 100755
index 0000000..a60a9cf
--- /dev/null
+++ b/scripts/build
@@ -0,0 +1,11 @@
+#!/usr/bin/env bash
+
+cli_build() {
+  out="bin"
+  CGO_ENABLED=0 go build $GO_BUILD_FLAGS \
+  -o "${out}/swctl" cmd/* || return
+}
+
+if echo "$0" | grep "build$" > /dev/null; then
+  cli_build
+fi
\ No newline at end of file
diff --git a/swctl/service/list.go b/swctl/service/list.go
new file mode 100644
index 0000000..73784f5
--- /dev/null
+++ b/swctl/service/list.go
@@ -0,0 +1,5 @@
+package service
+
+func (s *service) showList() error {
+	return nil
+}
diff --git a/swctl/service/service.go b/swctl/service/service.go
new file mode 100644
index 0000000..f67edf5
--- /dev/null
+++ b/swctl/service/service.go
@@ -0,0 +1,24 @@
+package service
+
+import (
+	"github.com/urfave/cli"
+)
+
+type service struct {
+	flag *cli.Context
+	list bool
+}
+
+func NewService(flag *cli.Context) *service {
+	return &service{
+		flag: flag,
+		list: flag.Bool("list"),
+	}
+}
+
+func (s *service) Exec() (err error) {
+	if s.list {
+		err = s.showList()
+	}
+	return
+}