From 82df58e4c29ee8aadcad06df5ab98ab7efcf7d50 Mon Sep 17 00:00:00 2001 From: ysicing Date: Mon, 8 May 2023 23:05:22 +0800 Subject: [PATCH] feat(debug): add debug add debug Signed-off-by: ysicing --- cmd/debug.go | 26 ++++++++++++++++++++++++++ cmd/debug/debug.go | 29 +++++++++++++++++++++++++++++ cmd/root.go | 5 +++-- docs/tiga.md | 5 +++-- docs/tiga_debug.md | 28 ++++++++++++++++++++++++++++ docs/tiga_debug_hostinfo.md | 27 +++++++++++++++++++++++++++ docs/tiga_plugin.md | 4 ++-- docs/tiga_plugin_list.md | 2 +- docs/tiga_upgrade.md | 4 ++-- docs/tiga_version.md | 4 ++-- go.mod | 2 +- internal/pkg/hostinfo/hostinfo.go | 22 ++++++++++++++++++++++ 12 files changed, 146 insertions(+), 12 deletions(-) create mode 100644 cmd/debug.go create mode 100644 cmd/debug/debug.go create mode 100644 docs/tiga_debug.md create mode 100644 docs/tiga_debug_hostinfo.md create mode 100644 internal/pkg/hostinfo/hostinfo.go diff --git a/cmd/debug.go b/cmd/debug.go new file mode 100644 index 0000000..0ed25a5 --- /dev/null +++ b/cmd/debug.go @@ -0,0 +1,26 @@ +// Copyright (c) 2023 ysicing(ysicing.me, ysicing@ysicing.cloud) All rights reserved. +// Use of this source code is covered by the following dual licenses: +// (1) Y PUBLIC LICENSE 1.0 (YPL 1.0) +// (2) Affero General Public License 3.0 (AGPL 3.0) +// License that can be found in the LICENSE file. + +package cmd + +import ( + "fmt" + "os" + + "github.com/spf13/cobra" + "github.com/ysicing/tiga/cmd/debug" + "github.com/ysicing/tiga/pkg/factory" +) + +func newCmdDebug(f factory.Factory) *cobra.Command { + debugCmd := &cobra.Command{ + Use: "debug", + Short: "debug, not a stable interface, contains misc debug facilities", + Long: fmt.Sprintf("\"%s debug\" contains misc debug facilities; it is not a stable interface.", os.Args[0]), + } + debugCmd.AddCommand(debug.HostInfoCommand(f)) + return debugCmd +} diff --git a/cmd/debug/debug.go b/cmd/debug/debug.go new file mode 100644 index 0000000..5cf6f4c --- /dev/null +++ b/cmd/debug/debug.go @@ -0,0 +1,29 @@ +// Copyright (c) 2023 ysicing(ysicing.me, ysicing@ysicing.cloud) All rights reserved. +// Use of this source code is covered by the following dual licenses: +// (1) Y PUBLIC LICENSE 1.0 (YPL 1.0) +// (2) Affero General Public License 3.0 (AGPL 3.0) +// License that can be found in the LICENSE file. + +package debug + +import ( + "encoding/json" + "os" + + "github.com/spf13/cobra" + "github.com/ysicing/tiga/internal/pkg/hostinfo" + "github.com/ysicing/tiga/pkg/factory" +) + +func HostInfoCommand(f factory.Factory) *cobra.Command { + return &cobra.Command{ + Use: "hostinfo", + Short: "print hostinfo", + RunE: func(cmd *cobra.Command, args []string) error { + hi := hostinfo.New() + j, _ := json.MarshalIndent(hi, "", " ") + os.Stdout.Write(j) + return nil + }, + } +} diff --git a/cmd/root.go b/cmd/root.go index f020b6d..0d0a59f 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -43,8 +43,8 @@ func Execute() { } if !strings.Contains(err.Error(), "unknown command") { f.GetLog().Info("----------------------------") - bugmsg := "found bug: submit the error message to Github \n\t Github: https://github.com/ysicing/tiga" - f.GetLog().Info(bugmsg) + bugMsg := "found bug: submit the error message to Github \n\t Github: https://github.com/ysicing/tiga" + f.GetLog().Info(bugMsg) } } } @@ -58,6 +58,7 @@ func BuildRoot(f factory.Factory) *cobra.Command { rootCmd.AddCommand(newCmdVersion(f)) rootCmd.AddCommand(newCmdUpgrade(f)) rootCmd.AddCommand(NewCmdPlugin()) + rootCmd.AddCommand(newCmdDebug(f)) rootCmd.AddCommand(newManCmd()) diff --git a/docs/tiga.md b/docs/tiga.md index f9cf5eb..66addb0 100644 --- a/docs/tiga.md +++ b/docs/tiga.md @@ -1,6 +1,6 @@ ## tiga -tiga is a cli tool for sernior restart engineer +tiga is a cli tool for senior restart engineer ### Options @@ -13,8 +13,9 @@ tiga is a cli tool for sernior restart engineer ### SEE ALSO +* [tiga debug](tiga_debug.md) - debug, not a stable interface, contains misc debug facilities * [tiga plugin](tiga_plugin.md) - provides utilities for interacting with plugins * [tiga upgrade](tiga_upgrade.md) - Upgrade tiga to the latest version * [tiga version](tiga_version.md) - Show version -###### Auto generated by spf13/cobra on 7-May-2023 +###### Auto generated by spf13/cobra on 8-May-2023 diff --git a/docs/tiga_debug.md b/docs/tiga_debug.md new file mode 100644 index 0000000..b345c94 --- /dev/null +++ b/docs/tiga_debug.md @@ -0,0 +1,28 @@ +## tiga debug + +debug, not a stable interface, contains misc debug facilities + +### Synopsis + +"/var/folders/59/glr2j03s3ws0bhb_v3zxt5lr0000gn/T/go-build3580675129/b001/exe/docs debug" contains misc debug facilities; it is not a stable interface. + +### Options + +``` + -h, --help help for debug +``` + +### Options inherited from parent commands + +``` + --config string The tiga config file to use (default "/Users/ysicing/.config/tiga/config/default.yaml") + --debug Prints the stack trace if an error occurs + --silent Run in silent mode and prevents any tiga log output except panics & fatals +``` + +### SEE ALSO + +* [tiga](tiga.md) - tiga is a cli tool for senior restart engineer +* [tiga debug hostinfo](tiga_debug_hostinfo.md) - print hostinfo + +###### Auto generated by spf13/cobra on 8-May-2023 diff --git a/docs/tiga_debug_hostinfo.md b/docs/tiga_debug_hostinfo.md new file mode 100644 index 0000000..435b11a --- /dev/null +++ b/docs/tiga_debug_hostinfo.md @@ -0,0 +1,27 @@ +## tiga debug hostinfo + +print hostinfo + +``` +tiga debug hostinfo [flags] +``` + +### Options + +``` + -h, --help help for hostinfo +``` + +### Options inherited from parent commands + +``` + --config string The tiga config file to use (default "/Users/ysicing/.config/tiga/config/default.yaml") + --debug Prints the stack trace if an error occurs + --silent Run in silent mode and prevents any tiga log output except panics & fatals +``` + +### SEE ALSO + +* [tiga debug](tiga_debug.md) - debug, not a stable interface, contains misc debug facilities + +###### Auto generated by spf13/cobra on 8-May-2023 diff --git a/docs/tiga_plugin.md b/docs/tiga_plugin.md index 820becd..2c57cb0 100644 --- a/docs/tiga_plugin.md +++ b/docs/tiga_plugin.md @@ -18,7 +18,7 @@ provides utilities for interacting with plugins ### SEE ALSO -* [tiga](tiga.md) - tiga is a cli tool for sernior restart engineer +* [tiga](tiga.md) - tiga is a cli tool for senior restart engineer * [tiga plugin list](tiga_plugin_list.md) - list all visible plugins executable by tiga on your PATH -###### Auto generated by spf13/cobra on 7-May-2023 +###### Auto generated by spf13/cobra on 8-May-2023 diff --git a/docs/tiga_plugin_list.md b/docs/tiga_plugin_list.md index 14951cf..2abe430 100644 --- a/docs/tiga_plugin_list.md +++ b/docs/tiga_plugin_list.md @@ -32,4 +32,4 @@ tiga plugin list [flags] * [tiga plugin](tiga_plugin.md) - provides utilities for interacting with plugins -###### Auto generated by spf13/cobra on 7-May-2023 +###### Auto generated by spf13/cobra on 8-May-2023 diff --git a/docs/tiga_upgrade.md b/docs/tiga_upgrade.md index 85365bd..36d25cf 100644 --- a/docs/tiga_upgrade.md +++ b/docs/tiga_upgrade.md @@ -22,6 +22,6 @@ tiga upgrade [flags] ### SEE ALSO -* [tiga](tiga.md) - tiga is a cli tool for sernior restart engineer +* [tiga](tiga.md) - tiga is a cli tool for senior restart engineer -###### Auto generated by spf13/cobra on 7-May-2023 +###### Auto generated by spf13/cobra on 8-May-2023 diff --git a/docs/tiga_version.md b/docs/tiga_version.md index c158e43..d7fe88e 100644 --- a/docs/tiga_version.md +++ b/docs/tiga_version.md @@ -22,6 +22,6 @@ tiga version [flags] ### SEE ALSO -* [tiga](tiga.md) - tiga is a cli tool for sernior restart engineer +* [tiga](tiga.md) - tiga is a cli tool for senior restart engineer -###### Auto generated by spf13/cobra on 7-May-2023 +###### Auto generated by spf13/cobra on 8-May-2023 diff --git a/go.mod b/go.mod index bbf7358..4406cfb 100644 --- a/go.mod +++ b/go.mod @@ -23,6 +23,7 @@ require ( gopkg.in/natefinch/lumberjack.v2 v2.2.1 k8s.io/apimachinery v0.27.1 k8s.io/kubectl v0.27.1 + tailscale.com v1.40.0 ) require ( @@ -111,5 +112,4 @@ require ( sigs.k8s.io/kustomize/kyaml v0.14.1 // indirect sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect sigs.k8s.io/yaml v1.3.0 // indirect - tailscale.com v1.40.0 // indirect ) diff --git a/internal/pkg/hostinfo/hostinfo.go b/internal/pkg/hostinfo/hostinfo.go new file mode 100644 index 0000000..fd17481 --- /dev/null +++ b/internal/pkg/hostinfo/hostinfo.go @@ -0,0 +1,22 @@ +// Copyright (c) 2023 ysicing(ysicing.me, ysicing@ysicing.cloud) All rights reserved. +// Use of this source code is covered by the following dual licenses: +// (1) Y PUBLIC LICENSE 1.0 (YPL 1.0) +// (2) Affero General Public License 3.0 (AGPL 3.0) +// License that can be found in the LICENSE file. + +package hostinfo + +import ( + "fmt" + + "github.com/ysicing/tiga/common" + hinfo "tailscale.com/hostinfo" + "tailscale.com/tailcfg" +) + +// New returns a partially populated Hostinfo for the current host. +func New() *tailcfg.Hostinfo { + t := hinfo.New() + t.IPNVersion = fmt.Sprintf("%s-%s", common.Version, common.GitCommitHash) + return t +}