Skip to content

cli: add --dump-ast AST output mode - #824

Merged
ewhauser merged 1 commit into
mainfrom
ewhauser/dump-ast-main
Apr 4, 2026
Merged

ewhauser merged 1 commit into
mainfrom
ewhauser/dump-ast-main

Conversation

@ewhauser

@ewhauser ewhauser commented Apr 4, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • add --dump-ast to print the parsed shell AST as pretty-printed typed JSON without executing
  • add --detect as a --dump-ast modifier that chooses the parser variant from shebang first, then file extension, else bash
  • cover the new shared CLI mode in gbash and gbash-extras, and document it in the README and SPEC

Validation

  • go test ./cli ./cmd/gbash ./contrib/extras/cmd/gbash-extras
  • make lint

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 041a6dc39c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread cli/ast_dump.go
return astDumpSource{}, exitCode, err
}

script, err := readASTDumpSessionScript(ctx, session.FileSystem(), session.Limits().MaxFileBytes, runtimeOpts.defaultWorkingDir(), parsed.ScriptPath)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Resolve AST file paths from the runtime session cwd

For --dump-ast on file inputs, relative script paths are resolved with runtimeOpts.defaultWorkingDir() instead of the runtime session’s actual working directory. This diverges whenever cli.Config.BaseOptions sets a custom working dir (for example via gbash.WithWorkingDir(...)), so --dump-ast script.sh can read the wrong file or fail with "No such file" even though normal execution in the same config can run it. The AST loader should derive path resolution from the session/runtime configuration rather than recomputing defaults from CLI flags only.

Useful? React with 👍 / 👎.

@ewhauser
ewhauser merged commit 57ccaab into main Apr 4, 2026
16 checks passed
@ewhauser
ewhauser deleted the ewhauser/dump-ast-main branch April 4, 2026 19:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant