Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ go install "github.com/anthdm/slick/slick@latest"

Create new slick project
```
slick new myapp
slick new project myapp
```

Install the project
Expand Down
53 changes: 49 additions & 4 deletions slick/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ import (
)

func usage() {
fmt.Println("help....")
fmt.Println("Usage:")
fmt.Println(" slick run - Run the Slick app")
fmt.Println(" slick install - Install the Slick project")
fmt.Println(" slick new <option> <name> - Create a new <option>")
fmt.Println(" - Options: project, handler, model, view")

os.Exit(0)
}

Expand All @@ -36,16 +41,56 @@ func main() {
fmt.Println(err)
}
case "new":
if len(os.Args) != 3 {

if len(os.Args) < 4 {
usage()
}
name := os.Args[2]
if err := generateProject(name); err != nil {

// handle new command
if err := handleNewCommand(os.Args[2:]); err != nil {
fmt.Println(err)
}
}
}

func handleNewCommand(args []string) error {
option := args[0]
name := args[1]

_, isSlickProject := os.Stat("cmd/main.go")

if option != "project" && isSlickProject != nil {
fmt.Println("not in slick project root: cmd/main.go not found")
os.Exit(1)
}

switch option {

case "project":
if err := generateProject(name); err != nil {
return err
}

case "handler":
// TODO: check if name is a folder and if it contains a .go extension
if err := os.WriteFile("./handler/"+name+".go", writeHandlerContent(name), os.ModePerm); err != nil {
return err
}

case "model":
// INFO: this is not yet implemented

case "view":
// TODO: check if name is a folder and if it contains a .go extension
if err := os.WriteFile("./view/"+name+".templ", writeViewContent(name), os.ModePerm); err != nil {
return err
}

}

return nil
}

func generateProject(name string) error {
fmt.Println("creating new slick project:", name)
if err := os.Mkdir(name, os.ModePerm); err != nil {
Expand Down