this repo has no description smallweb.run
smallweb
4
fork

Configure Feed

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

add ability to init a workpace in an empty dir

pomdtr 282e1c4d cfc4fe62

+18 -11
+16 -9
cmd/init.go
··· 19 19 Short: "Initialize a new workspace", 20 20 Args: cobra.NoArgs, 21 21 RunE: func(cmd *cobra.Command, args []string) error { 22 - dir, _ := cmd.Flags().GetString("dir") 22 + dir := k.String("dir") 23 23 if dir == "" { 24 - return fmt.Errorf("the dir flag is required") 24 + return fmt.Errorf("dir is required") 25 25 } 26 26 27 - domain, _ := cmd.Flags().GetString("domain") 27 + domain := k.String("domain") 28 28 if domain == "" { 29 - return fmt.Errorf("the domain flag is required") 29 + return fmt.Errorf("domain is required") 30 30 } 31 31 32 32 subFS, err := fs.Sub(embedFS, "templates/workspace") ··· 34 34 return fmt.Errorf("failed to read workspace embed: %w", err) 35 35 } 36 36 37 - if _, err := os.Stat(k.String("dir")); err == nil { 38 - return fmt.Errorf("directory %s already exists", k.String("dir")) 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 + } 39 46 } 40 47 41 48 templateFS := gosod.New(subFS) 42 - if err := templateFS.Extract(k.String("dir"), map[string]any{ 43 - "Domain": k.String("domain"), 49 + if err := templateFS.Extract(dir, map[string]any{ 50 + "Domain": domain, 44 51 }); err != nil { 45 52 return fmt.Errorf("failed to extract workspace: %w", err) 46 53 } 47 54 48 - fmt.Fprintf(cmd.ErrOrStderr(), "Workspace initialized at %s\n", k.String("dir")) 55 + fmt.Fprintf(cmd.ErrOrStderr(), "Workspace initialized at %s\n", dir) 49 56 return nil 50 57 }, 51 58 }
+1 -1
compose.dev.yml
··· 8 8 - 7777:7777 9 9 - 2222:2222 10 10 volumes: 11 - - ./workspace:/smallweb 11 + - ./empty:/home/smallweb/workspace 12 12 environment: 13 13 - SMALLWEB_DIR=/home/smallweb/workspace 14 14 - SMALLWEB_DOMAIN=smallweb.localhost
+1 -1
compose.yml
··· 7 7 - 7777:7777 8 8 - 2222:2222 9 9 volumes: 10 - - ./workspace:/smallweb 10 + - ./workspace:/home/smallweb/workspace 11 11 environment: 12 12 - SMALLWEB_DIR=/home/smallweb/workspace 13 13 - SMALLWEB_DOMAIN=smallweb.localhost