Skip to content

Commit

Permalink
add cli help and options
Browse files Browse the repository at this point in the history
  • Loading branch information
cchalop1 committed May 28, 2024
1 parent 8f7b67c commit 95ae007
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 8 deletions.
42 changes: 35 additions & 7 deletions cmd/just-deploy/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package main

import (
"flag"
"fmt"
"os"

"cchalop1.com/deploy/internal/adapter"
Expand All @@ -10,6 +12,14 @@ import (
"cchalop1.com/deploy/internal/web"
)

var flags struct {
noBrowser bool
help bool
redeploy struct {
deployId string
}
}

func main() {
app := api.NewApplication()

Expand All @@ -28,16 +38,34 @@ func main() {
// TODO: try server connection
// TODO: do health check

args := os.Args[1:]
getArgsOptions()

if len(args) > 1 {
if args[0] == "redeploy" {
application.ReDeployApplication(&deployService, args[1])
os.Exit(0)
}
if flags.help {
showHelp()
}

if flags.redeploy.deployId != "" {
application.ReDeployApplication(&deployService, flags.redeploy.deployId)
os.Exit(0)
} else {
api.CreateRoutes(app, &deployService)
web.CreateMiddlewareWebFiles(app)
app.StartServer(true)
app.StartServer(!flags.noBrowser)

}
}

func getArgsOptions() {
flag.BoolVar(&flags.noBrowser, "no-browser", false, "Do not open the browser")
flag.StringVar(&flags.redeploy.deployId, "redeploy", "", "Redeploy application by deploy id")
flag.BoolVar(&flags.help, "help", false, "Show help")
flag.Parse()
}

func showHelp() {
fmt.Println("Usage: main [options]")
fmt.Println(" -no-browser Do not open the browser")
fmt.Println(" -redeploy <id> Redeploy application by deploy id")
os.Exit(0)

}
2 changes: 1 addition & 1 deletion internal/adapter/filesystem.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (fs *FilesystemAdapter) CopyFileToRemoteServer(sourcePath string, serverIp

func (fs *FilesystemAdapter) CreateGitPostCommitHooks(deploy domain.Deploy) error {
hooksFilePath := deploy.PathToSource + ".git/hooks/post-commit"
fileContent := []byte("#!/bin/sh\njustdeploy redeploy " + deploy.Id + "\n")
fileContent := []byte("#!/bin/sh\njustdeploy --redeploy " + deploy.Id + "\n")

err := os.WriteFile(hooksFilePath, fileContent, 0755)

Expand Down

0 comments on commit 95ae007

Please sign in to comment.