runQueryModuleGraphCmd implements the logic behind the 'query ancestors' and 'query descendants' CLI sub-commands
(cmd *cobra.Command, args []string)
| 205 | |
| 206 | // runQueryModuleGraphCmd implements the logic behind the 'query ancestors' and 'query descendants' CLI sub-commands |
| 207 | func 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 |
nothing calls this directly
no test coverage detected