MCPcopy Create free account
hub / github.com/CrowdStrike/perseus / runListModuleVersionsCmd

Function runListModuleVersionsCmd

query.go:149–204  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

147}
148
149func runListModuleVersionsCmd(cmd *cobra.Command, args []string) error {
150 conf, err := parseSharedQueryOpts(cmd, args)
151 if err != nil {
152 return err
153 }
154 if len(args) != 1 {
155 return fmt.Errorf("the module match pattern must be provided")
156 }
157
158 if formatAsDotGraph {
159 return fmt.Errorf("DOT graph output is not supported for this command")
160 }
161 if !xor(formatAsJSON, formatAsList, formatTemplate != "") {
162 return fmt.Errorf("only one of --json, --list, or --format may be specified")
163 }
164
165 updateSpinner, stopSpinner := startSpinner()
166
167 ctx, cancel := context.WithCancel(context.Background())
168 defer cancel()
169 ps := conf.getClient()
170
171 versionFilter, err := cmd.Flags().GetString("versions")
172 if err != nil {
173 logger.Error(err, "unable to read 'version' CLI flag")
174 }
175 latest, err := cmd.Flags().GetBool("latest")
176 if err != nil {
177 logger.Error(err, "unable to read 'latest' CLI flag")
178 }
179 includePrerelease, err := cmd.Flags().GetBool("include-prerelease")
180 if err != nil {
181 logger.Error(err, "unable to read 'include-prerelease' CLI flag")
182 }
183 results, err := listModuleVersions(ctx, ps, listModuleVersionsRequest{
184 modulePattern: args[0],
185 versionPattern: versionFilter,
186 latestOnly: latest,
187 includePrerelease: includePrerelease,
188 updateStatus: updateSpinner,
189 })
190 stopSpinner()
191 if err != nil {
192 return err
193 }
194 if len(results) == 0 {
195 logger.Debug("found no matching versions for matching modules", "filter", versionFilter, "module", args[0])
196 return nil
197 }
198
199 if err = writeResults(os.Stdout, results); err != nil {
200 return err
201 }
202
203 return nil
204}
205
206// runQueryModuleGraphCmd implements the logic behind the 'query ancestors' and 'query descendants' CLI sub-commands

Callers

nothing calls this directly

Calls 8

parseSharedQueryOptsFunction · 0.85
xorFunction · 0.85
startSpinnerFunction · 0.85
listModuleVersionsFunction · 0.85
writeResultsFunction · 0.85
getClientMethod · 0.80
ErrorMethod · 0.65
DebugMethod · 0.65

Tested by

no test coverage detected