cli/builbo: portable option parsing with GNU getopt + getopts fallback#24
Closed
cli/builbo: portable option parsing with GNU getopt + getopts fallback#24
Conversation
…portability Co-authored-by: obnoxxx <8081179+obnoxxx@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add support for short and long options in cli/build script
cli/builbo: portable option parsing with GNU getopt + getopts fallback
Mar 15, 2026
Co-authored-by: obnoxxx <8081179+obnoxxx@users.noreply.github.com>
Contributor
Author
Collaborator
|
based on the above comment, the purpose of this PR has mostly been covered by #23 . Closing. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
cli/builboto its original state — the option parsing fix was already merged via PR cli/builbo: portable option parsing with GNU getopt + getopts fallback #24, making this PR's changes redundant.Original prompt
Rewrite the cli/builbo script so it supports both short (-b) and long (--build) options in a portable way. Achieve this by:
Preserve all original option/flag logic, including exclusive-action constraints, and maintain existing script functionality for both CI and end users on modern macOS and Linux. Test the script on both environments to confirm correct flag handling and robust error messages.
Update documentation/help text to describe the compatibility and fallback logic. Reference recent CI and user issues caused by getopt incompatibility for context (see https://github.com/TheBuildBox/buildbox/actions/runs/23117166893/job/67144640770?pr=23).
The following is the prior conversation context from the user's chat exploration (may be truncated):
User: Please find a solution for this failing job. Use the logs, job definition, and any referenced files where the failure occurred. Keep your response focused on the solution and include code suggestions when appropriate.
Assistant: The job failed because the builbo command in your workflow is passing an invalid option -b to getopt. The error log shows:
getopt: invalid option -- 'b'
error:invalid args.
According to the builbo output, for the build action you must provide the -s option, and the -b option is not recognized by getopt.
To fix the issue in your workflow (.github/workflows/ci.yml, lines 39 and 58), remove the -b flag from the builbo command. The correct usage should be:
For LaTeX (line 39):
builbo -l latex -o suse -s "make doc"
For tinyproxy (line 58):
builbo -l c -o fedora -s "./autogen.sh && make"
Update your workflow as above to resolve this job failure.
User: This must be a bug in the builbo script: -b is definitely intended to be a valid option (synonym to --build)
Assistant: You are correct: according to the builbo script, -b is intended to be a valid synonym for --build. The relevant portion of the script's usage message documents -b, and the argument parsing includes b in optstring and build in optstring_long.
However, your workflow is still failing with getopt: invalid option -- 'b'.
This suggests the bug is likely due to either:
How to fix:
Review Argument Parsing:
Check how getopt is invoked in the script after the optstring definition. Make sure it is compatible with both short (-b) and long (--build) flags.
Possible root cause:
On some platforms, the default getopt might behave differently (not supporting GNU-style long options), or the way flags are combined/parsed could trip it up.
Suggested fix for the script:
Example code suggestion for Bash:
If you want a simple solution using getopts (supporting only short options):
If you need both short/long options robustly, consider installing and using GNU getopt explicitly, and documenting that dependency.
Summary:
You can review the relevant code and usage here:
cli/builbo: argument parsing
If you want to share the getopt invocation section, I can suggest an exact fix.
User: the getopt invocation is in line 109 of the script.
Assistant: Thanks for pointing out the getopt invocation (line 101):
parsed_args=$(getopt -n "builbo" -o "$optstring" -l "$optstring_long" -- "$@")Your getopt bug root cause:
The short option string (
optstring) is:This means all of
l,r,c,o,n,s, anddexpect an argument (because of the:), whileh,b,t,eare flags and do not expect an argument.However:
If you pass
-b(intending it as a flag), but somewhere in the workflow an option argument immediately follows (e.g.,-b -s ...) and your defaultgetopt(particularly non-GNU getopt, such as on Ubuntu) does not support proper interleaving of flags and options, this triggers theinvalid option -- 'b'or, worse, tries to parse-s/make docas argum...This pull request was created from Copilot chat.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.