this repo has no description smallweb.run
smallweb
4
fork

Configure Feed

Select the types of activity you want to include in your feed.

at main 65 lines 1.4 kB view raw
1package cmd 2 3import ( 4 "fmt" 5 "os" 6 "path" 7 "path/filepath" 8 "strings" 9 10 "github.com/cli/browser" 11 "github.com/pomdtr/smallweb/internal/app" 12 "github.com/spf13/cobra" 13) 14 15func NewCmdOpen() *cobra.Command { 16 var flags struct { 17 app string 18 } 19 20 cmd := &cobra.Command{ 21 Use: "open [app]", 22 Short: "Open an app in the browser", 23 Args: cobra.NoArgs, 24 RunE: func(cmd *cobra.Command, args []string) error { 25 appName := flags.app 26 if flags.app == "" { 27 cwd, err := os.Getwd() 28 if err != nil { 29 return fmt.Errorf("could not get current working directory: %v", err) 30 } 31 32 if cwd == path.Clean(k.String("dir")) { 33 return fmt.Errorf("not in an app directory") 34 } 35 36 if !strings.HasPrefix(cwd, k.String("dir")) { 37 return fmt.Errorf("not in an app directory") 38 } 39 40 appDir := cwd 41 for filepath.Dir(appDir) != k.String("dir") { 42 appDir = filepath.Dir(appDir) 43 } 44 45 appName = filepath.Base(appDir) 46 } 47 48 a, err := app.LoadApp(appName, k.String("dir"), k.String("domain")) 49 if err != nil { 50 return fmt.Errorf("failed to load app: %w", err) 51 } 52 53 if err := browser.OpenURL(a.URL); err != nil { 54 return fmt.Errorf("failed to open browser: %w", err) 55 } 56 57 return nil 58 }, 59 } 60 61 cmd.Flags().StringVarP(&flags.app, "app", "a", "", "The app to open") 62 cmd.RegisterFlagCompletionFunc("app", completeApp) 63 64 return cmd 65}