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

commands: reimplements printing deployment statuses, closes #462 #486

Merged
merged 8 commits into from
Sep 21, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions api/deploy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestDeployService(t *testing.T) {
}, <-statuses)

require.Equal(t, DeployStatus{
Message: fmt.Sprintf("%s Completed.", aurora.Green("✔")),
Message: fmt.Sprintf("%s Service deployed.", aurora.Green("✔")),
Type: DONE,
}, <-statuses)

Expand Down Expand Up @@ -159,7 +159,7 @@ func TestDeployServiceFromURL(t *testing.T) {
}, <-statuses)

require.Equal(t, DeployStatus{
Message: fmt.Sprintf("%s Completed.", aurora.Green("✔")),
Message: fmt.Sprintf("%s Service deployed.", aurora.Green("✔")),
Type: DONE,
}, <-statuses)

Expand Down
16 changes: 16 additions & 0 deletions commands/provider/service_deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package provider

import (
"context"
"fmt"
"io"

"github.com/asaskevich/govalidator"
"github.com/docker/docker/pkg/archive"
"github.com/mesg-foundation/core/protobuf/coreapi"
"github.com/mesg-foundation/core/utils/pretty"
)

// ServiceDeploy deploys service from given path.
Expand Down Expand Up @@ -87,17 +89,31 @@ func readDeployReply(stream coreapi.Core_DeployServiceClient, deployment chan de
}

var (
status = message.GetStatus()
serviceID = message.GetServiceID()
validationError = message.GetValidationError()
)

switch {
case status != nil:
NicolasMahe marked this conversation as resolved.
Show resolved Hide resolved
switch status.Type {
case coreapi.DeployServiceReply_Status_RUNNING:
pretty.UseSpinner(status.Message)

case coreapi.DeployServiceReply_Status_DONE:
pretty.DestroySpinner()
fmt.Println(status.Message)
}

case serviceID != "":
pretty.DestroySpinner()
result.serviceID = serviceID
deployment <- result
return

case validationError != "":
pretty.DestroySpinner()
fmt.Println(pretty.Fail(validationError))
result.isValid = false
deployment <- result
return
Expand Down
6 changes: 2 additions & 4 deletions commands/service_deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,12 @@ func (c *serviceDeployCmd) runE(cmd *cobra.Command, args []string) error {
valid bool
err error
)
pretty.Progress("Deploying the service...", func() {
id, valid, err = c.e.ServiceDeploy(c.path)
})
id, valid, err = c.e.ServiceDeploy(c.path)
if err != nil {
return err
}
if !valid {
return errors.New("Service is invalid. To get more information, run: mesg-core service validate")
return errors.New("To get more information, run: mesg-core service validate")
}
fmt.Println("Service deployed with ID:", pretty.Success(id))
fmt.Printf("To start it, run the command: mesg-core service start %s\n", id)
Expand Down
7 changes: 2 additions & 5 deletions commands/service_dev.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,16 +53,13 @@ func (c *serviceDevCmd) runE(cmd *cobra.Command, args []string) error {
valid bool
err error
)
pretty.Progress("Deploying the service...", func() {
id, valid, err = c.e.ServiceDeploy(c.path)
})
id, valid, err = c.e.ServiceDeploy(c.path)
if err != nil {
return err
}
if !valid {
return errors.New("Service is invalid. To get more information, run: mesg-core service validate")
return errors.New("To get more information, run: mesg-core service validate")
}
fmt.Printf("%s Service deployed\n", pretty.SuccessSign)
defer pretty.Progress("Removing the service...", func() { c.e.ServiceDelete(id) })

pretty.Progress("Starting the service...", func() { err = c.e.ServiceStart(id) })
Expand Down
2 changes: 1 addition & 1 deletion service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ func (s *Service) deploy() error {
}

s.sendStatus(fmt.Sprintf("%s Image built with success.", aurora.Green("✔")), DDONE)
s.sendStatus(fmt.Sprintf("%s Completed.", aurora.Green("✔")), DDONE)
s.sendStatus(fmt.Sprintf("%s Service deployed.", aurora.Green("✔")), DDONE)

s.configuration.Key = "service"
s.configuration.Image = imageHash
Expand Down
20 changes: 18 additions & 2 deletions utils/pretty/pretty.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var (
FailSign = pg.Fail("⨯")
)

// Predefiend colors
// Predefined colors.
var (
FgYellow = color.New(color.FgYellow)
FgBlue = color.New(color.FgBlue)
Expand Down Expand Up @@ -239,9 +239,19 @@ func (p *Pretty) Progress(message string, fn func()) {
return
}

p.UseSpinner(message)
fn()
p.DestroySpinner()
}

// UseSpinner uses spinner animation for message.
func (p *Pretty) UseSpinner(message string) {
p.Spinner.Suffix = " " + strings.TrimRight(message, "\n")
p.Spinner.Start()
fn()
}

// DestroySpinner destroyes spinner animation.
func (p *Pretty) DestroySpinner() {
p.Spinner.Stop()
p.Spinner.Suffix = ""
}
Expand Down Expand Up @@ -356,6 +366,12 @@ func Colorize(c *color.Color, msg string) string { return pg.Colorize(c, msg) }
// Progress prints spinner with the given message while calling fn function.
func Progress(message string, fn func()) { pg.Progress(message, fn) }

// UseSpinner uses spinner animation for message.
func UseSpinner(message string) { pg.UseSpinner(message) }

// DestroySpinner destroyes spinner animation.
func DestroySpinner() { pg.DestroySpinner() }

// ColorizeJSON colors keys and values of stringified JSON. On errors the original string is returned.
// If color is nil then key/value won't be colorize.
func ColorizeJSON(keyColor *color.Color, valueColor *color.Color, data []byte) []byte {
Expand Down