Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add featureflag to force shell completions for windows #5093

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions cli/shell/completer.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package shell

import (
"runtime"

"github.com/c-bata/go-prompt"
"go.mondoo.com/cnquery/v11"
"go.mondoo.com/cnquery/v11/mqlc"
Expand All @@ -14,22 +16,27 @@ var completerSeparator = string([]byte{'.', ' '})

// Completer is an auto-complete helper for the shell
type Completer struct {
schema resources.ResourcesSchema
features cnquery.Features
queryPrefix func() string
schema resources.ResourcesSchema
features cnquery.Features
queryPrefix func() string
forceCompletions bool
}

// NewCompleter creates a new Mondoo completer object
func NewCompleter(schema resources.ResourcesSchema, features cnquery.Features, queryPrefix func() string) *Completer {
return &Completer{
schema: schema,
features: features,
queryPrefix: queryPrefix,
schema: schema,
features: features,
queryPrefix: queryPrefix,
forceCompletions: features.IsActive(cnquery.ForceShellCompletion),
}
}

// CompletePrompt provides suggestions
func (c *Completer) CompletePrompt(doc prompt.Document) []prompt.Suggest {
if runtime.GOOS == "windows" && !c.forceCompletions {
return nil
}
if doc.TextBeforeCursor() == "" {
return []prompt.Suggest{}
}
Expand Down
8 changes: 0 additions & 8 deletions cli/shell/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"os/signal"
"path"
"regexp"
"runtime"
"sort"
"strings"
"sync"
Expand Down Expand Up @@ -154,13 +153,6 @@ func (s *Shell) RunInteractive(cmd string) {
}

completer := s.completer.CompletePrompt
// NOTE: this is an issue with windows cmd and powershell prompt, since this is not reliable we deactivate the
// autocompletion, see https://github.com/c-bata/go-prompt/issues/209
if runtime.GOOS == "windows" {
completer = func(doc prompt.Document) []prompt.Suggest {
return nil
}
}

p := prompt.New(
s.ExecCmd,
Expand Down
5 changes: 3 additions & 2 deletions feature_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 14 additions & 8 deletions featureflags.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,18 +94,24 @@ const (
// start: v11.x
// end: tbd (candidate: v12.0)
SerialNumberAsID

// ForceShellCompletion feature flag
// desc: Forces shell completion to be enabled (for windows)
// start: v11.x
ForceShellCompletion
)

// FeaturesValue is a map from feature name to feature flag
var FeaturesValue = map[string]Feature{
MassQueries.String(): MassQueries,
PiperCode.String(): PiperCode,
BoolAssertions.String(): BoolAssertions,
MQLAssetContext.String(): MQLAssetContext,
ErrorsAsFailures.String(): ErrorsAsFailures,
StoreResourcesData.String(): StoreResourcesData,
FineGrainedAssets.String(): FineGrainedAssets,
SerialNumberAsID.String(): SerialNumberAsID,
MassQueries.String(): MassQueries,
PiperCode.String(): PiperCode,
BoolAssertions.String(): BoolAssertions,
MQLAssetContext.String(): MQLAssetContext,
ErrorsAsFailures.String(): ErrorsAsFailures,
StoreResourcesData.String(): StoreResourcesData,
FineGrainedAssets.String(): FineGrainedAssets,
SerialNumberAsID.String(): SerialNumberAsID,
ForceShellCompletion.String(): ForceShellCompletion,
}

// DefaultFeatures are a set of default flags that are active
Expand Down
Loading