-
Notifications
You must be signed in to change notification settings - Fork 34
⭐️ shell rewrite #6350
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
Merged
Merged
⭐️ shell rewrite #6350
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
ccabf29
⭐️ initial shell rewrite
chris-rock 4de9588
🧹 remove go-prompt
chris-rock 5be87c4
🧹 improve exit behaviour
chris-rock b5d724c
🧹 support multi-line input
chris-rock fe21cb4
🧹 improve history navigation
chris-rock 8a0a6a8
🧹 support copy/paste conent
chris-rock 1e0db28
🧹 loading query and cmd help text
chris-rock 7948a00
🧹 improve multi-line handling
chris-rock 65c0eaf
🧹 improve prompt + asset information
chris-rock 3d6c181
⭐️ syntax highlighting and improve shell history
chris-rock 6a46c3e
🧹 update go mod
chris-rock 87f104e
🧹 warning log when history loading fails
chris-rock 3c039cc
🧹 fix rendering of cat
chris-rock a35f818
🧹 simplify shell for interactive and non-interactive use
chris-rock 7037ce7
🧹 filter auto-completion
chris-rock 0458f0b
🧹 clear compile error when completion is used
chris-rock 8d6242b
🧹 add help menu and clean keymap
chris-rock File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| // Copyright (c) Mondoo, Inc. | ||
| // SPDX-License-Identifier: BUSL-1.1 | ||
|
|
||
| package shell | ||
|
|
||
| import ( | ||
| "go.mondoo.com/cnquery/v12/providers-sdk/v1/resources" | ||
| ) | ||
|
|
||
| // FilteredSchema wraps a ResourcesSchema and filters resources to only show | ||
| // those from connected providers or cross-provider resources (like core). | ||
| type FilteredSchema struct { | ||
| schema resources.ResourcesSchema | ||
| connectedProviders map[string]struct{} | ||
| } | ||
|
|
||
| // Providers that are always available regardless of connection | ||
| var alwaysAvailableProviders = []string{ | ||
| "go.mondoo.com/cnquery/v9/providers/core", | ||
| "go.mondoo.com/cnquery/v9/providers/network", | ||
| } | ||
|
|
||
| // NewFilteredSchema creates a new FilteredSchema that only exposes resources | ||
| // from the specified providers. The core and network providers are always included | ||
| // as they are available regardless of the connection type. | ||
| func NewFilteredSchema(schema resources.ResourcesSchema, providerIDs []string) *FilteredSchema { | ||
| providers := make(map[string]struct{}, len(providerIDs)+len(alwaysAvailableProviders)) | ||
| for _, id := range providerIDs { | ||
| providers[id] = struct{}{} | ||
| } | ||
| // Always include core and network providers | ||
| for _, id := range alwaysAvailableProviders { | ||
| providers[id] = struct{}{} | ||
| } | ||
|
|
||
| return &FilteredSchema{ | ||
| schema: schema, | ||
| connectedProviders: providers, | ||
| } | ||
| } | ||
|
|
||
| // Lookup returns the resource info for a given resource name. | ||
| // It returns nil if the resource is not from a connected provider. | ||
| func (f *FilteredSchema) Lookup(resource string) *resources.ResourceInfo { | ||
| info := f.schema.Lookup(resource) | ||
| if info == nil { | ||
| return nil | ||
| } | ||
| if !f.isProviderConnected(info.Provider) { | ||
| return nil | ||
| } | ||
| return info | ||
| } | ||
|
|
||
| // LookupField returns the resource info and field for a given resource and field name. | ||
| func (f *FilteredSchema) LookupField(resource string, field string) (*resources.ResourceInfo, *resources.Field) { | ||
| info, fieldInfo := f.schema.LookupField(resource, field) | ||
| if info == nil { | ||
| return nil, nil | ||
| } | ||
| if !f.isProviderConnected(info.Provider) { | ||
| return nil, nil | ||
| } | ||
| return info, fieldInfo | ||
| } | ||
|
|
||
| // FindField finds a field in a resource, including embedded fields. | ||
| func (f *FilteredSchema) FindField(resource *resources.ResourceInfo, field string) (resources.FieldPath, []*resources.Field, bool) { | ||
| return f.schema.FindField(resource, field) | ||
| } | ||
|
|
||
| // AllResources returns only resources from connected providers. | ||
| func (f *FilteredSchema) AllResources() map[string]*resources.ResourceInfo { | ||
| all := f.schema.AllResources() | ||
| filtered := make(map[string]*resources.ResourceInfo, len(all)) | ||
|
|
||
| for name, info := range all { | ||
| if f.isProviderConnected(info.Provider) { | ||
| filtered[name] = info | ||
| } | ||
| } | ||
|
|
||
| return filtered | ||
| } | ||
|
|
||
| // AllDependencies returns all provider dependencies. | ||
| func (f *FilteredSchema) AllDependencies() map[string]*resources.ProviderInfo { | ||
| return f.schema.AllDependencies() | ||
| } | ||
|
|
||
| // isProviderConnected checks if a provider is in the connected providers set. | ||
| // Empty provider string means cross-provider resource, which is always included. | ||
| func (f *FilteredSchema) isProviderConnected(provider string) bool { | ||
| if provider == "" { | ||
| return true | ||
| } | ||
| _, ok := f.connectedProviders[provider] | ||
| return ok | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.