File tree Expand file tree Collapse file tree 3 files changed +59
-0
lines changed
Expand file tree Collapse file tree 3 files changed +59
-0
lines changed Original file line number Diff line number Diff line change 1+ package resource
2+
3+ import (
4+ "fmt"
5+
6+ "github.com/major-technology/cli/singletons"
7+ "github.com/major-technology/cli/utils"
8+ "github.com/spf13/cobra"
9+ )
10+
11+ // createCmd represents the resource create command
12+ var createCmd = & cobra.Command {
13+ Use : "create" ,
14+ Short : "Open the resource creation page in your browser" ,
15+ Long : `Open the resource creation page in your default browser.` ,
16+ Run : func (cmd * cobra.Command , args []string ) {
17+ cobra .CheckErr (runCreate (cmd ))
18+ },
19+ }
20+
21+ func runCreate (cmd * cobra.Command ) error {
22+ // Get config to access frontend URI
23+ cfg := singletons .GetConfig ()
24+ if cfg == nil {
25+ return fmt .Errorf ("configuration not initialized" )
26+ }
27+
28+ // Construct the resource creation URL
29+ resourceURL := fmt .Sprintf ("%s/resources?action=add" , cfg .FrontendURI )
30+
31+ // Open the URL in the browser
32+ if err := utils .OpenBrowser (resourceURL ); err != nil {
33+ // If browser fails to open, still show the URL
34+ cmd .Printf ("Failed to open browser automatically. Please visit:\n %s\n " , resourceURL )
35+ return nil
36+ }
37+
38+ cmd .Printf ("Opening resource creation page in your browser:\n %s\n " , resourceURL )
39+ return nil
40+ }
Original file line number Diff line number Diff line change 1+ package resource
2+
3+ import (
4+ "github.com/spf13/cobra"
5+ )
6+
7+ // Cmd represents the resource command
8+ var Cmd = & cobra.Command {
9+ Use : "resource" ,
10+ Short : "Resource management commands" ,
11+ Long : `Commands for creating and managing resources.` ,
12+ }
13+
14+ func init () {
15+ // Add resource subcommands
16+ Cmd .AddCommand (createCmd )
17+ }
Original file line number Diff line number Diff line change 77 "github.com/major-technology/cli/clients/config"
88 "github.com/major-technology/cli/cmd/app"
99 "github.com/major-technology/cli/cmd/org"
10+ "github.com/major-technology/cli/cmd/resource"
1011 "github.com/major-technology/cli/cmd/user"
1112 "github.com/major-technology/cli/singletons"
1213 "github.com/spf13/cobra"
@@ -44,6 +45,7 @@ func init() {
4445 rootCmd .AddCommand (user .Cmd )
4546 rootCmd .AddCommand (org .Cmd )
4647 rootCmd .AddCommand (app .Cmd )
48+ rootCmd .AddCommand (resource .Cmd )
4749}
4850
4951func initConfig () {
You can’t perform that action at this time.
0 commit comments