diff --git a/cli/shell/completer.go b/cli/shell/completer.go index aab70b80ba..2b96c7419c 100644 --- a/cli/shell/completer.go +++ b/cli/shell/completer.go @@ -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" @@ -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{} } diff --git a/cli/shell/shell.go b/cli/shell/shell.go index 6a40f2d213..e201cdd83c 100644 --- a/cli/shell/shell.go +++ b/cli/shell/shell.go @@ -10,7 +10,6 @@ import ( "os/signal" "path" "regexp" - "runtime" "sort" "strings" "sync" @@ -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, diff --git a/feature_string.go b/feature_string.go index c2e0695fdf..0bffa79e9e 100644 --- a/feature_string.go +++ b/feature_string.go @@ -17,11 +17,12 @@ func _() { _ = x[StoreResourcesData-7] _ = x[FineGrainedAssets-8] _ = x[SerialNumberAsID-9] + _ = x[ForceShellCompletion-10] } -const _Feature_name = "MassQueriesPiperCodeBoolAssertionsK8sNodeDiscoveryMQLAssetContextErrorsAsFailuresStoreResourcesDataFineGrainedAssetsSerialNumberAsID" +const _Feature_name = "MassQueriesPiperCodeBoolAssertionsK8sNodeDiscoveryMQLAssetContextErrorsAsFailuresStoreResourcesDataFineGrainedAssetsSerialNumberAsIDForceShellCompletion" -var _Feature_index = [...]uint8{0, 11, 20, 34, 50, 65, 81, 99, 116, 132} +var _Feature_index = [...]uint8{0, 11, 20, 34, 50, 65, 81, 99, 116, 132, 152} func (i Feature) String() string { i -= 1 diff --git a/featureflags.go b/featureflags.go index 0595c3cc6d..407c17c902 100644 --- a/featureflags.go +++ b/featureflags.go @@ -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