Skip to content

refactor: replace string registry with enum and update related logic#13

Merged
Bechma merged 1 commit intocyberfabric:mainfrom
Bechma:add-documentation
Mar 17, 2026
Merged

refactor: replace string registry with enum and update related logic#13
Bechma merged 1 commit intocyberfabric:mainfrom
Bechma:add-documentation

Conversation

@Bechma
Copy link
Collaborator

@Bechma Bechma commented Mar 17, 2026

Summary by CodeRabbit

  • Documentation

    • README retitled to "CyberFabric CLI" with updated project description
    • AGENTS guidelines clarified; added formatting/testing conditional and prefer enums for fixed-value sets
  • New Features

    • Registry selection exposed as a typed CLI option (default: crates.io) and applied across docs, resolution and cache commands
    • Tool install/upgrade accepts named tool options (Rustup, Rustfmt, Clippy)
  • Chores

    • CI workflow restricted to Rust and manifest file patterns (.rs, .toml, Cargo.lock)

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 17, 2026

📝 Walkthrough

Walkthrough

Adds a typed Registry enum and threads it through registry-related flows (docs resolver, module listing, cache paths, downloads), replaces string-based tooling with a ToolName enum-driven installer flow, narrows CI PR triggers to Rust/TOML/Cargo.lock paths, and updates README and contributor guidance text.

Changes

Cohort / File(s) Summary
CI Workflow & Guidelines
\.github/workflows/ci.yml, AGENTS.md
PR trigger restricted to Rust/TOML/Cargo.lock paths; AGENTS.md wording, punctuation, and new guideline preferring enums over strings.
Repository README
README.md
Project title changed to "CyberFabric CLI" and short description updated; doc content reworded without behavioral changes.
Registry Type
crates/cli/src/common.rs
Adds public Registry enum with ValueEnum, Default, as_str(), and Display.
Docs Resolver & Cache
crates/cli/src/docs/mod.rs
Replaces String/&str registry uses with Registry; updates Resolver field types, resolve/cache/download function signatures, path helpers, sanitization, and tests to accept/return Registry-based values.
Module Listing & Fetch
crates/cli/src/config/modules/list.rs
List args use Registry; replaces crates.io-specific logic with registry-aware calls; updates fetch functions and URLs to accept and interpolate Registry.
Tooling Refactor
crates/cli/src/tools/mod.rs
Replaces Tool struct with ToolName and InstallMethod enums; CLI args accept ToolName; installation/upgrade flows and checks updated to enum-driven behavior; PATH helpers removed.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant CLI as "cf-cli (List/Docs)"
  participant Resolver
  participant Cache
  participant Remote as "Registry HTTP"

  User->>CLI: run list/docs --registry <registry>
  CLI->>Resolver: resolve with Registry
  Resolver->>Cache: check registry cache (registry-specific path)
  alt cache hit
    Cache-->>Resolver: return cached crate/source
  else cache miss
    Resolver->>Remote: fetch metadata & module.rs from https://{registry}/...
    Remote-->>Resolver: metadata + module.rs
    Resolver->>Cache: write registry-scoped cache
  end
  Resolver-->>CLI: resolved module(s)/docs
  CLI-->>User: display results
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Poem

🐰 I hopped through code with tiny feet,
Swapped loose strings for variants neat.
Tools found names, the CLI sings,
CI watches fewer things.
🥕 A happy hop — registry springs!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 5.88% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the primary change: replacing string-based registry handling with a strongly-typed enum throughout the codebase, including updates to related logic in multiple modules.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
📝 Coding Plan
  • Generate coding plan for human review comments

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
Contributor

@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: 2

🧹 Nitpick comments (2)
README.md (1)

72-72: Clarify tool name: cargofmt vs rustfmt.

The documentation mentions cargofmt, but the actual tool being installed/checked is rustfmt (a rustup component). Consider using rustfmt here to match what users will see installed, or clarify that cargofmt is the CLI argument name that installs rustfmt.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@README.md` at line 72, Update the README wording so the tool name matches
what's actually installed: replace or clarify the `cargofmt` mention with
`rustfmt` (or explicitly state that the CLI flag `cargofmt` installs the
`rustfmt` rustup component). Ensure the sentence referencing `tools` and the
install/upgrade list mentions `rustfmt` so users see the same tool name that
will be installed, or add a parenthetical note linking `cargofmt` -> `rustfmt`.
crates/cli/src/docs/mod.rs (1)

304-310: Consider updating the hardcoded error message.

The error message on line 307 specifically mentions "crates.io registry" while the function now accepts a generic Registry parameter. Consider using the registry's display representation for consistency:

Proposed fix
     } else {
         fetch_exact_crates_io_candidate(client, registry, crate_name)
             .await?
             .with_context(|| {
-                format!("could not resolve package '{crate_name}' from the crates.io registry")
+                format!("could not resolve package '{crate_name}' from the {registry} registry")
             })?
             .max_version
     };
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/cli/src/docs/mod.rs` around lines 304 - 310, The error message is
hardcoded to "crates.io registry" but the call to
fetch_exact_crates_io_candidate(client, registry, crate_name) accepts a generic
Registry; update the with_context closure to include the registry's display
instead of the fixed string by formatting the message with crate_name and the
registry (e.g., use registry's Display/ToString) so the context reads like
"could not resolve package '{crate_name}' from registry '{registry}'"; locate
the call to fetch_exact_crates_io_candidate and modify its with_context
formatting accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.github/workflows/ci.yml:
- Around line 6-9: The CI workflow's paths filter currently only includes
Rust/TOML/lockfile patterns under the YAML key paths, so changes to workflow
files under .github/workflows can skip running this pipeline; update the paths
list in the ci.yml workflow (the YAML key "paths" and its current glob entries)
to also include workflow file globs (e.g., add a pattern matching
.github/workflows/**/*.yml or .github/**) or remove the "paths" restriction
entirely so edits to workflow files will trigger the pipeline.

In `@crates/cli/src/config/modules/list.rs`:
- Around line 31-32: The registry field on the command struct (registry:
Registry) is unused in run(); either remove the field or wire it up consistently
with docs/mod.rs: update run() to accept and pass the selected Registry into the
metadata fetcher/resolver instead of calling fetch_all_crates_io_metadata() with
no args — e.g., replace the direct call to fetch_all_crates_io_metadata() with a
call that accepts the Registry or call the resolver used in docs (passing
registry) and also pass registry into clean_registry_cache()/fetch helper;
alternatively remove the unused registry field and its arg attribute if
multi-registry support is not intended.

---

Nitpick comments:
In `@crates/cli/src/docs/mod.rs`:
- Around line 304-310: The error message is hardcoded to "crates.io registry"
but the call to fetch_exact_crates_io_candidate(client, registry, crate_name)
accepts a generic Registry; update the with_context closure to include the
registry's display instead of the fixed string by formatting the message with
crate_name and the registry (e.g., use registry's Display/ToString) so the
context reads like "could not resolve package '{crate_name}' from registry
'{registry}'"; locate the call to fetch_exact_crates_io_candidate and modify its
with_context formatting accordingly.

In `@README.md`:
- Line 72: Update the README wording so the tool name matches what's actually
installed: replace or clarify the `cargofmt` mention with `rustfmt` (or
explicitly state that the CLI flag `cargofmt` installs the `rustfmt` rustup
component). Ensure the sentence referencing `tools` and the install/upgrade list
mentions `rustfmt` so users see the same tool name that will be installed, or
add a parenthetical note linking `cargofmt` -> `rustfmt`.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: c33f79bf-e5ae-430a-bf57-9c56ffc104c0

📥 Commits

Reviewing files that changed from the base of the PR and between 58f9e0c and 9f24787.

📒 Files selected for processing (7)
  • .github/workflows/ci.yml
  • AGENTS.md
  • README.md
  • crates/cli/src/common.rs
  • crates/cli/src/config/modules/list.rs
  • crates/cli/src/docs/mod.rs
  • crates/cli/src/tools/mod.rs

@Bechma Bechma force-pushed the add-documentation branch from 9f24787 to 6693bd6 Compare March 17, 2026 15:41
Copy link
Contributor

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@crates/cli/src/tools/mod.rs`:
- Around line 111-123: The prereq check currently uses
is_installed(tool.check_binary()) and then immediately bails for
InstallMethod::Prerequisite, which misses the ensure_rustup fallback
(~/.cargo/bin/rustup) used elsewhere; update the logic so that before bailing
for InstallMethod::Prerequisite you call or leverage ensure_rustup() (or extend
is_installed to check the same fallback path) to verify rustup via the fallback
location and only bail if both PATH and the ensure_rustup fallback fail—refer to
is_installed, tool.check_binary(), ensure_rustup, and
InstallMethod::Prerequisite to locate and change the check.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d3e6b9b8-3730-4221-af31-77d9bfae6997

📥 Commits

Reviewing files that changed from the base of the PR and between 9f24787 and 6693bd6.

📒 Files selected for processing (7)
  • .github/workflows/ci.yml
  • AGENTS.md
  • README.md
  • crates/cli/src/common.rs
  • crates/cli/src/config/modules/list.rs
  • crates/cli/src/docs/mod.rs
  • crates/cli/src/tools/mod.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • README.md
  • .github/workflows/ci.yml

@Bechma Bechma force-pushed the add-documentation branch from 6693bd6 to b0c0cfc Compare March 17, 2026 19:15
Copy link
Contributor

@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

♻️ Duplicate comments (1)
crates/cli/src/tools/mod.rs (1)

191-195: ⚠️ Potential issue | 🟠 Major

PATH-only recheck breaks fresh rustup installs.

install_rustup() runs in a child process, so a successful install cannot update this process's PATH. On hosts where ~/.cargo/bin was not already exported, this branch bails immediately after install and the later rustup invocations never run. Reuse a resolved rustup path here instead of re-checking PATH only.

#!/bin/bash
set -euo pipefail
# Verify that rustup is only validated/invoked via PATH in the current flow.
rg -n -C2 'fn ensure_rustup|install_rustup\(|is_installed\("rustup"\)|Command::new\("rustup"\)|cargo_bin_path|\.cargo/bin' crates/cli/src/tools/mod.rs
# Expected: the output shows PATH-only checks and direct "rustup" invocations,
# with no fallback path reused after auto-install.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/cli/src/tools/mod.rs` around lines 191 - 195, The current logic bails
if is_installed("rustup") fails, which breaks when install_rustup() ran in a
child process and updated ~/.cargo/bin only for new shells; instead, after
calling install_rustup() or when detecting a successful installation, resolve
the rustup binary path (e.g., by checking the concrete path under
cargo_bin_path() or using a which/lookup helper) and reuse that resolved path
for subsequent rustup invocations rather than re-checking PATH; change the
branch that currently calls bail! when is_installed("rustup") is false to accept
a resolved rustup_path (from install_rustup or cargo_bin_path()) and only bail
if neither a PATH lookup nor a concrete resolved path is available so subsequent
calls use the known rustup_path.
🧹 Nitpick comments (1)
crates/cli/src/docs/mod.rs (1)

713-717: Rename the helper to match the new abstraction.

fetch_exact_crates_io_candidate now accepts a generic Registry, so the current name reads like a leftover special-case. A registry-neutral name would make the new flow easier to follow.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/cli/src/docs/mod.rs` around lines 713 - 717, The helper function
fetch_exact_crates_io_candidate is misleading because it now accepts a generic
Registry; rename it (and all its call sites) to a registry-neutral identifier
such as fetch_exact_registry_candidate or fetch_exact_candidate to reflect the
new abstraction, updating the function declaration, any imports/usages, and
documentation/comments that reference fetch_exact_crates_io_candidate so
compilation and call semantics remain consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@crates/cli/src/config/modules/list.rs`:
- Around line 30-32: Update the field doc comment for the registry argument (the
registry: Registry field with #[arg(long, value_enum, default_value_t =
Registry::CratesIo)]) to clearly state that the --registry flag is only
consulted when both --system and --verbose are enabled (i.e., the --verbose path
alone does not query the registry); reference the Registry enum in the help text
so users know the allowed values and keep the existing default value behavior.

---

Duplicate comments:
In `@crates/cli/src/tools/mod.rs`:
- Around line 191-195: The current logic bails if is_installed("rustup") fails,
which breaks when install_rustup() ran in a child process and updated
~/.cargo/bin only for new shells; instead, after calling install_rustup() or
when detecting a successful installation, resolve the rustup binary path (e.g.,
by checking the concrete path under cargo_bin_path() or using a which/lookup
helper) and reuse that resolved path for subsequent rustup invocations rather
than re-checking PATH; change the branch that currently calls bail! when
is_installed("rustup") is false to accept a resolved rustup_path (from
install_rustup or cargo_bin_path()) and only bail if neither a PATH lookup nor a
concrete resolved path is available so subsequent calls use the known
rustup_path.

---

Nitpick comments:
In `@crates/cli/src/docs/mod.rs`:
- Around line 713-717: The helper function fetch_exact_crates_io_candidate is
misleading because it now accepts a generic Registry; rename it (and all its
call sites) to a registry-neutral identifier such as
fetch_exact_registry_candidate or fetch_exact_candidate to reflect the new
abstraction, updating the function declaration, any imports/usages, and
documentation/comments that reference fetch_exact_crates_io_candidate so
compilation and call semantics remain consistent.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: fcd67e83-8202-4008-85fd-3f2bc9594e92

📥 Commits

Reviewing files that changed from the base of the PR and between 6693bd6 and b0c0cfc.

📒 Files selected for processing (7)
  • .github/workflows/ci.yml
  • AGENTS.md
  • README.md
  • crates/cli/src/common.rs
  • crates/cli/src/config/modules/list.rs
  • crates/cli/src/docs/mod.rs
  • crates/cli/src/tools/mod.rs
🚧 Files skipped from review as they are similar to previous changes (2)
  • .github/workflows/ci.yml
  • README.md

Signed-off-by: Bechma <19294519+Bechma@users.noreply.github.com>
@Bechma Bechma force-pushed the add-documentation branch from b0c0cfc to 7fc9447 Compare March 17, 2026 19:51
Copy link
Contributor

@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.

♻️ Duplicate comments (1)
crates/cli/src/tools/mod.rs (1)

107-123: ⚠️ Potential issue | 🟠 Major

Rustup availability check can still fail right after auto-install.

Line 111 only checks PATH. If ensure_rustup installs rustup under cargo’s bin path but PATH is not refreshed in-process, Line 119 can still bail incorrectly and downstream rustup component commands may fail.

🔧 Suggested fix
 fn ensure_rustup(yolo: bool) -> anyhow::Result<()> {
-    if is_installed("rustup") {
+    if is_rustup_available() {
         return Ok(());
     }
@@
     println!("Installing rustup...");
     install_rustup().context("failed to install rustup")?;
+    if !is_rustup_available() {
+        bail!("rustup was installed but is not discoverable in this shell; ensure cargo bin is on PATH");
+    }
     println!("✓ rustup installed");
     Ok(())
 }
 
+fn is_rustup_available() -> bool {
+    if is_installed("rustup") {
+        return true;
+    }
+    let exe = if cfg!(windows) { "rustup.exe" } else { "rustup" };
+    std::env::var_os("HOME")
+        .map(std::path::PathBuf::from)
+        .map(|home| home.join(".cargo").join("bin").join(exe))
+        .map(|path| path.to_string_lossy().into_owned())
+        .as_deref()
+        .is_some_and(is_installed)
+}
@@
-            let installed = is_installed(tool.check_binary());
+            let installed = match tool {
+                ToolName::Rustup => is_rustup_available(),
+                _ => is_installed(tool.check_binary()),
+            };
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@crates/cli/src/tools/mod.rs` around lines 107 - 123, install_tools currently
calls ensure_rustup(self.yolo) but then only checks PATH once via
is_installed(tool.check_binary()), which can cause a false-negative if rustup
was just installed and the process PATH wasn't refreshed; update install_tools
to re-check rustup availability after ensure_rustup (e.g., call
is_installed("rustup") or re-run the binary check used by is_installed) before
bailing in the InstallMethod::Prerequisite branch and before attempting
RustupComponent installs (referencing install_tools, ensure_rustup,
is_installed, tool.install_method, InstallMethod::Prerequisite,
InstallMethod::RustupComponent) so that a freshly-installed rustup is detected
and the code only bails when rustup truly cannot be found.
🧹 Nitpick comments (1)
AGENTS.md (1)

3-10: Optional: reduce repeated “Always …” phrasing for readability.

Consider converting these lines into a short bullet list with parallel phrasing; it will scan faster.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@AGENTS.md` around lines 3 - 10, Refactor the repeated "Always ..." sentences
into a concise bullet list with parallel phrasing for readability: replace the
four sentences with bullets like "Use cargo clippy", "Format code with cargo fmt
and run cargo test when touching Rust code", "Use cargo add instead of editing
Cargo.toml", and "Prefer enums over strings when values are fixed"; keep the
same guidance but remove the repeated "Always" preface and ensure punctuation
and capitalization are consistent.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@crates/cli/src/tools/mod.rs`:
- Around line 107-123: install_tools currently calls ensure_rustup(self.yolo)
but then only checks PATH once via is_installed(tool.check_binary()), which can
cause a false-negative if rustup was just installed and the process PATH wasn't
refreshed; update install_tools to re-check rustup availability after
ensure_rustup (e.g., call is_installed("rustup") or re-run the binary check used
by is_installed) before bailing in the InstallMethod::Prerequisite branch and
before attempting RustupComponent installs (referencing install_tools,
ensure_rustup, is_installed, tool.install_method, InstallMethod::Prerequisite,
InstallMethod::RustupComponent) so that a freshly-installed rustup is detected
and the code only bails when rustup truly cannot be found.

---

Nitpick comments:
In `@AGENTS.md`:
- Around line 3-10: Refactor the repeated "Always ..." sentences into a concise
bullet list with parallel phrasing for readability: replace the four sentences
with bullets like "Use cargo clippy", "Format code with cargo fmt and run cargo
test when touching Rust code", "Use cargo add instead of editing Cargo.toml",
and "Prefer enums over strings when values are fixed"; keep the same guidance
but remove the repeated "Always" preface and ensure punctuation and
capitalization are consistent.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 6d1018c7-a99c-4fda-bbb6-8480222360d3

📥 Commits

Reviewing files that changed from the base of the PR and between b0c0cfc and 7fc9447.

📒 Files selected for processing (7)
  • .github/workflows/ci.yml
  • AGENTS.md
  • README.md
  • crates/cli/src/common.rs
  • crates/cli/src/config/modules/list.rs
  • crates/cli/src/docs/mod.rs
  • crates/cli/src/tools/mod.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/ci.yml

@Bechma Bechma merged commit 0d288f5 into cyberfabric:main Mar 17, 2026
2 checks passed
@Bechma Bechma deleted the add-documentation branch March 17, 2026 20:25
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