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

Update cli with new api #236

Merged
merged 4 commits into from
Jun 17, 2018
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- (#181) MESG Core and Service start and stop functions wait for the docker container to actually run or stop.
- (#183) **BREAKING** Docker image is automatically injected in the `mesg.yml` file for your service. Now `dependencies` attribute is for extra dependencies so for most of service this is not necessary anymore.
- (#212) **BREAKING** Communication from services to core is now done through a token provided by the core
- (#) CLI only use the API
- (#234) `service list` command now includes the status for every services

#### Added
Expand Down
7 changes: 3 additions & 4 deletions cmd/service/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/logrusorgru/aurora"
"github.com/mesg-foundation/core/api/core"
"github.com/mesg-foundation/core/cmd/utils"
"github.com/mesg-foundation/core/database/services"
"github.com/spf13/cobra"
survey "gopkg.in/AlecAivazis/survey.v1"
)
Expand Down Expand Up @@ -36,13 +35,13 @@ func deleteHandler(cmd *cobra.Command, args []string) {
return
}
fmt.Println("Deleting all services...")
services, err := services.All() // TODO: this should use the API
reply, err := cli.ListServices(context.Background(), &core.ListServicesRequest{})
utils.HandleError(err)
if len(services) == 0 {
if len(reply.Services) == 0 {
fmt.Println("All services are already deleted")
return
}
for _, service := range services {
for _, service := range reply.Services {
args = append(args, service.Hash())
}
}
Expand Down
8 changes: 6 additions & 2 deletions cmd/service/detail.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package service

import (
"context"
"fmt"
"strings"

"github.com/logrusorgru/aurora"
"github.com/mesg-foundation/core/api/core"
"github.com/mesg-foundation/core/cmd/utils"
"github.com/mesg-foundation/core/database/services"
"github.com/spf13/cobra"
)

Expand All @@ -21,8 +22,11 @@ var Detail = &cobra.Command{
}

func detailHandler(cmd *cobra.Command, args []string) {
service, err := services.Get(args[0])
serviceReply, err := cli.GetService(context.Background(), &core.GetServiceRequest{
ServiceID: args[0],
})
utils.HandleError(err)
service := serviceReply.Service
fmt.Println("name: ", aurora.Bold(service.Name))
fmt.Println("events: ")
for name, event := range service.Events {
Expand Down
7 changes: 4 additions & 3 deletions cmd/service/list.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package service

import (
"context"
"fmt"
"sort"
"strings"

"github.com/logrusorgru/aurora"
"github.com/mesg-foundation/core/api/core"
"github.com/mesg-foundation/core/cmd/utils"
"github.com/mesg-foundation/core/database/services"
"github.com/mesg-foundation/core/service"
"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -50,9 +51,9 @@ To have more details, see the [detail command](mesg-core_service_detail.md).`,
}

func listHandler(cmd *cobra.Command, args []string) {
services, err := services.All() // TODO: this should use the API
reply, err := cli.ListServices(context.Background(), &core.ListServicesRequest{})
utils.HandleError(err)
status, err := servicesWithStatus(services)
status, err := servicesWithStatus(reply.Services)
utils.HandleError(err)
sort.Sort(byStatus(status))
for _, serviceStatus := range status {
Expand Down
22 changes: 8 additions & 14 deletions cmd/service/logs.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package service

import (
"fmt"
"context"
"os"

"github.com/docker/docker/pkg/stdcopy"
"github.com/logrusorgru/aurora"
"github.com/mesg-foundation/core/api/core"
"github.com/mesg-foundation/core/cmd/utils"
serviceDB "github.com/mesg-foundation/core/database/services"
"github.com/spf13/cobra"
)

Expand All @@ -27,17 +26,12 @@ func init() {
}

func logsHandler(cmd *cobra.Command, args []string) {
serviceID := args[0]
service, err := serviceDB.Get(serviceID)
if err != nil {
return
}
dependency := cmd.Flag("dependency").Value.String()
readers, err := service.Logs(dependency)
if err != nil {
fmt.Println(aurora.Red(err))
return
}
reply, err := cli.GetService(context.Background(), &core.GetServiceRequest{
ServiceID: args[0],
})
utils.HandleError(err)
readers, err := reply.Service.Logs(cmd.Flag("dependency").Value.String())
utils.HandleError(err)
for _, reader := range readers {
defer reader.Close()
go stdcopy.StdCopy(os.Stdout, os.Stderr, reader)
Expand Down
33 changes: 0 additions & 33 deletions cmd/service/pause.go

This file was deleted.

28 changes: 0 additions & 28 deletions cmd/service/resume.go

This file was deleted.