From 7305077cff0acd0f8b402c169e265bb7b34e5650 Mon Sep 17 00:00:00 2001 From: Marco Argentieri <3596602+tiero@users.noreply.github.com> Date: Tue, 8 Sep 2020 18:41:32 +0100 Subject: [PATCH] Improving logs help (#88) * 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 Co-authored-by: FrancisMars <11526661+francismars@users.noreply.github.com> --- cli/cmd/logs.go | 28 ++++++++++++++++++++++++++-- cli/controller/controller.go | 4 ++-- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/cli/cmd/logs.go b/cli/cmd/logs.go index 07b168b..cd659af 100644 --- a/cli/cmd/logs.go +++ b/cli/cmd/logs.go @@ -1,6 +1,7 @@ package cmd import ( + "errors" "os" "os/exec" @@ -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 ", + 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") diff --git a/cli/controller/controller.go b/cli/controller/controller.go index bc7d7fd..3e18a82 100644 --- a/cli/controller/controller.go +++ b/cli/controller/controller.go @@ -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, @@ -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