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
40 changes: 40 additions & 0 deletions cmd/resource/create.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package resource

import (
"fmt"

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

// createCmd represents the resource create command
var createCmd = &cobra.Command{
Use: "create",
Short: "Open the resource creation page in your browser",
Long: `Open the resource creation page in your default browser.`,
Run: func(cmd *cobra.Command, args []string) {
cobra.CheckErr(runCreate(cmd))
},
}

func runCreate(cmd *cobra.Command) error {
// Get config to access frontend URI
cfg := singletons.GetConfig()
if cfg == nil {
return fmt.Errorf("configuration not initialized")
}

// Construct the resource creation URL
resourceURL := fmt.Sprintf("%s/resources?action=add", cfg.FrontendURI)

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

cmd.Printf("Opening resource creation page in your browser:\n%s\n", resourceURL)
return nil
}
17 changes: 17 additions & 0 deletions cmd/resource/resource.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package resource

import (
"github.com/spf13/cobra"
)

// Cmd represents the resource command
var Cmd = &cobra.Command{
Use: "resource",
Short: "Resource management commands",
Long: `Commands for creating and managing resources.`,
}

func init() {
// Add resource subcommands
Cmd.AddCommand(createCmd)
}
2 changes: 2 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/major-technology/cli/clients/config"
"github.com/major-technology/cli/cmd/app"
"github.com/major-technology/cli/cmd/org"
"github.com/major-technology/cli/cmd/resource"
"github.com/major-technology/cli/cmd/user"
"github.com/major-technology/cli/singletons"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -44,6 +45,7 @@ func init() {
rootCmd.AddCommand(user.Cmd)
rootCmd.AddCommand(org.Cmd)
rootCmd.AddCommand(app.Cmd)
rootCmd.AddCommand(resource.Cmd)
}

func initConfig() {
Expand Down