Skip to content

Commit a2bafee

Browse files
committed
Don't include number of CPUs in generated docs
Firstly, it causes the "check for uncommitted diffs" CI step to mysteriously fail in GitHub due to mismatch in the generated docs. Here's an example of the diff in docs/modules/ROOT/pages/ec_opa_test.adoc: --p, --parallel:: the number of tests that can run in parallel, defaulting to the number of CPUs (explicitly set with 0). Benchmarks are always run sequentially. (Default: 16) +-p, --parallel:: the number of tests that can run in parallel, defaulting to the number of CPUs (explicitly set with 0). Benchmarks are always run sequentially. (Default: 4) Secondly, having the number of CPUs hard-coded in static docs does not make much sense. Notes: - Originally I implemented this workaround in the template internal/documentation/asciidoc/cli/cli.tmp which worked fine, but made the template quite messy. - See relevant opa code here: https://github.com/open-policy-agent/opa/blob/d0c0ae9730b1ecb06a29c341c707c265138f0494/cmd/test.go#L569C69-L569C76 - This is was tough one to debug! Ref: https://issues.redhat.com/browse/EC-1130
1 parent 0c34e60 commit a2bafee

2 files changed

Lines changed: 14 additions & 3 deletions

File tree

docs/modules/ROOT/pages/ec_opa_test.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ ec opa test <path> [path [...]] [flags]
9191
-h, --help:: help for test (Default: false)
9292
--ignore:: set file and directory names to ignore during loading (e.g., '.*' excludes hidden files) (Default: [])
9393
-m, --max-errors:: set the number of errors to allow before compilation fails early (Default: 10)
94-
-p, --parallel:: the number of tests that can run in parallel, defaulting to the number of CPUs (explicitly set with 0). Benchmarks are always run sequentially. (Default: 16)
94+
-p, --parallel:: the number of tests that can run in parallel, defaulting to the number of CPUs (explicitly set with 0). Benchmarks are always run sequentially.
9595
-r, --run:: run only test cases matching the regular expression
9696
-s, --schema:: set schema file path or directory path
9797
-t, --target:: set the runtime to exercise (Default: rego)

internal/documentation/asciidoc/cli/cli.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,14 @@ func options(flags *pflag.FlagSet) []option {
133133
opt := option{
134134
flag.Name,
135135
flag.Shorthand,
136-
flag.DefValue,
136+
flagDefValueMaybe(flag),
137137
flag.Usage,
138138
}
139139
result = append(result, opt)
140140
} else {
141141
opt := option{
142142
Name: flag.Name,
143-
DefaultValue: flag.DefValue,
143+
DefaultValue: flagDefValueMaybe(flag),
144144
Usage: flag.Usage,
145145
}
146146
result = append(result, opt)
@@ -149,3 +149,14 @@ func options(flags *pflag.FlagSet) []option {
149149

150150
return result
151151
}
152+
153+
func flagDefValueMaybe(flag *pflag.Flag) string {
154+
// For `ec opa test` the default value for the --parallel flag is `runtime.NumCPU()`.
155+
// We don't want to show that in the docs since it causes problems in the CI and it
156+
// also it makes no sense in static documentation.
157+
if flag.Name == "parallel" && strings.Contains(flag.Usage, "defaulting to the number of CPUs") {
158+
// Don't show the default value in the docs
159+
return ""
160+
}
161+
return flag.DefValue
162+
}

0 commit comments

Comments
 (0)