Skip to content

Commit 3646c4b

Browse files
committed
✨ Show all provider subcommands
Usually we only show subcommands for providers that are installed. This offers an alternative where we show all provider subcommands in the help menu. eg: ```bash ~ $> cnquery shell --help x1 Allows the interactive exploration of MQL queries. Usage: cnquery shell [flags] cnquery shell [command] Available Commands: arista Interactive shell with an Arista EOS device atlassian Interactive shell with Atlassian aws Interactive shell with an AWS account azure Interactive shell with an Azure subscription container Interactive shell with a running container or container image docker Interactive shell with a running docker or docker image equinix Interactive shell with an Equinix Metal organization filesystem Interactive shell with a mounted file system target. gcp Interactive shell with a Google Cloud project github Interactive shell with a GitHub organization or repository ... ``` I still wonder if we should create a custom help for these provider plugins that is shorter than the current list of defaults. They are getting a bit out of hand... Signed-off-by: Dominik Richter <dominik.richter@gmail.com>
1 parent 445b71c commit 3646c4b

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

cli/providers/providers.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ func AttachCLIs(rootCmd *cobra.Command, commands ...*Command) error {
4141
}
4242
}
4343

44+
// We want to offer as many commands as possible,
45+
// useful for e.g. help commands
46+
providers.AddMissingDefaults(existing)
47+
4448
// Now that we know we have all providers, it's time to load them to build
4549
// the remaining CLI. Probably an opportunity to optimize in the future,
4650
// but fine for now to do it all.

providers/providers.go

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package providers
66
import (
77
"archive/tar"
88
"encoding/json"
9-
"go.mondoo.com/ranger-rpc"
109
"io"
1110
"net/http"
1211
"os"
@@ -23,6 +22,7 @@ import (
2322
"go.mondoo.com/cnquery/v9/cli/config"
2423
"go.mondoo.com/cnquery/v9/providers-sdk/v1/plugin"
2524
"go.mondoo.com/cnquery/v9/providers-sdk/v1/resources"
25+
"go.mondoo.com/ranger-rpc"
2626
"golang.org/x/exp/slices"
2727
)
2828

@@ -160,6 +160,19 @@ func ListAll() ([]*Provider, error) {
160160
return res, nil
161161
}
162162

163+
// AddMissingDefaults to a list of existing providers. A system may have
164+
// a set of providers already installed. This command cycles through
165+
// the list of default providers and adds them to the list of existing
166+
// providers to create a full list of possible providers (existing + potential).
167+
// Useful when generating the CLI without having all providers installed.
168+
func AddMissingDefaults(existing Providers) {
169+
for _, v := range DefaultProviders {
170+
if _, ok := existing[v.ID]; !ok {
171+
existing[v.ID] = v
172+
}
173+
}
174+
}
175+
163176
// EnsureProvider makes sure that a given provider exists and returns it.
164177
// You can supply providers either via:
165178
// 1. connectorName, which is what you see in the CLI e.g. "local", "ssh", ...

0 commit comments

Comments
 (0)