Skip to content

Commit

Permalink
prettier output
Browse files Browse the repository at this point in the history
  • Loading branch information
jfeodor committed May 28, 2024
1 parent 93bf7f7 commit 3f302df
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 25 deletions.
27 changes: 19 additions & 8 deletions cli/cmd/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,16 @@ func Deploy(ctx context.Context, dir string, slug string, appName string, apps A
return ErrInvalidAppName
}

output.PrintTaskStarted("Loading app configuration....")

manifest, err := manifest.LoadManifest(filepath.Join(dir, manifest.ManifestPath))
if err != nil {
output.PrintErrorAppNotInitialized()
return err
}
output.PrintTaskDone("Loading app configuration....")

output.PrintTaskStarted("Registering new version......")
appID, err := readOrCreateApp(ctx, apps, slug, appName, manifest)
if err != nil {
return err
Expand All @@ -58,14 +62,9 @@ func Deploy(ctx context.Context, dir string, slug string, appName string, apps A
output.PrintErrorDetails("Error creating app version remotely", err)
return err
}
output.PrintTaskDone("Registering new version......")

uploadURLInput := app.AppVersionUploadURLInput(appVersionOutput)
uploadURLOutput, err := apps.AppVersionUploadURL(ctx, uploadURLInput)
if err != nil {
output.PrintErrorDetails("Error creating app version remotely", err)
return err
}

output.PrintTaskStarted("Creating app archive.........")
tarPath := path.Join(dir, ".tmp_app_archive.tar")
err = archive.TarCreate(dir, tarPath, manifest.Exclude)
if err != nil {
Expand All @@ -79,13 +78,24 @@ func Deploy(ctx context.Context, dir string, slug string, appName string, apps A
output.PrintErrorDetails("Error archiving app source", err)
return err
}
output.PrintTaskDone("Creating app archive.........")

output.PrintTaskStarted("Uploading app archive........")
uploadURLInput := app.AppVersionUploadURLInput(appVersionOutput)
uploadURLOutput, err := apps.AppVersionUploadURL(ctx, uploadURLInput)
if err != nil {
output.PrintErrorDetails("Error creating app version remotely", err)
return err
}

err = apps.UploadAppSource(uploadURLOutput.UploadURL, archive)
if err != nil {
output.PrintErrorDetails("Error uploading app source archive", err)
return err
}
output.PrintTaskDone("Uploading app archive........")

output.PrintTaskStarted("Deploying app................")
deployAppInput := app.DeployAppInput(appVersionOutput)
deployAppOutput, err := apps.DeployApp(ctx, deployAppInput)
if err != nil {
Expand All @@ -95,14 +105,15 @@ func Deploy(ctx context.Context, dir string, slug string, appName string, apps A
input := app.DeployEventsInput{
DeploymentVersionID: deployAppOutput.DeploymentVersionID,
Handler: func(de app.DeployEvent) bool {
println("DEPLOY:", de.Message)
// TODO: display status based on deploy events
return true
},
}
err = apps.DeployEvents(ctx, input)
if err != nil {
output.PrintErrorDetails("Error receiving deploy logs", err)
}
output.PrintTaskDone("Deploying app................")

return nil
}
Expand Down
19 changes: 19 additions & 0 deletions cli/cmd/output/task.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package output

import "fmt"

var (
greenColorEscapeANSI = "\033[32m"
resetColorEscapeANSI = "\033[0m"
unicodeCheckmark = "\u2713"
greenCheckmark = greenColorEscapeANSI + unicodeCheckmark + resetColorEscapeANSI
unicodeHourglass = "\u29D6"
)

func PrintTaskStarted(message string) {
fmt.Print(unicodeHourglass + " " + message)
}

func PrintTaskDone(message string) {
fmt.Println("\r" + greenCheckmark + " " + message + "Done")
}
25 changes: 8 additions & 17 deletions cli/cmd/push/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,6 @@ const (

var verbose bool

var (
carriageReturn = "\r"
greenColorEscapeANSI = "\033[32m"
resetColorEscapeANSI = "\033[0m"
unicodeCheckmark = "\u2713"
greenCheckmark = carriageReturn + greenColorEscapeANSI + unicodeCheckmark + resetColorEscapeANSI
unicodeHourglass = "\u29D6"
)

const (
ProjectArgLength = 1
ProjectAndAppArgLength = 2
Expand Down Expand Up @@ -139,7 +130,7 @@ func printURL(toolID string) (ok bool) {
}

func deployApp(toolID string) (ok bool) {
fmt.Print(unicodeHourglass + " Deploying app......")
output.PrintTaskStarted("Deploying app......")

err := stopJobs(string(toolID))
if err != nil {
Expand All @@ -153,13 +144,13 @@ func deployApp(toolID string) (ok bool) {
return false
}

fmt.Println(greenCheckmark + " Deploying app......Done")
output.PrintTaskDone("Deploying app......")

return true
}

func buildApp(buildID string, appPath string) (ok bool) {
fmt.Print(unicodeHourglass + " Building app.......")
output.PrintTaskStarted("Building app.......")
if verbose {
// To allow nice printing of build messages from backend
fmt.Println()
Expand All @@ -171,15 +162,15 @@ func buildApp(buildID string, appPath string) (ok bool) {
return false
}

fmt.Println(greenCheckmark + " Building app.......Done")
output.PrintTaskDone("Building app.......")

return true
}

func uploadApp(appDir string, toolID string) (buildID string, ok bool) {
defer os.Remove(zipFileName)

fmt.Print(unicodeHourglass + " Uploading app......")
output.PrintTaskStarted("Uploading app......")

secrets := loadSecretsFromEnv(appDir)
buildID, err := pushBuild(zipFileName, string(toolID), secrets)
Expand All @@ -199,14 +190,14 @@ func uploadApp(appDir string, toolID string) (buildID string, ok bool) {
return "", false
}

fmt.Println(greenCheckmark + " Uploading app......Done")
output.PrintTaskDone("Uploading app......Done")

return buildID, true
}

func prepareApp(m *manifest.Manifest) (ok bool) {
if !verbose {
fmt.Print(unicodeHourglass + " Preparing upload...")
output.PrintTaskStarted("Preparing upload...")
}

if err := archive.ZipCreate(".", zipFileName, m.Exclude); err != nil {
Expand All @@ -216,7 +207,7 @@ func prepareApp(m *manifest.Manifest) (ok bool) {
return false
}

fmt.Println(greenCheckmark + " Preparing upload...Done")
output.PrintTaskDone("Preparing upload...")

return true
}
Expand Down

0 comments on commit 3f302df

Please sign in to comment.