Skip to content

feat: add default flag options #4044

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 10 commits into from
Jul 11, 2025
Merged

feat: add default flag options #4044

merged 10 commits into from
Jul 11, 2025

Conversation

RodrigoVillar
Copy link
Contributor

@RodrigoVillar RodrigoVillar commented Jun 30, 2025

Why this should be merged

As mentioned in #3996 (comment), test suites should ideally be able to set the default number of nodes for a test. Rather than extending the current RegisterFlagsWithDefaultX() pattern to support a default node count, this PR refactors setting the default flag values to use an options pattern.

How this works

Registering a flags default values is now done via RegisterFlagsWithOptions(). Calling this function without any arguments is equivalent to previously calling RegisterFlags.

How this was tested

CI

Need to be documented in RELEASES.md?

N/A

@RodrigoVillar RodrigoVillar self-assigned this Jun 30, 2025
@RodrigoVillar RodrigoVillar added the testing This primarily focuses on testing label Jun 30, 2025
@RodrigoVillar RodrigoVillar marked this pull request as ready for review July 6, 2025 18:44
@Copilot Copilot AI review requested due to automatic review settings July 6, 2025 18:44
@RodrigoVillar RodrigoVillar requested a review from maru-ava as a code owner July 6, 2025 18:45
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors flag registration to use an options pattern for default values, allowing tests to specify a default node count (and owner) when registering flags.

  • Introduces DefaultOptions and DefaultOption types with WithDefaultNodeCount/WithDefaultOwner helpers.
  • Replaces RegisterFlags and RegisterFlagsWithDefaultOwner calls with RegisterFlagsWithOptions.
  • Updates flag constructors to use the provided default node count.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/load2/main/main.go Added defaultNodeCount constant and passed it via RegisterFlagsWithOptions
tests/load/c/main/main.go Switched from RegisterFlags to RegisterFlagsWithOptions
tests/fixture/tmpnet/tmpnetctl/main.go Supplied tmpnet.DefaultNodeCount into NewStartNetworkFlagSetVars
tests/fixture/tmpnet/flags/start_network.go Extended constructors to accept defaultNodeCount and wire it through
tests/fixture/e2e/flags.go Added options pattern, but RegisterFlagsWithDefaultOwner is misimplemented
tests/e2e/e2e_test.go Updated to call RegisterFlagsWithOptions(e2e.WithDefaultOwner(...))
tests/antithesis/config.go Replaced RegisterFlags() with RegisterFlagsWithOptions()
Comments suppressed due to low confidence (2)

tests/fixture/e2e/flags.go:162

  • The RegisterFlagsWithDefaultOwner function is declared to return *FlagVars but currently returns an int. It should delegate to RegisterFlagsWithOptions, e.g.: return RegisterFlagsWithOptions(WithDefaultOwner(defaultOwner)).
}

tests/fixture/e2e/flags.go:155

  • This return statement returns an int inside RegisterFlagsWithDefaultOwner, but the function signature expects *FlagVars. Update to return the result of RegisterFlagsWithOptions instead.
	return d.nodeCount

@RodrigoVillar RodrigoVillar requested a review from maru-ava July 7, 2025 18:26
return RegisterFlagsWithDefaultOwner("")
type DefaultOption func(*DefaultOptions)

type DefaultOptions struct {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(No action required) I still think this a pretty complicated alternative to using a struct.

type Defaults struct {
  Owner     string
  NodeCount int
}
...
flags.RegisterFlags(flags.Defaults{})

@RodrigoVillar RodrigoVillar requested a review from Elvis339 July 10, 2025 19:16
@maru-ava maru-ava added this pull request to the merge queue Jul 11, 2025
Merged via the queue into master with commit d746eac Jul 11, 2025
29 checks passed
@maru-ava maru-ava deleted the tmpnet-register-defaults branch July 11, 2025 18:42
@github-project-automation github-project-automation bot moved this to Done 🎉 in avalanchego Jul 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
testing This primarily focuses on testing
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants