Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: 🎸 add docs command #839

Merged
merged 3 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cmd/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func (ac *AddCommand) Init() {
ac.command.Flags().String("context-name", "", "override context name when add kubeconfig context")
ac.command.PersistentFlags().BoolP("cover", "c", false, "Overwrite local kubeconfig files")
_ = ac.command.MarkFlagRequired("file")
ac.AddCommands(&DocsCommand{})
}

func (ac *AddCommand) runAdd(cmd *cobra.Command, args []string) error {
Expand Down
1 change: 1 addition & 0 deletions cmd/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func (al *AliasCommand) Init() {
al.command.DisableFlagsInUseLine = true
al.command.Flags().StringP("out", "o", "", "output to ~/.zshrc or ~/.bash_profile")
_ = al.command.MarkFlagRequired("out")
al.AddCommands(&DocsCommand{})
}

// SourceCmd source command
Expand Down
1 change: 1 addition & 0 deletions cmd/clear.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func (cl *ClearCommand) Init() {
Example: clearExample(),
}
cl.command.DisableFlagsInUseLine = true
cl.AddCommands(&DocsCommand{})
}

func (cl *ClearCommand) runClear(cmd *cobra.Command, args []string) error {
Expand Down
1 change: 1 addition & 0 deletions cmd/cloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func (cc *CloudCommand) Init() {
cc.command.PersistentFlags().String("region_id", "", "cloud region id")
cc.AddCommands(&CloudAddCommand{})
cc.AddCommands(&CloudListCommand{})
cc.AddCommands(&DocsCommand{})
}

func getClusters(provider, regionID string, num int) ([]cloud.ClusterInfo, error) {
Expand Down
1 change: 1 addition & 0 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ func NewBaseCommand() *BaseCommand {
&CreateCommand{}, // create command
&CloudCommand{}, // cloud command
&ExportCommand{}, // export command
&DocsCommand{}, // docs command
)

return baseCmd
Expand Down
2 changes: 1 addition & 1 deletion cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func (dc *DeleteCommand) Init() {
},
Example: deleteExample(),
}

dc.AddCommands(&DocsCommand{})
}

func (dc *DeleteCommand) runDelete(command *cobra.Command, args []string) error {
Expand Down
46 changes: 46 additions & 0 deletions cmd/docs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package cmd

import (
"fmt"
"github.com/pkg/browser"
"github.com/spf13/cobra"
)

type DocsCommand struct {
BaseCommand
}

var DOCS = "https://kubecm.cloud/"

// Init DocsCommand
func (dc *DocsCommand) Init() {
dc.command = &cobra.Command{
Use: "docs",
Short: "Open document website",
Long: "Open document website in your browser",
RunE: func(cmd *cobra.Command, args []string) error {
return dc.runDocs(cmd, args)
},
Example: docsExample(),
}
}

func (dc *DocsCommand) runDocs(cmd *cobra.Command, args []string) error {
var url string
if cmd.Parent().Use == "kubecm" {
url = DOCS
} else {
url = fmt.Sprintf("%s#/en-us/cli/kubecm_%s", DOCS, cmd.Parent().Use)
}
fmt.Printf("Opened %s in your browser.\n", url)
return browser.OpenURL(url)
}

func docsExample() string {
return `
# Open kubecm website
kubecm docs
# Open add command document page
kubecm add docs
`
}
1 change: 1 addition & 0 deletions cmd/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func (ec *ExportCommand) Init() {
}
ec.command.Flags().StringP("file", "f", "", "Path to export kubeconfig files")
_ = ec.command.MarkFlagRequired("file")
ec.AddCommands(&DocsCommand{})
}

func (ec *ExportCommand) runExport(args []string) error {
Expand Down
1 change: 1 addition & 0 deletions cmd/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func (lc *ListCommand) Init() {
Example: listExample(),
}
lc.command.DisableFlagsInUseLine = true
lc.AddCommands(&DocsCommand{})
}

func (lc *ListCommand) runList(command *cobra.Command, args []string) error {
Expand Down
1 change: 1 addition & 0 deletions cmd/merge.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func (mc *MergeCommand) Init() {
mc.command.Flags().StringP("folder", "f", "", "KubeConfig folder")
mc.command.Flags().BoolP("assumeyes", "y", false, "skip interactive file overwrite confirmation")
//_ = mc.command.MarkFlagRequired("folder")
mc.AddCommands(&DocsCommand{})
}

func (mc MergeCommand) runMerge(command *cobra.Command, args []string) error {
Expand Down
1 change: 1 addition & 0 deletions cmd/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Switch or change namespace interactively
},
Example: namespaceExample(),
}
nc.AddCommands(&DocsCommand{})
}

func (nc *NamespaceCommand) runNamespace(command *cobra.Command, args []string) error {
Expand Down
1 change: 1 addition & 0 deletions cmd/rename.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func (rc *RenameCommand) Init() {
},
Example: renameExample(),
}
rc.AddCommands(&DocsCommand{})
}

func (rc *RenameCommand) runRename(command *cobra.Command, args []string) error {
Expand Down
1 change: 1 addition & 0 deletions cmd/switch.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ Switch Kube Context interactively
},
Example: switchExample(),
}
sc.AddCommands(&DocsCommand{})
}

func (sc *SwitchCommand) runSwitch(command *cobra.Command, args []string) error {
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ require (
github.com/Azure/azure-sdk-for-go v68.0.0+incompatible
github.com/Azure/go-autorest/autorest v0.11.24
github.com/Azure/go-autorest/autorest/azure/auth v0.5.12
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c
github.com/aws/aws-sdk-go v1.49.13
github.com/stretchr/testify v1.8.4
)
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,8 @@ github.com/paulmach/orb v0.1.3/go.mod h1:VFlX/8C+IQ1p6FTRRKzKoOPJnvEtA5G0Veuqwbu
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/peterbourgon/diskv v2.0.1+incompatible/go.mod h1:uqqh8zWWbv1HBMNONnaR/tNboyR3/BZd58JJSHlUSCU=
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmdv1U2eRNDiU2ErMBj1gwrq8eQ=
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
Expand Down Expand Up @@ -766,6 +768,7 @@ golang.org/x/sys v0.0.0-20211013075003-97ac67df715c/go.mod h1:oPkhp1MJrh7nUepCBc
golang.org/x/sys v0.0.0-20220319134239-a9b59b0215f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.9.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
Expand Down
Loading