Skip to content

Commit 997c9ee

Browse files
ceritiumclaude
andcommitted
Add open command to open tech stack in default browser
Add a new 'stacktodate open' command that opens the project's tech stack page on StackToDate in the user's default web browser. Features: - Reads project UUID from stacktodate.yml - Opens https://stacktodate.club/tech_stacks/{uuid} in default browser - Cross-platform support: macOS (open), Windows (start), Linux (xdg-open) - Respects STD_API_URL environment variable for custom API endpoints - Works with --config flag to specify custom config file path Usage: stacktodate open stacktodate open --config /path/to/stacktodate.yml This provides a quick way to view project details on the StackToDate website without needing to copy-paste the UUID or remember the URL format. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Haiku 4.5 <[email protected]>
1 parent 8409842 commit 997c9ee

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

cmd/open.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"os/exec"
6+
"runtime"
7+
8+
"github.com/stacktodate/stacktodate-cli/cmd/helpers"
9+
"github.com/stacktodate/stacktodate-cli/cmd/lib/cache"
10+
"github.com/spf13/cobra"
11+
)
12+
13+
var openCmd = &cobra.Command{
14+
Use: "open",
15+
Short: "Open the tech stack in your browser",
16+
Long: `Open the project's tech stack page on StackToDate in your default web browser`,
17+
Run: func(cmd *cobra.Command, args []string) {
18+
// Load config to get UUID
19+
config, err := helpers.LoadConfigWithDefaults(configFile, true)
20+
if err != nil {
21+
helpers.ExitOnError(err, "failed to load config")
22+
}
23+
24+
// Get API URL
25+
apiURL := cache.GetAPIURL()
26+
27+
// Build the tech stack URL
28+
url := fmt.Sprintf("%s/tech_stacks/%s", apiURL, config.UUID)
29+
30+
// Open in default browser
31+
if err := openBrowser(url); err != nil {
32+
helpers.ExitOnError(err, "failed to open browser")
33+
}
34+
35+
fmt.Printf("✓ Opening %s in your browser\n", url)
36+
},
37+
}
38+
39+
// openBrowser opens a URL in the default browser for the current operating system
40+
func openBrowser(url string) error {
41+
var cmd *exec.Cmd
42+
43+
switch runtime.GOOS {
44+
case "darwin":
45+
// macOS
46+
cmd = exec.Command("open", url)
47+
case "windows":
48+
// Windows
49+
cmd = exec.Command("cmd", "/c", "start", url)
50+
case "linux":
51+
// Linux - try xdg-open first, then fall back to others
52+
cmd = exec.Command("xdg-open", url)
53+
default:
54+
return fmt.Errorf("unsupported operating system: %s", runtime.GOOS)
55+
}
56+
57+
return cmd.Run()
58+
}
59+
60+
func init() {
61+
rootCmd.AddCommand(openCmd)
62+
openCmd.Flags().StringVarP(&configFile, "config", "c", "", "Path to stacktodate.yml config file (default: stacktodate.yml)")
63+
}

0 commit comments

Comments
 (0)