Skip to content

Add --line-format support to collection list command#23

Merged
DanielCardonaRojas merged 4 commits intomainfrom
collection_line_format
Apr 21, 2026
Merged

Add --line-format support to collection list command#23
DanielCardonaRojas merged 4 commits intomainfrom
collection_line_format

Conversation

@DanielCardonaRojas
Copy link
Copy Markdown
Owner

@DanielCardonaRojas DanielCardonaRojas commented Apr 21, 2026

Summary

  • Add --line-format option to codemark collection list for custom output formatting
  • Support placeholders: {ID}, {NAME}, {COUNT}, {DESCRIPTION}, {CREATED}
  • Update television integration to use the new line format option
  • Simplify television integration commands by removing unnecessary cd prefix

Changes

  • src/cli/mod.rs: Add line_format field to CollectionListArgs
  • src/cli/handlers.rs: Implement custom line format rendering in handle_collection_list
  • extras/television-integration/codemark-collections.toml: Use --line-format and simplify commands

Test plan

  • All existing tests pass
  • Verified --line-format works with various placeholder combinations

Summary by CodeRabbit

  • New Features

    • Added --line-format parameter to collection list command for custom output formatting. Users can define templates with placeholders for collection ID, name, count, description, and creation date.
  • Chores

    • Refactored television integration to remove working directory navigation from commands. Updated configuration to use tab-separated formatting for consistent output parsing across listing and preview operations.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 21, 2026

Warning

Rate limit exceeded

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

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 43 minutes and 36 seconds.

⌛ 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: defaults

Review profile: CHILL

Plan: Pro

Run ID: 4d08558f-c1da-46cb-91f3-cf22a260f227

📥 Commits

Reviewing files that changed from the base of the PR and between 89e16bf and ebd1f62.

📒 Files selected for processing (5)
  • src/config.rs
  • src/engine/resolution.rs
  • src/git/context.rs
  • src/query/generator.rs
  • tests/cli_integration.rs
📝 Walkthrough

Walkthrough

The changes add a --line-format template feature to the collection list CLI command, enabling custom output formatting through placeholder substitution. This includes a new CLI argument definition, handler logic to process and render templates, and updates to the Television integration configuration to leverage the new formatting capability.

Changes

Cohort / File(s) Summary
CLI Argument Infrastructure
src/cli/mod.rs
Added optional line_format: Option<String> field to CollectionListArgs struct with documentation for supported placeholders ({ID}, {NAME}, {COUNT}, {DESCRIPTION}, {CREATED}).
Handler Logic
src/cli/handlers.rs
Implemented custom line formatting in handle_collection_list function with two code paths: (1) bookmark-specific collections iterating with {ID}, {NAME}, {DESCRIPTION}, {CREATED} placeholders, and (2) all-collections mode with additional {COUNT} placeholder. Bypasses existing OutputMode branches and writes directly to stdout via writeln!.
Television Integration Configuration
extras/television-integration/codemark-collections.toml
Removed directory-change wrapper (cd "$(dirname ...)") from collection listing and preview commands. Updated collections listing command to use --line-format "{NAME}\t{COUNT}\t{DESCRIPTION}" for tab-separated output. Modified television launch action to preserve behavior while removing directory navigation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • DanielCardonaRojas/codemark#20: Directly related—both add and wire the --line-format argument into CLI structures and handlers (handle_collection_list in src/cli/handlers.rs), with parallel updates to Television TOML configuration for custom line-format output.
  • DanielCardonaRojas/codemark#21: Related through command-line formatting and Television integration—modifies collection list line-format usage and TV TOML command fields in tandem.

Poem

🐰 A template arrives with placeholders bright,
Collections format in tabs, oh what a sight!
No more cd wrappers cluttering the way,
Just substitute and write—cleaner today! 📋✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% 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
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Add --line-format support to collection list command' is a concise, specific summary that clearly describes the primary feature added in the changeset—a new CLI option for custom output formatting.
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 collection_line_format

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: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
src/cli/handlers.rs (1)

2163-2226: ⚠️ Potential issue | 🟡 Minor

A few rough edges in the template rendering.

  1. {COUNT} leaks literally in the --bookmark branch (Lines 2165-2181). The doc/top-level help lists {COUNT} as supported, but it isn't replaced here. At minimum strip/replace it with "" in this branch so the placeholder doesn't appear in output.

  2. Value-level placeholder bleed-through. Because placeholders are replaced sequentially on the same string, any earlier substituted value that happens to contain a later placeholder (e.g. a collection name equal to "{CREATED}", or a description ending with {count}) will be re-substituted on the next .replace(..) call. Consider a single-pass formatter (e.g. small regex, or strfmt-style loop) to avoid cross-field interference.

  3. No escape expansion for \t / \n. Users invoking from a plain shell with --line-format "{NAME}\t{COUNT}" will get the literal backslash-t, not a tab. It works in the TOML in extras/television-integration/codemark-collections.toml only because TOML interprets \t at parse time. Consider expanding common escapes in the template before substitution so the CLI UX matches the TV config.

  4. Duplicated rendering logic between the two branches. Lines 2165-2181 and 2208-2226 differ only by the {COUNT} row; extracting a helper (e.g. fn render_collection_line(template, &c, count: Option<usize>) -> String) would DRY this and make it easier to keep the two code paths in sync for future placeholders.

  5. Nit: the local let short_id = output::short_id(&c.id); shadows the imported short_id function in-scope; fine here, but renaming to sid or similar avoids confusion.

Sketch of a single helper
fn render_collection_line(
    template: &str,
    c: &Collection,
    count: Option<usize>,
) -> String {
    let sid = output::short_id(&c.id);
    let desc = c.description.as_deref().unwrap_or("");
    let count_str = count.map(|n| n.to_string()).unwrap_or_default();
    // Consider a single-pass replacer here to avoid value-bleed.
    template
        .replace("{ID}", sid).replace("{id}", sid)
        .replace("{NAME}", &c.name).replace("{name}", &c.name)
        .replace("{COUNT}", &count_str).replace("{count}", &count_str)
        .replace("{DESCRIPTION}", desc).replace("{description}", desc)
        .replace("{CREATED}", &c.created_at).replace("{created}", &c.created_at)
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/cli/handlers.rs` around lines 2163 - 2226, The bookmark branch missing
{COUNT} and duplicated, bleed-prone template logic should be refactored: add a
helper fn render_collection_line(template: &str, c: &Collection, count:
Option<usize>) -> String and use it from both places (replace the inline
template blocks around the loops); inside the helper perform escape expansion on
the template (translate \t, \n, \\) then do a single-pass substitution (e.g.
iterate over placeholders with a small regex or tokenizer rather than chained
.replace) to avoid value-level bleed-through, ensure count is substituted as ""
when None (fixes the --bookmark branch), and rename the local short_id binding
to sid to avoid shadowing the output::short_id function.
extras/television-integration/codemark-collections.toml (1)

7-24: ⚠️ Potential issue | 🟡 Minor

Relative --db .codemark/codemark.db paths will fail when launched from subdirectories.

The three commands on lines 7, 12, and 24 explicitly pass relative paths to the database. When TV is launched with the current working directory in a subdirectory of the repo, these relative paths won't resolve and the commands will fail. The codemark CLI's open_db functions have git-root auto-detection via git_context::detect_context(), but that only activates when --db is omitted.

Simplest fix: drop the explicit --db flag entirely to leverage the built-in auto-detection. Alternatively, derive an absolute path from git rev-parse --show-toplevel.

Proposed diff
 [source]
-command = "codemark collection list --line-format \"{NAME}\t{COUNT}\t{DESCRIPTION}\" --db .codemark/codemark.db"
+command = "codemark collection list --line-format \"{NAME}\t{COUNT}\t{DESCRIPTION}\""
 display = "{split:\t:0}  ({split:\t:1} bookmarks)  {split:\t:2}"
 output = "{split:\t:0}"

 [preview]
-command = "codemark collection show {split:\t:0} --format table --db .codemark/codemark.db"
+command = "codemark collection show {split:\t:0} --format table"
 offset = "0"
 ...
 [actions.show]
 description = "Show bookmarks in this collection (opens television with codemark channel)"
-command = "sh -c 'tv --source-command=\"codemark list --format tv --collection $1 --db .codemark/codemark.db\" codemark' placeholder {split:\t:0}"
+command = "sh -c 'tv --source-command=\"codemark list --format tv --collection $1\" codemark' placeholder {split:\t:0}"
 mode = "execute"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@extras/television-integration/codemark-collections.toml` around lines 7 - 24,
The commands in the TOML (the root "command" value, "[preview] command", and
"[actions.show] command") pass a relative "--db .codemark/codemark.db" which
will break when launched from subdirectories; remove the explicit "--db
.codemark/codemark.db" flags so the codemark CLI's built-in git-root
auto-detection (git_context::detect_context) can find the DB, or if you prefer
an absolute path, replace the flag with a computed absolute path via `git
rev-parse --show-toplevel` before invoking the CLI; update the three command
strings (command, [preview].command, and [actions.show].command) accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Outside diff comments:
In `@extras/television-integration/codemark-collections.toml`:
- Around line 7-24: The commands in the TOML (the root "command" value,
"[preview] command", and "[actions.show] command") pass a relative "--db
.codemark/codemark.db" which will break when launched from subdirectories;
remove the explicit "--db .codemark/codemark.db" flags so the codemark CLI's
built-in git-root auto-detection (git_context::detect_context) can find the DB,
or if you prefer an absolute path, replace the flag with a computed absolute
path via `git rev-parse --show-toplevel` before invoking the CLI; update the
three command strings (command, [preview].command, and [actions.show].command)
accordingly.

In `@src/cli/handlers.rs`:
- Around line 2163-2226: The bookmark branch missing {COUNT} and duplicated,
bleed-prone template logic should be refactored: add a helper fn
render_collection_line(template: &str, c: &Collection, count: Option<usize>) ->
String and use it from both places (replace the inline template blocks around
the loops); inside the helper perform escape expansion on the template
(translate \t, \n, \\) then do a single-pass substitution (e.g. iterate over
placeholders with a small regex or tokenizer rather than chained .replace) to
avoid value-level bleed-through, ensure count is substituted as "" when None
(fixes the --bookmark branch), and rename the local short_id binding to sid to
avoid shadowing the output::short_id function.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fc2d30b0-1e92-413d-8691-52c166a25f19

📥 Commits

Reviewing files that changed from the base of the PR and between ee66e9e and 89e16bf.

📒 Files selected for processing (3)
  • extras/television-integration/codemark-collections.toml
  • src/cli/handlers.rs
  • src/cli/mod.rs

Comment thread src/cli/mod.rs
Comment on lines +496 to +498
/// Custom line format template (placeholders: {ID}, {NAME}, {COUNT}, {DESCRIPTION}, {CREATED})
#[arg(long)]
pub line_format: Option<String>,
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

Doc lists {COUNT} but it's only populated when --bookmark is not used.

handle_collection_list only substitutes {COUNT}/{count} in the "list all collections" branch; the --bookmark <id> branch (which iterates list_collections_for_bookmark) has no count and leaves {COUNT} as a literal in the output. Either document the restriction or substitute it with a sensible value (e.g. empty string or per-collection count) in the bookmark branch.

Suggested doc clarification
-    /// Custom line format template (placeholders: {ID}, {NAME}, {COUNT}, {DESCRIPTION}, {CREATED})
+    /// Custom line format template (placeholders: {ID}, {NAME}, {DESCRIPTION}, {CREATED};
+    /// additionally {COUNT} when --bookmark is not used)
     #[arg(long)]
     pub line_format: Option<String>,

@DanielCardonaRojas DanielCardonaRojas merged commit efb455f into main Apr 21, 2026
2 of 4 checks passed
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