Skip to content

Commit

Permalink
Improving logs help (#88)
Browse files Browse the repository at this point in the history
* added container_names

* removed deprecated links directive

* changed container_name related documentation

* added necessary dependencies

* added dependency

* improved help from Logs

* changed Services to global var

* Some fixes on logs helper

* fixes on logs helper

* logs helper changed if logic

* changed services string spacing

Co-authored-by: FrancisMars <[email protected]>
Co-authored-by: FrancisMars <[email protected]>
  • Loading branch information
3 people authored Sep 8, 2020
1 parent b076d2d commit 7305077
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
28 changes: 26 additions & 2 deletions cli/cmd/logs.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cmd

import (
"errors"
"os"
"os/exec"

Expand All @@ -10,13 +11,36 @@ import (
"github.com/spf13/cobra"
)

var logsDescription = "Check Service logs. Requires one Service: " + servicesList()

var LogsCmd = &cobra.Command{
Use: "logs",
Short: "Check service logs",
Args: func(cmd *cobra.Command, args []string) error {

if len(args) != 1 {
return errors.New(logsDescription)
}
_, found := controller.Services[args[0]]
if !found {
return errors.New(logsDescription)
}
return nil
},
Use: "logs <service>",
Short: logsDescription,
Long: logsDescription,
RunE: logs,
PreRunE: logsChecks,
}

func servicesList() string {
var servicesString string
for key, _ := range controller.Services {
servicesString += key
servicesString += " | "
}
return servicesString[:len(servicesString)-3]
}

func logsChecks(cmd *cobra.Command, args []string) error {
datadir, _ := cmd.Flags().GetString("datadir")
isLiquidService, _ := cmd.Flags().GetBool("liquid")
Expand Down
4 changes: 2 additions & 2 deletions cli/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/vulpemventures/nigiri/cli/constants"
)

var services = map[string]bool{
var Services = map[string]bool{
"node": true,
"esplora": true,
"electrs": true,
Expand Down Expand Up @@ -37,7 +37,7 @@ func NewController() (*Controller, error) {
return nil, err
}
c.env = &Env{}
c.parser = newParser(services)
c.parser = newParser(Services)
c.docker = dockerClient
c.config = &config.Config{}
return c, nil
Expand Down

0 comments on commit 7305077

Please sign in to comment.