Skip to content

Commit c108ce3

Browse files
committed
feat(docs): name the boolean type in the flag table
pflag.UnquoteUsage returns an empty type name for booleans, so 403 of the 1546 flag rows had a blank cell in a column headed Type. That reads as missing data and left the reader to infer that the flag takes no value. Fall back to the underlying pflag type name, so a boolean says bool. The fallback is on the empty string rather than on the bool type specifically, so any future pflag type that declines to name itself is covered too. It runs before the NoOptDefVal block, so an optional value reads as bool[=x], matching the existing string[="x"]. Regenerated all 94 command docs: no cell is empty now, every row is still a well formed three column row, and comparing against the previous output, 403 rows had an empty type become bool while the other 1143 are untouched. No flag name or description changed anywhere.
1 parent a105a30 commit c108ce3

4 files changed

Lines changed: 33 additions & 10 deletions

File tree

‎cmd/kosli/testdata/output/docs/mintlify/artifact.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ is set), registry credentials are resolved as follows:
5151
| `-t`, `--artifact-type` | string | The type of the artifact to calculate its SHA256 fingerprint. One of: [oci, docker, file, dir]. Only required if you want Kosli to calculate the fingerprint for you (i.e. when you don't specify '`--fingerprint`' on commands that allow it). |
5252
| `-b`, `--build-url` | string | The url of CI pipeline that built the artifact. (defaulted in some CIs: [docs](/integrations/ci_cd) ). |
5353
| `-u`, `--commit-url` | string | The url for the git commit that created the artifact. (defaulted in some CIs: [docs](/integrations/ci_cd) ). |
54-
| `-D`, `--dry-run` | | [optional] Run in dry-run mode. When enabled, no data is sent to Kosli and the CLI exits with 0 exit code regardless of any errors. |
54+
| `-D`, `--dry-run` | bool | [optional] Run in dry-run mode. When enabled, no data is sent to Kosli and the CLI exits with 0 exit code regardless of any errors. |
5555
| `-x`, `--exclude` | strings | [optional] The comma separated list of directories and files to exclude from fingerprinting. Can take glob patterns. Only applicable for `--artifact-type` dir. |
5656
| `-F`, `--fingerprint` | string | [conditional] The SHA256 fingerprint of the artifact. Only required if you don't specify '`--artifact-type`'. |
5757
| `-f`, `--flow` | string | The Kosli flow name. |
5858
| `-g`, `--git-commit` | string | [defaulted] The git commit from which the artifact was created. (defaulted in some CIs: [docs](/integrations/ci_cd), otherwise defaults to HEAD ). |
59-
| `-h`, `--help` | | help for artifact |
59+
| `-h`, `--help` | bool | help for artifact |
6060
| `-n`, `--name` | string | [optional] Artifact display name, if different from file, image or directory name. |
6161
| `--registry-password` | string | [conditional] The container registry password or access token. Only required if you want to read container image SHA256 digest from a remote container registry and it is not already accessible via Docker/Podman auth files or a credential helper. |
6262
| `--registry-provider` | string | [deprecated] The docker registry provider or url. Only required if you want to read docker image SHA256 digest from a remote docker registry. (DEPRECATED: no longer used) |

‎cmd/kosli/testdata/output/docs/mintlify/snyk.md‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ In other CI systems, set them explicitly to capture repository metadata.
4040
| `--attachments` | strings | [optional] The comma-separated list of paths of attachments for the reported attestation. Attachments can be files or directories. All attachments are compressed and uploaded to Kosli's evidence vault. |
4141
| `-g`, `--commit` | string | [conditional] The git commit for which the attestation is associated to. Becomes required when reporting an attestation for an artifact before reporting it to Kosli. (defaulted in some CIs: [docs](/integrations/ci_cd) ). |
4242
| `--description` | string | [optional] attestation description |
43-
| `-D`, `--dry-run` | | [optional] Run in dry-run mode. When enabled, no data is sent to Kosli and the CLI exits with 0 exit code regardless of any errors. |
43+
| `-D`, `--dry-run` | bool | [optional] Run in dry-run mode. When enabled, no data is sent to Kosli and the CLI exits with 0 exit code regardless of any errors. |
4444
| `-x`, `--exclude` | strings | [optional] The comma separated list of directories and files to exclude from fingerprinting. Can take glob patterns. Only applicable for `--artifact-type` dir. |
4545
| `--external-fingerprint` | stringToString | [optional] A SHA256 fingerprint of an external attachment represented by `--external-url`. The format is label=fingerprint (labels cannot contain '.' or '='). This flag can be set multiple times. There must be an external url with a matching label for each external fingerprint. |
4646
| `--external-url` | stringToString | [optional] Add labeled reference URL for an external resource. The format is label=url (labels cannot contain '.' or '='). This flag can be set multiple times. If the resource is a file or dir, you can optionally add its fingerprint via `--external-fingerprint` |
4747
| `-F`, `--fingerprint` | string | [conditional] The SHA256 fingerprint of the artifact to attach the attestation to. Only required if the attestation is for an artifact and `--artifact-type` and artifact name/path are not used. |
4848
| `-f`, `--flow` | string | The Kosli flow name. |
49-
| `-h`, `--help` | | help for snyk |
49+
| `-h`, `--help` | bool | help for snyk |
5050
| `-n`, `--name` | string | The name of the attestation as declared in the flow or trail yaml template. |
5151
| `-o`, `--origin-url` | string | [optional] The url pointing to where the attestation came from or is related. (defaulted to the CI url in some CIs: [docs](/integrations/ci_cd/#defaulted-kosli-command-flags-from-ci-variables) ). |
5252
| `--redact-commit-info` | strings | [optional] The list of commit info to be redacted before sending to Kosli. Allowed values are one or more of [author, message, branch]. |
@@ -60,7 +60,7 @@ In other CI systems, set them explicitly to capture repository metadata.
6060
| `--repository` | string | [conditional] The name of the repository (e.g. owner/repo-name). All three of `--repo-id`, `--repo-url` and `--repository` must be set to record repository information (defaulted in some CIs: [docs](/integrations/ci_cd) ). |
6161
| `-R`, `--scan-results` | string | The path to Snyk scan SARIF results file from 'snyk test' and 'snyk container test'. By default, the Snyk results will be uploaded to Kosli's evidence vault. |
6262
| `-T`, `--trail` | string | The Kosli trail name. |
63-
| `--upload-results` | | [defaulted] Whether to upload the provided Snyk results file as an attachment to Kosli or not. (default true) |
63+
| `--upload-results` | bool | [defaulted] Whether to upload the provided Snyk results file as an attachment to Kosli or not. (default true) |
6464
| `-u`, `--user-data` | string | [optional] The path to a JSON file containing additional data you would like to attach to the attestation. |
6565

6666

‎internal/docgen/helpers.go‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,15 @@ func CommandsInTable(f *pflag.FlagSet) string {
5353
flagName = "--" + flag.Name
5454
}
5555

56-
// varname is the value type ("string", "strings", ...) and is empty for
57-
// booleans. NoOptDefVal describes the optional-value syntax, so it is
58-
// appended here rather than to the description.
56+
// varname is the value type ("string", "strings", ...). pflag leaves it
57+
// empty for booleans, which reads as missing data in a column headed
58+
// "Type" and leaves the reader to infer that the flag takes no value, so
59+
// fall back to the underlying type name. Done before the NoOptDefVal
60+
// block so an optional value reads as bool[=x], matching string[="x"].
5961
varname, usage := pflag.UnquoteUsage(flag)
62+
if varname == "" {
63+
varname = flag.Value.Type()
64+
}
6065
if flag.NoOptDefVal != "" {
6166
switch flag.Value.Type() {
6267
case "string":

‎internal/docgen/helpers_test.go‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,26 @@ func TestCommandsInTable(t *testing.T) {
1616
if !strings.Contains(got, "| -n, --name | string | The name |") {
1717
t.Errorf("expected string type in its own column, got:\n%s", got)
1818
}
19-
if !strings.Contains(got, "| --verbose | | Enable verbose |") {
20-
t.Errorf("expected empty type column for bool flag, got:\n%s", got)
19+
// pflag leaves the type empty for booleans; the table names it anyway so a
20+
// blank cell never leaves the reader guessing what the flag takes.
21+
if !strings.Contains(got, "| --verbose | bool | Enable verbose |") {
22+
t.Errorf("expected bool type column for bool flag, got:\n%s", got)
23+
}
24+
if strings.Contains(got, "| |") {
25+
t.Errorf("expected no empty type cell, got:\n%s", got)
26+
}
27+
}
28+
29+
// TestCommandsInTableBoolOptionalValue checks the bool naming lands before the
30+
// optional-value suffix, so it reads like the string case (string[="x"]).
31+
func TestCommandsInTableBoolOptionalValue(t *testing.T) {
32+
fs := pflag.NewFlagSet("test", pflag.ContinueOnError)
33+
fs.Bool("verbose", false, "Enable verbose")
34+
fs.Lookup("verbose").NoOptDefVal = "maybe"
35+
36+
got := CommandsInTable(fs)
37+
if !strings.Contains(got, `| --verbose | bool[=maybe] | Enable verbose |`) {
38+
t.Errorf("expected bool[=maybe] in the type column, got:\n%s", got)
2139
}
2240
}
2341

0 commit comments

Comments
 (0)