Skip to content

feat(dawgrun): CLI mode#84

Open
seanjSO wants to merge 3 commits into
mainfrom
seanj/dawgrun-cli
Open

feat(dawgrun): CLI mode#84
seanjSO wants to merge 3 commits into
mainfrom
seanj/dawgrun-cli

Conversation

@seanjSO
Copy link
Copy Markdown
Contributor

@seanjSO seanjSO commented May 19, 2026

Description

Adds a CLI mode to dawgrun, enabling users (and agents) to run queries, copy datasets, etc.
Note that this does not have any changes in the production path.

Type of Change

  • Chore (a change that does not modify the application functionality)
  • Bug fix (a change that fixes an issue)
  • New feature / enhancement (a change that adds new functionality)
  • Refactor (no behaviour change)
  • Test coverage
  • Build / CI / tooling
  • Documentation

Testing

  • Unit tests added / updated
  • Integration tests added / updated
  • Full test suite run (make test_all with CONNECTION_STRING set)

Screenshots (if appropriate):

Driver Impact

  • PostgreSQL driver (drivers/pg)
  • Neo4j driver (drivers/neo4j)

Checklist

  • Code is formatted
  • All existing tests pass
  • go.mod / go.sum are up to date if dependencies changed

Summary by CodeRabbit

  • New Features

    • Added CLI mode for one-shot command execution alongside interactive REPL mode.
    • Added configuration file support for saving and loading database connections via $XDG_CONFIG_HOME/dawgrun/config.json.
    • Added load-connections and save-connections commands.
    • Expanded help system with help all to display all available commands.
  • Documentation

    • Updated README with CLI/REPL modes, configuration examples, and styling behavior.

Review Change Stack

@seanjSO seanjSO self-assigned this May 19, 2026
@seanjSO seanjSO added enhancement New feature or request go Pull requests that update go code labels May 19, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 19, 2026

Warning

Rate limit exceeded

@seanjSO has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 14 minutes and 49 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 18ff46cd-2a49-4a97-98e6-ed8dc8d79555

📥 Commits

Reviewing files that changed from the base of the PR and between 3bbd653 and 975f07a.

📒 Files selected for processing (2)
  • tools/dawgrun/pkg/commands/config.go
  • tools/dawgrun/pkg/commands/db.go

Walkthrough

This PR extends dawgrun from an interactive REPL-only tool to support one-shot CLI execution with persistent connection configuration. It extracts connection state management, adds JSON config persistence, refactors command output with styled-output control, and updates existing commands to use the new abstractions.

Changes

CLI mode and config infrastructure for dawgrun

Layer / File(s) Summary
Config persistence types and connection state tracking
pkg/types/config.go, pkg/commands/commandscope.go
Config and ConnectionConfig types enable JSON-backed persistence of connections; Scope provides thread-safe tracking of open connections and their metadata, extracted from CommandContext into a reusable abstraction.
Command context enhancement with styled output and config support
pkg/commands/commandcontext.go, pkg/commands/commandcontext_test.go
CommandContext gains appConfigBaseDir field and styledOutputEnabled flag; new EnsureConnection and OpenConnection methods provide lazy/explicit connection management; output methods delegate text rendering to extracted texttools utilities.
Text rendering utilities extraction
pkg/texttools/style.go, pkg/texttools/cypher.go, pkg/commands/helpers.go
Extracts indentation and highlighting helpers into texttools.IndentLines and texttools.HighlightText; adds CypherOutputJSON and CypherOutputTable to render query results as formatted JSON or ASCII tables with terminal-aware column sizing; removes duplicate helpers from commands package.
Load and save connection configuration commands
pkg/commands/config.go, pkg/commands/config_test.go, pkg/commands/registry.go
Introduces loadConnectionsCmd and saveConnectionsCmd to manage persistent connection configuration from $XDG_CONFIG_HOME/dawgrun/config.json; resolveConfigPath helper validates and resolves config file paths; comprehensive tests cover config round-trips, legacy format compatibility, and connection workflows.
Existing command refactoring for new abstractions
pkg/commands/db.go, pkg/commands/cypher.go, pkg/commands/opengraph.go, pkg/commands/help.go, pkg/commands/runtime.go
listConnectionsCmd reports both open and configured-unopened connections; open delegates to new openConnection/openDAWGSDatabase helpers; all commands switch to EnsureConnection for safer lookups; help adds renderHelp helper and "all" subcommand; quit guards against nil instance in CLI mode.
Main entry point: CLI vs REPL routing and config initialization
cmd/dawgrun/main.go, cmd/dawgrun/main_test.go
main() routes execution to cliMain (one-shot) or replMain (interactive) based on os.Args; ensureAppConfigBaseDir and loadDefaultConfigConnectionStrings helpers centralize config initialization; new runCommand helpers construct context with appConfigBaseDir and control styled output based on terminal detection.
Documentation and configuration reference updates
.gitignore, README.md, docs/RFC.md
.gitignore uses path-specific /dawgrun ignore; README.md documents both REPL and CLI modes, adds Configuration section with sample config.json, and notes styling behavior; RFC.md describes the new CLI execution model with single-command-per-process constraint.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~50 minutes

Poem

🐰 A CLI hops beside the REPL's glow,
Config files persist as connections flow,
Styled output dances when a terminal's near,
New checkpoints guide the reviewer's cheer! 🌟

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 3.23% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: adding CLI mode functionality to dawgrun. It is concise and directly related to the primary objective of the PR.
Description check ✅ Passed The description follows the template structure with all required sections completed. It explains what the PR does, selects appropriate type(s) of change, indicates unit tests were added, and completes the checklist. All critical information is present.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch seanj/dawgrun-cli

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@tools/dawgrun/pkg/commands/config.go`:
- Around line 36-45: When loading connections in the loop that calls
openConnection for each entry in config.Connections, avoid leaving a partially
applied state by tracking successfully opened connections (e.g., opened :=
[]string{}) and on any openConnection error iterate over opened to roll them
back: call an existing teardown API (or implement one) such as
closeConnection(ctx, name) or removeConnection(name) to close resources and
remove them from the in-memory registry, then return the original error (or an
aggregated error if you prefer); update the loop around openConnection and
ensure opened is appended only after a successful open and cleaned up on error.

In `@tools/dawgrun/pkg/commands/db.go`:
- Around line 186-187: The error message currently includes the raw connStr
which may leak credentials; update the fmt.Errorf call in the DB open path (the
return using driverName and connStr) to omit or redact connStr and instead
include only safe identifiers like driverName or a connection identifier.
Replace fmt.Errorf("error opening %s database connection '%s': %w", driverName,
connStr, err) with a message that does not embed connStr (e.g. fmt.Errorf("error
opening %s database connection: %w", driverName, err)) or use a
sanitized/redacted version of connStr if you must show it.

In `@tools/dawgrun/README.md`:
- Around line 54-64: Replace the indented code examples in the README CLI
section with fenced code blocks using triple backticks and a language tag (use
"text") so markdownlint MD046 is satisfied; for each example that currently
shows lines like "dawgrun >", "dawgrun parse \"match (n) return n limit 1\"",
"dawgrun > list-connections", "dawgrun > save-connections", "dawgrun >
load-connections", and the two examples with paths, wrap the example lines with
```text and ``` (opening before the example and closing after) rather than using
indentation, and apply the same fenced-block change to the other occurrences in
the same README section.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7c3893c9-4ed3-44c8-8dee-f346eb88638a

📥 Commits

Reviewing files that changed from the base of the PR and between 0ee0b16 and 3bbd653.

📒 Files selected for processing (20)
  • tools/dawgrun/.gitignore
  • tools/dawgrun/README.md
  • tools/dawgrun/cmd/dawgrun/main.go
  • tools/dawgrun/cmd/dawgrun/main_test.go
  • tools/dawgrun/docs/RFC.md
  • tools/dawgrun/pkg/commands/commandcontext.go
  • tools/dawgrun/pkg/commands/commandcontext_test.go
  • tools/dawgrun/pkg/commands/commandscope.go
  • tools/dawgrun/pkg/commands/config.go
  • tools/dawgrun/pkg/commands/config_test.go
  • tools/dawgrun/pkg/commands/cypher.go
  • tools/dawgrun/pkg/commands/db.go
  • tools/dawgrun/pkg/commands/help.go
  • tools/dawgrun/pkg/commands/helpers.go
  • tools/dawgrun/pkg/commands/opengraph.go
  • tools/dawgrun/pkg/commands/registry.go
  • tools/dawgrun/pkg/commands/runtime.go
  • tools/dawgrun/pkg/texttools/cypher.go
  • tools/dawgrun/pkg/texttools/style.go
  • tools/dawgrun/pkg/types/config.go
💤 Files with no reviewable changes (1)
  • tools/dawgrun/pkg/commands/helpers.go

Comment thread tools/dawgrun/pkg/commands/config.go
Comment thread tools/dawgrun/pkg/commands/db.go Outdated
Comment thread tools/dawgrun/README.md
Comment on lines +54 to +64
Run without arguments to start the REPL:

dawgrun >

Pass a command and its arguments to execute that command once and exit:

dawgrun parse "match (n) return n limit 1"

CLI mode reads `$XDG_CONFIG_HOME/dawgrun/config.json` (or the platform
equivalent) if it exists, so commands can refer to configured
connection names without an interactive `open` first.
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Use fenced code blocks to satisfy markdownlint MD046.

These newly added command examples are indented code blocks, but markdownlint expects fenced blocks in this repo style (warnings at Lines 56, 60, 105, 112, 116, 120).

Suggested doc fix
-Run without arguments to start the REPL:
-
-    dawgrun >
+Run without arguments to start the REPL:
+```text
+dawgrun >
+```

-Pass a command and its arguments to execute that command once and exit:
-
-    dawgrun parse "match (n) return n limit 1"
+Pass a command and its arguments to execute that command once and exit:
+```text
+dawgrun parse "match (n) return n limit 1"
+```

-To list open and configured connection names directly:
-
-    dawgrun > list-connections
+To list open and configured connection names directly:
+```text
+dawgrun > list-connections
+```

-Save the currently open connections to the default config file:
-
-    dawgrun > save-connections
+Save the currently open connections to the default config file:
+```text
+dawgrun > save-connections
+```

-Load and open connections from the default config file:
-
-    dawgrun > load-connections
+Load and open connections from the default config file:
+```text
+dawgrun > load-connections
+```

-Both commands accept an optional config path:
-
-    dawgrun > save-connections ./dawgrun.local.json
-    dawgrun > load-connections ./dawgrun.local.json
+Both commands accept an optional config path:
+```text
+dawgrun > save-connections ./dawgrun.local.json
+dawgrun > load-connections ./dawgrun.local.json
+```

Also applies to: 103-121

🧰 Tools
🪛 markdownlint-cli2 (0.22.1)

[warning] 56-56: Code block style
Expected: fenced; Actual: indented

(MD046, code-block-style)


[warning] 60-60: Code block style
Expected: fenced; Actual: indented

(MD046, code-block-style)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tools/dawgrun/README.md` around lines 54 - 64, Replace the indented code
examples in the README CLI section with fenced code blocks using triple
backticks and a language tag (use "text") so markdownlint MD046 is satisfied;
for each example that currently shows lines like "dawgrun >", "dawgrun parse
\"match (n) return n limit 1\"", "dawgrun > list-connections", "dawgrun >
save-connections", "dawgrun > load-connections", and the two examples with
paths, wrap the example lines with ```text and ``` (opening before the example
and closing after) rather than using indentation, and apply the same
fenced-block change to the other occurrences in the same README section.

Copy link
Copy Markdown
Contributor

@kpom-specter kpom-specter left a comment

Choose a reason for hiding this comment

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

Love the direction! This sets us up for more/different way of interacting with the data

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request go Pull requests that update go code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants