Skip to content

Commit

Permalink
added a dashboard cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
h4ck3rk3y committed Jul 16, 2024
1 parent 7d3776e commit f117c08
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
20 changes: 20 additions & 0 deletions kardinal-cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@ package cmd
import (
"context"
"fmt"
"kardinal.cli/consts"
"kardinal.cli/multi_os_cmd_executor"
"log"
"net/http"
"os"
"path"
"strings"

"github.com/kurtosis-tech/stacktrace"
Expand Down Expand Up @@ -154,10 +157,27 @@ var removeManagerCmd = &cobra.Command{
},
}

var dashboardCmd = &cobra.Command{
Use: "dashboard",
Short: "Open your Kardinal Dashboard",
Args: cobra.ExactArgs(0),
Run: func(cmr *cobra.Command, args []string) {
tenantUuid, err := tenant.GetOrCreateUserTenantUUID()
if err != nil {
log.Fatal("Error getting or creating user tenant UUID", err)
}
tenantUuidStr := tenantUuid.String()
if err := multi_os_cmd_executor.OpenFile(path.Join(consts.KardinalDevURL, tenantUuidStr)); err != nil {
log.Fatal("Error occurred opening the dashboard", err)
}
},
}

func init() {
rootCmd.AddCommand(flowCmd)
rootCmd.AddCommand(managerCmd)
rootCmd.AddCommand(deployCmd)
rootCmd.AddCommand(dashboardCmd)
flowCmd.AddCommand(createCmd, deleteCmd)
managerCmd.AddCommand(deployManagerCmd, removeManagerCmd)

Expand Down
1 change: 1 addition & 0 deletions kardinal-cli/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ package consts
const (
KardinalAppIDLabelKey = "dev.kardinal.app-id"
KardinalManagerAppIDLabelValue = "kardinal-manager"
KardinalDevURL = "https://app.kardinal.dev"
)
38 changes: 38 additions & 0 deletions kardinal-cli/multi_os_cmd_executor/multi_os_cmd_executor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package multi_os_cmd_executor

import (
"github.com/kurtosis-tech/stacktrace"
"os/exec"
"runtime"
)

const (
linuxOSName = "linux"
macOSName = "darwin"
windowsOSName = "windows"

openFileLinuxCommandName = "xdg-open"
openFileMacCommandName = "open"
openFileWindowsCommandName = "rundll32"

openFileWindowsCommandFirstArgumentDefault = "url.dll,FileProtocolHandler"
)

func OpenFile(filepathOrURL string) error {
var args []string
switch runtime.GOOS {
case linuxOSName:
args = []string{openFileLinuxCommandName, filepathOrURL}
case macOSName:
args = []string{openFileMacCommandName, filepathOrURL}
case windowsOSName:
args = []string{openFileWindowsCommandName, openFileWindowsCommandFirstArgumentDefault, filepathOrURL}
default:
return stacktrace.NewError("Unsupported operating system")
}
command := exec.Command(args[0], args[1:]...)
if err := command.Start(); err != nil {
return stacktrace.Propagate(err, "An error occurred while opening '%v'", filepathOrURL)
}
return nil
}

0 comments on commit f117c08

Please sign in to comment.