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

Function runQueryModuleGraphCmd

query.go:207–316  ·  view source on GitHub ↗

runQueryModuleGraphCmd implements the logic behind the 'query ancestors' and 'query descendants' CLI sub-commands

(cmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

205
206// runQueryModuleGraphCmd implements the logic behind the 'query ancestors' and 'query descendants' CLI sub-commands
207func runQueryModuleGraphCmd(cmd *cobra.Command, args []string) error {
208 conf, err := parseSharedQueryOpts(cmd, args)
209 if err != nil {
210 return err
211 }
212 if len(args) != 1 {
213 return fmt.Errorf("the root module name/version must be provided")
214 }
215
216 var rootMod module.Version
217 toks := strings.Split(args[0], "@")
218 switch len(toks) {
219 case 1:
220 rootMod.Path = toks[0]
221 case 2:
222 rootMod.Path = toks[0]
223 rootMod.Version = toks[1]
224 default:
225 return fmt.Errorf("invalid module path/version %q", args[0])
226 }
227 if err := module.CheckPath(rootMod.Path); err != nil {
228 return fmt.Errorf("the specified module name %q is invalid: %w", rootMod, err)
229 }
230
231 if !xor(formatAsJSON, formatAsList, formatAsDotGraph, formatTemplate != "") {
232 return fmt.Errorf("only one of --json, --list, --dot, or --format may be specified")
233 }
234
235 ctx, cancel := context.WithCancel(context.Background())
236 defer cancel()
237 ps := conf.getClient()
238
239 switch rootMod.Version {
240 case "", "latest":
241 rootMod.Version, err = lookupLatestModuleVersion(ctx, ps, rootMod.Path)
242 if err != nil {
243 return err
244 }
245 default:
246 if !semver.IsValid(rootMod.Version) {
247 return fmt.Errorf("%s is not a valid Go module semantic version string", rootMod.Version)
248 }
249 }
250
251 if maxDepth <= 0 {
252 maxDepth = 1
253 }
254 dir := perseusapi.DependencyDirection_dependencies
255 if strings.HasPrefix(cmd.Use, "descendants") {
256 dir = perseusapi.DependencyDirection_dependents
257 }
258
259 updateSpinner, stopSpinner := startSpinner()
260 tree, err := walkDependencies(ctx, ps, rootMod, dir, 1, maxDepth, updateSpinner)
261 if err != nil {
262 return err
263 }
264

Callers

nothing calls this directly

Calls 9

parseSharedQueryOptsFunction · 0.85
xorFunction · 0.85
startSpinnerFunction · 0.85
walkDependenciesFunction · 0.85
flattenTreeFunction · 0.85
generateDotGraphFunction · 0.85
getClientMethod · 0.80
NameMethod · 0.80

Tested by

no test coverage detected