Skip to content

Commit

Permalink
Merge pull request #801 from rsteube/env-hidden
Browse files Browse the repository at this point in the history
env: add `CARAPACE_HIDDEN` to show hidden
  • Loading branch information
rsteube authored Jul 10, 2023
2 parents 3ecd336 + 2a465fe commit 008b117
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 008b117

Please sign in to comment.