Integrate --format flag docs helper with commands

This commit is contained in:
Juan Carlos Mejías Rodríguez 2019-08-10 16:51:36 -04:00
parent 65c7b6cafc
commit 9551afd432
5 changed files with 15 additions and 10 deletions

View File

@ -92,16 +92,7 @@ func init() {
configListCmd.Flags().String("format", "", "Format output using a Go template.")
viper.BindPFlag("config.list.format", configListCmd.Flags().Lookup("format"))
configListCmd.SetUsageTemplate(configListCmd.UsageTemplate() + `
Format:
The --format flag accepts a Go template, which is executed in an object with this structure:
{
Key string
EnvironmentVariable string
CurrentValue string
}
`)
configListCmd.SetUsageTemplate(configListCmd.UsageTemplate() + common.GetFormatHelp(config{}))
}
type config struct {

View File

@ -5,6 +5,8 @@ import (
"os"
"text/template"
portainer "github.com/portainer/portainer/api"
"github.com/greenled/portainer-stack-utils/common"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
@ -62,4 +64,6 @@ func init() {
endpointGroupListCmd.Flags().String("format", "", "Format output using a Go template.")
viper.BindPFlag("endpoint.group.list.format", endpointGroupListCmd.Flags().Lookup("format"))
endpointGroupListCmd.SetUsageTemplate(endpointGroupListCmd.UsageTemplate() + common.GetFormatHelp(portainer.EndpointGroup{}))
}

View File

@ -21,6 +21,8 @@ import (
"os"
"text/template"
portainer "github.com/portainer/portainer/api"
"github.com/greenled/portainer-stack-utils/common"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
@ -90,4 +92,6 @@ func init() {
endpointListCmd.Flags().String("format", "", "Format output using a Go template.")
viper.BindPFlag("endpoint.list.format", endpointListCmd.Flags().Lookup("format"))
endpointListCmd.SetUsageTemplate(endpointListCmd.UsageTemplate() + common.GetFormatHelp(portainer.Endpoint{}))
}

View File

@ -98,4 +98,6 @@ func init() {
stackListCmd.Flags().String("format", "", "Format output using a Go template.")
viper.BindPFlag("stack.list.endpoint", stackListCmd.Flags().Lookup("endpoint"))
viper.BindPFlag("stack.list.format", stackListCmd.Flags().Lookup("format"))
stackListCmd.SetUsageTemplate(stackListCmd.UsageTemplate() + common.GetFormatHelp(portainer.Stack{}))
}

View File

@ -5,6 +5,8 @@ import (
"os"
"text/template"
portainer "github.com/portainer/portainer/api"
"github.com/greenled/portainer-stack-utils/common"
"github.com/spf13/cobra"
"github.com/spf13/viper"
@ -58,4 +60,6 @@ func init() {
statusCmd.Flags().String("format", "", "Format output using a Go template.")
viper.BindPFlag("status.format", statusCmd.Flags().Lookup("format"))
statusCmd.SetUsageTemplate(statusCmd.UsageTemplate() + common.GetFormatHelp(portainer.Status{}))
}