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 61 lines 1.3 kB view raw
1package cmd 2 3import ( 4 "embed" 5 "fmt" 6 "io/fs" 7 "os" 8 9 "github.com/leaanthony/gosod" 10 "github.com/spf13/cobra" 11) 12 13//go:embed templates/workspace/* 14var embedFS embed.FS 15 16func NewCmdInit() *cobra.Command { 17 cmd := &cobra.Command{ 18 Use: "init", 19 Short: "Initialize a new workspace", 20 Args: cobra.NoArgs, 21 RunE: func(cmd *cobra.Command, args []string) error { 22 dir := k.String("dir") 23 if dir == "" { 24 return fmt.Errorf("dir is required") 25 } 26 27 domain := k.String("domain") 28 if domain == "" { 29 return fmt.Errorf("domain is required") 30 } 31 32 subFS, err := fs.Sub(embedFS, "templates/workspace") 33 if err != nil { 34 return fmt.Errorf("failed to read workspace embed: %w", err) 35 } 36 37 if _, err := os.Stat(dir); err == nil { 38 entries, err := os.ReadDir(dir) 39 if err != nil { 40 return fmt.Errorf("failed to read directory %s: %w", dir, err) 41 } 42 43 if len(entries) > 0 { 44 return fmt.Errorf("directory %s already exists and is not empty", dir) 45 } 46 } 47 48 templateFS := gosod.New(subFS) 49 if err := templateFS.Extract(dir, map[string]any{ 50 "Domain": domain, 51 }); err != nil { 52 return fmt.Errorf("failed to extract workspace: %w", err) 53 } 54 55 fmt.Fprintf(cmd.ErrOrStderr(), "Workspace initialized at %s\n", dir) 56 return nil 57 }, 58 } 59 60 return cmd 61}