Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🗑️ Add delete-app command #24

Merged
5 changes: 5 additions & 0 deletions cmd/boneless/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Targets:
migrate <app-name> <up|down> Run migrations for an app
create-app <app-name> Create a new app based on a template
build-app <app-name> Build an app using Weaver and SQLC
delete-app <app-name> Delete an app created
run Run the project using Weaver

Parameters:
Expand All @@ -37,6 +38,7 @@ Examples:
boneless migrate my-app up
boneless create-app my-app
boneless build-app my-app
boneless delete-app my-app
boneless run

`
Expand All @@ -51,6 +53,7 @@ const (
cmdMigrate = "migrate"
cmdCreateApp = "create-app"
cmdBuildApp = "build-app"
cmdDeleteApp = "delete-app"
cmdRun = "run"

DefaultComponentName = "app"
Expand Down Expand Up @@ -83,6 +86,8 @@ func main() {
internal.Build(flag.Arg(1), internal.KindComponent, "")
internal.SqlcGenerate(flag.Arg(1))
internal.WeaverGenerate()
case cmdDeleteApp:
internal.DeleteApp(flag.Arg(1))
case cmdBuild:
internal.SqlcGenerate()
internal.WeaverGenerate()
Expand Down
49 changes: 49 additions & 0 deletions internal/delete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package internal

import (
"fmt"
"os"
)

func DeleteApp(appName string) {
davidgaspardev marked this conversation as resolved.
Show resolved Hide resolved
validateAppName(appName)

appFolderPath := getAppFolderPath(appName)
checkIfAppFolderExists(appFolderPath)

// Delete the app folder
err := os.RemoveAll(appFolderPath)
if err != nil {
fmt.Println("Error deleting app folder: ", err)
davidgaspardev marked this conversation as resolved.
Show resolved Hide resolved
panic(err)
davidgaspardev marked this conversation as resolved.
Show resolved Hide resolved
}

fmt.Printf("App deleted successfully: %s\n", appName)
}

func validateAppName(appName string) {
if appName == "app" {
fmt.Println("You can't delete the app folder, it's the example component")
os.Exit(0)
}

if appName == "bff" {
fmt.Println("You can't delete the bff folder, it's required to run the application")
os.Exit(0)
}
}

func checkIfAppFolderExists(pathToDelete string) {
if _, err := os.Stat(pathToDelete); err != nil {
if os.IsNotExist(err) {
fmt.Println("App folder not found")
} else {
fmt.Println("Error checking app folder: ", err)
}
panic(err)
renanbastos93 marked this conversation as resolved.
Show resolved Hide resolved
}
}

func getAppFolderPath(appName string) string {
return fmt.Sprintf("internal/%s", appName)
}