diff --git a/cmd/helper.go b/cmd/helper.go index 3f20558..ec796e8 100644 --- a/cmd/helper.go +++ b/cmd/helper.go @@ -18,6 +18,9 @@ import ( "sync" ) +var DisableLongOutput = false +var DisableExampleOutput = false + func GetSingularTypeNames(types []string) []string { var ret []string @@ -242,6 +245,10 @@ func GetDeleteAllShort(resource resources.Resource) string { func GetGetLong(resourceName string, resourceUrl string, usageGetType string, completionVerb int, urlInfo *resources.CrudEntityInfo, resource resources.Resource) string { + if DisableLongOutput { + return "" + } + types, err := resources.GetTypesOfVariablesNeeded(resourceUrl) if err != nil { @@ -322,6 +329,9 @@ func toJsonExample(in []string, resource resources.Resource) string { } func GetCreateLong(resource resources.Resource) string { + if DisableLongOutput { + return "" + } resourceName := resource.SingularName singularTypeNames, err := resources.GetSingularTypesOfVariablesNeeded(resource.CreateEntityInfo.Url) @@ -354,6 +364,9 @@ Documentation: } func GetUpdateLong(resource resources.Resource) string { + if DisableLongOutput { + return "" + } resourceName := resource.SingularName singularTypeNames, err := resources.GetSingularTypesOfVariablesNeeded(resource.UpdateEntityInfo.Url) @@ -386,6 +399,9 @@ Documentation: } func GetDeleteLong(resource resources.Resource) string { + if DisableLongOutput { + return "" + } resourceName := resource.SingularName singularTypeNames, err := resources.GetSingularTypesOfVariablesNeeded(resource.DeleteEntityInfo.Url) @@ -499,6 +515,10 @@ var getExampleCache sync.Map func GetGetExample(resourceName string, resourceUrl string, usageGetType string, completionVerb int, urlInfo *resources.CrudEntityInfo, resource resources.Resource) string { + if DisableExampleOutput { + return "" + } + cacheKey := fmt.Sprintf("%s-%d", resourceName, completionVerb) if example, ok := getExampleCache.Load(cacheKey); ok { return example.(string) @@ -605,6 +625,10 @@ func GetGetExample(resourceName string, resourceUrl string, usageGetType string, var createExampleCache sync.Map func GetCreateExample(resource resources.Resource) string { + if DisableExampleOutput { + return "" + } + resourceName := resource.SingularName if v, ok := createExampleCache.Load(resourceName); ok { @@ -685,6 +709,9 @@ func GetCreateExample(resource resources.Resource) string { var updateExampleCache sync.Map func GetUpdateExample(resource resources.Resource) string { + if DisableExampleOutput { + return "" + } resourceName := resource.SingularName if v, ok := updateExampleCache.Load(resourceName); ok { @@ -754,6 +781,10 @@ func GetUpdateExample(resource resources.Resource) string { var deleteExampleCache sync.Map func GetDeleteExample(resource resources.Resource) string { + if DisableExampleOutput { + return "" + } + resourceName := resource.SingularName if v, ok := deleteExampleCache.Load(resourceName); ok { return v.(string) diff --git a/cmd/root.go b/cmd/root.go index d155dd0..213db1b 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -58,6 +58,10 @@ var jqCompletionFunc = func(cmd *cobra.Command, args []string, toComplete string var profileNameFromCommandLine = "" func InitializeCmd() { + if os.Args[1] == "__complete" { + DisableLongOutput = true + DisableExampleOutput = true + } cobra.OnInitialize(initConfig) initConfig() diff --git a/cmd/runbooks.go b/cmd/runbooks.go index d087300..1994b4e 100644 --- a/cmd/runbooks.go +++ b/cmd/runbooks.go @@ -341,6 +341,14 @@ type CommandAndReset struct { } func generateRunbookCmd() *CommandAndReset { + DisableLongOutput = true + DisableExampleOutput = true + + defer func() { + DisableLongOutput = false + DisableExampleOutput = false + }() + root := &cobra.Command{ Use: "epcc", SilenceUsage: true,