Skip to content

Commit

Permalink
feat(debug): add debug
Browse files Browse the repository at this point in the history
add debug

Signed-off-by: ysicing <i@ysicing.me>
  • Loading branch information
ysicing committed May 8, 2023
1 parent 760f28c commit 82df58e
Show file tree
Hide file tree
Showing 12 changed files with 146 additions and 12 deletions.
26 changes: 26 additions & 0 deletions cmd/debug.go
Original file line number Diff line number Diff line change
@@ -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
}
29 changes: 29 additions & 0 deletions cmd/debug/debug.go
Original file line number Diff line number Diff line change
@@ -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
},
}
}
5 changes: 3 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand All @@ -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())

Expand Down
5 changes: 3 additions & 2 deletions docs/tiga.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## tiga

tiga is a cli tool for sernior restart engineer
tiga is a cli tool for senior restart engineer

### Options

Expand All @@ -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
28 changes: 28 additions & 0 deletions docs/tiga_debug.md
Original file line number Diff line number Diff line change
@@ -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
27 changes: 27 additions & 0 deletions docs/tiga_debug_hostinfo.md
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions docs/tiga_plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion docs/tiga_plugin_list.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions docs/tiga_upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions docs/tiga_version.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
)
22 changes: 22 additions & 0 deletions internal/pkg/hostinfo/hostinfo.go
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 82df58e

Please sign in to comment.