Skip to content

Commit

Permalink
env: add CARAPACE_HIDDEN to show hidden
Browse files Browse the repository at this point in the history
  • Loading branch information
rsteube committed Jul 10, 2023
1 parent 3ecd336 commit 2a465fe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions internal/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ func Sandbox() string {
func Log() bool {
return os.Getenv("CARAPACE_LOG") != ""
}

func Hidden() bool {
return os.Getenv("CARAPACE_HIDDEN") != ""
}
5 changes: 3 additions & 2 deletions internalActions.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

"github.com/rsteube/carapace/internal/common"
"github.com/rsteube/carapace/internal/env"
"github.com/rsteube/carapace/internal/pflagfork"
"github.com/rsteube/carapace/pkg/style"
"github.com/rsteube/carapace/pkg/util"
Expand Down Expand Up @@ -85,7 +86,7 @@ func actionFlags(cmd *cobra.Command) Action {
vals := make([]string, 0)
flagSet.VisitAll(func(f *pflagfork.Flag) {
switch {
case f.Hidden:
case f.Hidden && !env.Hidden():
return // skip hidden flags
case f.Deprecated != "":
return // skip deprecated flags
Expand Down Expand Up @@ -129,7 +130,7 @@ func actionSubcommands(cmd *cobra.Command) Action {
return ActionCallback(func(c Context) Action {
batch := Batch()
for _, subcommand := range cmd.Commands() {
if !subcommand.Hidden && subcommand.Deprecated == "" {
if (!subcommand.Hidden || env.Hidden()) && subcommand.Deprecated == "" {
group := common.Group{Cmd: subcommand}
batch = append(batch, ActionStyledValuesDescribed(subcommand.Name(), subcommand.Short, group.Style()).Tag(group.Tag()))
for _, alias := range subcommand.Aliases {
Expand Down

0 comments on commit 2a465fe

Please sign in to comment.