Skip to content
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/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ func init() {
Cmd.AddCommand(generateResourcesCmd)
Cmd.AddCommand(startCmd)
Cmd.AddCommand(deployCmd)
Cmd.AddCommand(editCmd)
}
46 changes: 46 additions & 0 deletions cmd/app/editor.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package app

import (
"fmt"

"github.com/major-technology/cli/singletons"
"github.com/major-technology/cli/utils"
"github.com/spf13/cobra"
)

// editCmd represents the editor command
var editCmd = &cobra.Command{
Use: "editor",
Short: "Open the application editor in your browser",
Long: `Open the application editor in your default browser for the current application.`,
Run: func(cmd *cobra.Command, args []string) {
cobra.CheckErr(runEdit(cmd))
},
}

func runEdit(cmd *cobra.Command) error {
// Get application ID
applicationID, err := getApplicationID()
if err != nil {
return err
}

// Get config to access frontend URI
cfg := singletons.GetConfig()
if cfg == nil {
return fmt.Errorf("configuration not initialized")
}

// Construct the editor URL
editorURL := fmt.Sprintf("%s/apps/%s/edit", cfg.FrontendURI, applicationID)

// Open the URL in the browser
if err := utils.OpenBrowser(editorURL); err != nil {
// If browser fails to open, still show the URL
cmd.Printf("Failed to open browser automatically. Please visit:\n%s\n", editorURL)
return nil
}

cmd.Printf("Opening application editor in your browser:\n%s\n", editorURL)
return nil
}
23 changes: 2 additions & 21 deletions cmd/user/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ package user

import (
"fmt"
"os/exec"
"runtime"
"time"

"github.com/charmbracelet/huh"
apiClient "github.com/major-technology/cli/clients/api"
mjrToken "github.com/major-technology/cli/clients/token"
"github.com/major-technology/cli/singletons"
"github.com/major-technology/cli/utils"
"github.com/spf13/cobra"
)

Expand All @@ -31,7 +30,7 @@ func runLogin(cobraCmd *cobra.Command) error {
return fmt.Errorf("failed to start login: %w", err)
}

if err := openBrowser(startResp.VerificationURI); err != nil {
if err := utils.OpenBrowser(startResp.VerificationURI); err != nil {
// ignore, failed to open browser
}
cobraCmd.Println("Attempting to automatically open the SSO authorization page in your default browser.")
Expand Down Expand Up @@ -71,24 +70,6 @@ func runLogin(cobraCmd *cobra.Command) error {
return nil
}

// openBrowser opens the specified URL in the default browser
func openBrowser(url string) error {
var execCmd *exec.Cmd

switch runtime.GOOS {
case "linux":
execCmd = exec.Command("xdg-open", url)
case "windows":
execCmd = exec.Command("rundll32", "url.dll,FileProtocolHandler", url)
case "darwin":
execCmd = exec.Command("open", url)
default:
return fmt.Errorf("unsupported platform")
}

return execCmd.Start()
}

// pollForToken polls POST /cli/login/poll until authenticated or timeout
func pollForToken(cobraCmd *cobra.Command, client *apiClient.Client, deviceCode string, interval int, expiresIn int) (string, error) {
ticker := time.NewTicker(time.Duration(interval) * time.Second)
Expand Down
2 changes: 1 addition & 1 deletion configs/local.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"api_url": "http://localhost:3001/cli",
"frontend_uri": "http://localhost:3000/device"
"frontend_uri": "http://localhost:3000"
}
2 changes: 1 addition & 1 deletion configs/prod.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"api_url": "https://api.prod.major.build/cli",
"frontend_uri": "https://app.major.build/device"
"frontend_uri": "https://app.major.build"
}
25 changes: 25 additions & 0 deletions utils/browser.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package utils

import (
"fmt"
"os/exec"
"runtime"
)

// OpenBrowser opens the specified URL in the default browser
func OpenBrowser(url string) error {
var execCmd *exec.Cmd

switch runtime.GOOS {
case "linux":
execCmd = exec.Command("xdg-open", url)
case "windows":
execCmd = exec.Command("rundll32", "url.dll,FileProtocolHandler", url)
case "darwin":
execCmd = exec.Command("open", url)
default:
return fmt.Errorf("unsupported platform")
}

return execCmd.Start()
}