feat(cli): Add nibid localnet script command#2616
Conversation
PR SummaryLow Risk Overview The embedded script is a self-contained single-node localnet flow: reset chain data under
Reviewed by Cursor Bugbot for commit de55f7e. Configure here. |
There was a problem hiding this comment.
Code Review
This pull request introduces a new localnet command to nibid that embeds and outputs a shell script for running a single-node Nibiru localnet. The embedded script automates network initialization, configuration updates, and genesis setup, including seeding a canonical WNIBI contract. Review feedback suggests improving the script's robustness by adding early checks for required dependencies like jq and the nibid binary, as well as refactoring the macOS sed compatibility logic with a wrapper function to avoid creating unwanted backup files.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| SEDOPTION="" | ||
| if [[ "$OSTYPE" == "darwin"* ]]; then | ||
| SEDOPTION="''" | ||
| fi |
There was a problem hiding this comment.
On macOS, setting SEDOPTION="''" and running sed -i $SEDOPTION passes literal single quotes as the backup extension to sed because the shell does not perform quote removal on expanded variables. This results in unwanted backup files like app.toml'' being created in the configuration directory.
A cleaner, more robust, and cross-platform way to handle this is to define a wrapper function for sed that automatically handles the -i flag differences between GNU and BSD/macOS sed without needing to modify any of the downstream sed invocations.
| SEDOPTION="" | |
| if [[ "$OSTYPE" == "darwin"* ]]; then | |
| SEDOPTION="''" | |
| fi | |
| SEDOPTION="" | |
| sed() { | |
| if [[ "$1" == "-i" && "$OSTYPE" == "darwin"* ]]; then | |
| shift | |
| command sed -i '' "$@" | |
| else | |
| command sed "$@" | |
| fi | |
| } |
| echo "$1" | ||
| echo "${COLOR_RESET}" | ||
| } | ||
|
|
There was a problem hiding this comment.
To make the script more robust and user-friendly, we should add early checks for required dependencies:
BINARYCheck & Fallback: Ifnibidis not in thePATHbut exists in the current working directory (e.g., a local build), automatically fall back to./nibid. Otherwise, fail early with a clear error message.jqCheck: Sincejqis heavily used to manipulate the genesis file, the script will fail or corrupt files if it is missing. Checking for it upfront prevents partial execution failures.
| if ! which_ok "$BINARY" >/dev/null; then | |
| if [[ -f "./$(basename "$BINARY")" ]]; then | |
| BINARY="./$(basename "$BINARY")" | |
| else | |
| echo_error "Error: $BINARY is not in PATH and no local binary found in the current directory." | |
| exit 1 | |
| fi | |
| fi | |
| if ! which_ok jq >/dev/null; then | |
| echo_error "Error: jq is required but not installed. Please install jq to run this script." | |
| exit 1 | |
| fi |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
feat(cli): Add
nibid localnetscript commandAdds a
nibid localnetCLI command that ships the localnet setup script inside the binary, so developers can start a single-node localnet without hunting forcontrib/scripts/localnet.shin the repo.Key Changes
nibid localnetwith a--scriptflag that prints an embedded bash script for piping to bash:nibid localnet --script | bash; without--script, the command shows help.contrib/scripts/localnet.shtuned for CLI use: it always skips building (--no-buildis accepted for compatibility) and runs the localnet by default.contrib/scripts/localnet.shto honor aBINARYenv override and usebasenamefor process detection and cleanup, so custom binary paths work reliably.Appendix
Verification:
go test ./cmd/nibid,go run ./cmd/nibid localnet,go run ./cmd/nibid localnet --script | bash -n,git diff --check.