Skip to content

Commit

Permalink
Added UI command
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Kosiewski <[email protected]>
  • Loading branch information
Thomas Kosiewski committed Sep 22, 2023
1 parent a54e5cf commit d7a9612
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 17 deletions.
6 changes: 6 additions & 0 deletions cmd/vclusterctl/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ func BuildRoot(log log.Logger) (*cobra.Command, error) {
}
rootCmd.AddCommand(logoutCmd)

uiCmd, err := NewUICmd(globalFlags)
if err != nil {
return nil, fmt.Errorf("failed to create ui command: %w", err)
}
rootCmd.AddCommand(uiCmd)

// add completion command
err = rootCmd.RegisterFlagCompletionFunc("namespace", newNamespaceCompletionFunc(rootCmd.Context()))
if err != nil {
Expand Down
55 changes: 55 additions & 0 deletions cmd/vclusterctl/cmd/ui.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package cmd

import (
"errors"
"fmt"

loftctl "github.com/loft-sh/loftctl/v3/cmd/loftctl/cmd"
"github.com/loft-sh/log"
"github.com/loft-sh/vcluster/cmd/vclusterctl/flags"
"github.com/loft-sh/vcluster/pkg/pro"
"github.com/spf13/cobra"
)

func NewUICmd(globalFlags *flags.GlobalFlags) (*cobra.Command, error) {
loftctlGlobalFlags, err := pro.GlobalFlags(globalFlags)
if err != nil {
return nil, fmt.Errorf("failed to parse pro flags: %w", err)
}

cmd := &loftctl.UiCmd{
GlobalFlags: loftctlGlobalFlags,
Log: log.GetInstance(),
}

description := `########################################################
##################### vcluster ui ######################
########################################################
Open the vCluster.Pro web UI
Example:
vcluster ui
########################################################
`

uiCmd := &cobra.Command{
Use: "ui",
Short: "Start the web UI",
Long: description,
Args: cobra.NoArgs,
RunE: func(cobraCmd *cobra.Command, args []string) error {
err := cmd.Run(cobraCmd.Context(), args)
if err != nil {
if errors.Is(err, loftctl.ErrNoUrl) {
return fmt.Errorf("%w: please login first using 'vcluster login' or start using 'vcluster pro start'", err)
}

return fmt.Errorf("failed to run ui command: %w", err)
}

return nil
},
}

return uiCmd, nil
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/hashicorp/golang-lru/v2 v2.0.2
github.com/kubernetes-csi/external-snapshotter/client/v4 v4.2.0
github.com/loft-sh/api/v3 v3.0.0-20230922094800-6d0c1cbf0fa6
github.com/loft-sh/loftctl/v3 v3.0.0-20230922094952-2a6aef29f31e
github.com/loft-sh/loftctl/v3 v3.0.0-20230922112452-20febcea05a7
github.com/loft-sh/utils v0.0.25
github.com/mitchellh/go-homedir v1.1.0
github.com/moby/term v0.5.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,8 @@ github.com/loft-sh/loftctl/v3 v3.0.0-20230921143437-669b265e3ecf h1:SwIal5P1coM0
github.com/loft-sh/loftctl/v3 v3.0.0-20230921143437-669b265e3ecf/go.mod h1:I+dMG4zKZWOn+CcteN0cyPGOclHlqqmXBC6THcUwj60=
github.com/loft-sh/loftctl/v3 v3.0.0-20230922094952-2a6aef29f31e h1:OhQRp9uH7U14lYg8yOrnOiVhhxxC9tFdwWSyxoSUJ/I=
github.com/loft-sh/loftctl/v3 v3.0.0-20230922094952-2a6aef29f31e/go.mod h1:g2HZHmpkqtiQGqM8QVRuaCgNDI6IMW6DZQP0cOUgxp8=
github.com/loft-sh/loftctl/v3 v3.0.0-20230922112452-20febcea05a7 h1:lsBF4llFeHcDvYj2TCFVNsdYAPemIXXg7v0w2A6txPw=
github.com/loft-sh/loftctl/v3 v3.0.0-20230922112452-20febcea05a7/go.mod h1:g2HZHmpkqtiQGqM8QVRuaCgNDI6IMW6DZQP0cOUgxp8=
github.com/loft-sh/log v0.0.0-20230824104949-bd516c25712a h1:/gqqjKpcHEdFXIX41lx1Y/FBqT/72gbPpf7sa20tyM8=
github.com/loft-sh/log v0.0.0-20230824104949-bd516c25712a/go.mod h1:YImeRjXH34Yf5E79T7UHBQpDZl9fIaaFRgyZ/bkY+UQ=
github.com/loft-sh/utils v0.0.25 h1:JbbRJfXO1Rd34fQcaoDSmwyPBEzsrLwBSR21C90hHuk=
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 76 additions & 0 deletions vendor/github.com/loft-sh/loftctl/v3/cmd/loftctl/cmd/ui.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ github.com/loft-sh/external-types/loft-sh/admin-services/pkg/server
# github.com/loft-sh/jspolicy v0.1.0
## explicit; go 1.16
github.com/loft-sh/jspolicy/pkg/apis/policy/v1beta1
# github.com/loft-sh/loftctl/v3 v3.0.0-20230922094952-2a6aef29f31e
# github.com/loft-sh/loftctl/v3 v3.0.0-20230922112452-20febcea05a7
## explicit; go 1.21.1
github.com/loft-sh/loftctl/v3/cmd/loftctl/cmd
github.com/loft-sh/loftctl/v3/cmd/loftctl/cmd/connect
Expand Down

0 comments on commit d7a9612

Please sign in to comment.