Skip to content

Conversation

@triarius
Copy link
Contributor

@triarius triarius commented Aug 23, 2023

This is the script cli2md.rb that generates the agent cli reference docs.
Its input is the output of buildkite-agent commands with the flag --help.

We've changed some of the practices since when this script was first written. Now:

  • We will encase code blocks in shell backtick blocks. In the input, we will use 4 spaces to indicate the start of a code block.
  • We will also replace prime signs with backticks in all the input, previously it was just the descriptions of the arguments.
  • We also remove the user's home directory from the docs, since it is not relevant to the docs.
  • We also make the state machine explicit, instead of using 2 boolean variables to control it.

There is a companion PR to adjust the cli commands in the agent to work consistently with this script. If you checkout that version of the agent, compile it and run scripts/update-agent-help.sh, it should be a no-op.

Certain help text in the agent will display the user's home directory as
part of a default value. But this does not make sense in the docs.
Now, we will encase code blocks in `shell` backtick blocks.
In the input, we will use 2 spaces for indentation, and we will use
4 spaces to indicate the start of a code block.

We also substitute prime symbols in more places. And we will prevent the
user's home directory from leaking into the docs via this script.
Previously, there was a state machine that was controlled by 2 boolean
variables. But there were only 3 valid states. Now, because the state
machine is explicit, we can avoid the invalid state.
@buildkite-docs-bot
Copy link
Contributor

Preview URL: https://2406--bk-docs-preview.netlify.app

@triarius triarius force-pushed the pdp-1465-fix-docs-script-that-parses-agent-help-text branch from 99fea56 to 9c0af63 Compare August 23, 2023 04:32
@triarius triarius requested a review from a team August 23, 2023 04:32
# Replace all prime symbols with backticks. We use prime symbols instead of backticks in CLI
# helptext because Go does not support escaping backticks in backtick delimited strings.
# See: https://github.com/buildkite/agent/blob/main/clicommand/prime-signs.md
line.tr!("′", "`")
Copy link
Contributor Author

@triarius triarius Aug 23, 2023

Choose a reason for hiding this comment

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

Woah, my browser is not rendering this very well, but you should be able to copy this into your text editor and see that is prime sign.

ARGF.each_with_index do |line, line_num|
# Headings
# Replace all prime symbols with backticks. We use prime symbols instead of backticks in CLI
# helptext because Go does not support escaping backticks in backtick delimited strings.
Copy link
Contributor

Choose a reason for hiding this comment

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

because Go does not support escaping backticks in backtick delimited strings

this is true, but not why we avoid backticks in usage strings; we actually avoid them because urfave/cli has special handling for backtick-enclosed substrings in usage docs, and mangles usage strings that have backticked strings in them

Copy link
Contributor

Choose a reason for hiding this comment

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

admittedly i probably could have put that there instead of just writing "reasons"

@triarius triarius requested a review from moskyb August 23, 2023 05:13
@triarius triarius force-pushed the pdp-1465-fix-docs-script-that-parses-agent-help-text branch from d7423a9 to bda8578 Compare August 23, 2023 05:14
@triarius triarius merged commit cb9c03a into main Aug 23, 2023
@triarius triarius deleted the pdp-1465-fix-docs-script-that-parses-agent-help-text branch August 23, 2023 06:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants