mirror of
https://github.com/PR0M3TH3AN/Marlin.git
synced 2026-10-27 08:51:00 +00:00
Update CI workflow for comprehensive testing and benchmarking
Enhance the GitHub Actions CI workflow by introducing a comprehensive test job that runs a new script (`run_all_tests.sh`) for building, testing, and benchmarking. Update dependencies to use the latest actions and ensure consistent environment variables. Remove the previous build-and-test and benchmark jobs, consolidating functionality for improved clarity and efficiency.
This commit is contained in:
1 parent
0c40bdac84
commit
f8f890c29a
2 files changed
+78
-58
No files matched your search
+76
-56
@@ -1,3 +1,6 @@
|
||||
# .github/workflows/ci.yml
|
||||
# This is the full GitHub Actions workflow file.
|
||||
|
||||
name: CI
|
||||
|
||||
on:
|
||||
@@ -6,88 +9,105 @@ on:
|
||||
pull_request:
|
||||
branches: [ main ]
|
||||
|
||||
env:
|
||||
CARGO_TERM_COLOR: always
|
||||
CARGO_TARGET_DIR: ${{ github.workspace }}/target # Consistent target dir
|
||||
RUST_BACKTRACE: 1
|
||||
|
||||
jobs:
|
||||
build-and-test:
|
||||
name: Build & Test
|
||||
# This job will now run your comprehensive script
|
||||
comprehensive-tests:
|
||||
name: Comprehensive Tests & Benchmarks
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
uses: actions/checkout@v4 # Updated to v4
|
||||
|
||||
- name: Install Rust (stable)
|
||||
uses: actions-rs/toolchain@v1
|
||||
uses: actions/setup-rust@v1 # Using the official setup-rust action
|
||||
with:
|
||||
toolchain: stable
|
||||
override: true
|
||||
# Optional: enable caching
|
||||
# cache: true
|
||||
|
||||
- name: Build (release)
|
||||
run: cargo build --workspace --release
|
||||
- name: Install system prerequisites for tests and benchmarks
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y hyperfine jq bc # For benchmarks within run_all_tests.sh
|
||||
|
||||
- name: Run tests
|
||||
run: cargo test --all -- --nocapture
|
||||
- name: Ensure run_all_tests.sh is executable
|
||||
run: chmod +x ./run_all_tests.sh
|
||||
|
||||
- name: Run Comprehensive Test Script
|
||||
# This script should now handle:
|
||||
# - Building and installing Marlin
|
||||
# - Running cargo test --all
|
||||
# - Generating test corpus
|
||||
# - Running bench/dirty-vs-full.sh (produces dirty-vs-full.md)
|
||||
# - (Optional) Running the cold-start benchmark (produces perf.json or similar)
|
||||
# - Running the demo flow tests
|
||||
run: ./run_all_tests.sh
|
||||
|
||||
- name: Upload Dirty vs Full Benchmark Report
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: marlin-dirty-vs-full-benchmark-report
|
||||
path: bench/dirty-vs-full.md
|
||||
if-no-files-found: warn # Don't fail if the file isn't there, just warn
|
||||
retention-days: 7
|
||||
|
||||
# If your run_all_tests.sh now also creates perf.json for cold-start
|
||||
- name: Upload Cold Start Benchmark JSON (if generated by script)
|
||||
uses: actions/upload-artifact@v4
|
||||
if: ${{ success() }} # Only if previous steps succeed
|
||||
with:
|
||||
name: marlin-cold-start-perf-json
|
||||
path: perf.json # Assuming run_all_tests.sh now creates this
|
||||
if-no-files-found: ignore # Okay if this specific file isn't generated
|
||||
retention-days: 7
|
||||
|
||||
coverage:
|
||||
name: Code Coverage (Tarpaulin)
|
||||
needs: build-and-test
|
||||
needs: comprehensive-tests # Run after the main tests
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
- name: Install Rust (nightly)
|
||||
uses: actions-rs/toolchain@v1
|
||||
- name: Install Rust (nightly for Tarpaulin, if needed)
|
||||
uses: actions/setup-rust@v1
|
||||
with:
|
||||
toolchain: nightly
|
||||
toolchain: nightly # Or stable if Tarpaulin works well with it for your project
|
||||
override: true
|
||||
components: llvm-tools-preview # Component needed by Tarpaulin
|
||||
|
||||
- name: Install system prerequisites
|
||||
- name: Install system prerequisites for Tarpaulin
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y pkg-config libssl-dev
|
||||
|
||||
- name: Add llvm-tools (for tarpaulin)
|
||||
run: rustup component add llvm-tools-preview
|
||||
sudo apt-get install -y pkg-config libssl-dev # Keep if your build needs them
|
||||
|
||||
- name: Install cargo-tarpaulin
|
||||
run: cargo install cargo-tarpaulin
|
||||
|
||||
- name: Code Coverage (libmarlin only)
|
||||
run: cargo +nightly tarpaulin --package libmarlin --out Xml --fail-under 85
|
||||
# MARLIN_DB_PATH should be unset or point to a temp location for isolated test runs
|
||||
run: |
|
||||
unset MARLIN_DB_PATH
|
||||
cargo +nightly tarpaulin --package libmarlin --out Html --out Xml --fail-under 85
|
||||
continue-on-error: true # So the workflow doesn't fail if coverage is low during development
|
||||
|
||||
benchmark:
|
||||
name: Performance Benchmark (Hyperfine)
|
||||
needs: build-and-test
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Checkout code
|
||||
uses: actions/checkout@v3
|
||||
|
||||
- name: Install Rust (stable)
|
||||
uses: actions-rs/toolchain@v1
|
||||
- name: Upload HTML Coverage Report
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
toolchain: stable
|
||||
override: true
|
||||
name: marlin-coverage-report-html
|
||||
path: tarpaulin-report.html
|
||||
if-no-files-found: warn
|
||||
retention-days: 7
|
||||
|
||||
- name: Install benchmarking tools
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y hyperfine jq bc
|
||||
|
||||
- name: Build release binary
|
||||
run: cargo build --release
|
||||
|
||||
- name: Run cold-start benchmark
|
||||
run: |
|
||||
# measure cold start init latency
|
||||
hyperfine \
|
||||
--warmup 3 \
|
||||
--export-json perf.json \
|
||||
'target/release/marlin init'
|
||||
|
||||
- name: Enforce P95 ≤ 3s
|
||||
run: |
|
||||
p95=$(jq '.results[0].percentiles["95.00"]' perf.json)
|
||||
echo "P95 init latency: ${p95}s"
|
||||
if (( $(echo "$p95 > 3.0" | bc -l) )); then
|
||||
echo "::error ::Performance threshold exceeded (P95 > 3.0s)"
|
||||
exit 1
|
||||
fi
|
||||
- name: Upload XML Coverage Report (for services like Codecov)
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
name: marlin-coverage-report-xml
|
||||
path: cobertura.xml # Default XML output name for Tarpaulin
|
||||
if-no-files-found: warn
|
||||
retention-days: 7
|
||||
@@ -118,8 +118,8 @@
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script>
|
||||
var data = {"files":[{"path":["/","home","user","Documents","GitHub","Marlin","cli-bin","build.rs"],"content":"// cli-bin/build.rs\n//\n// The CLI currently needs no build-time code-generation, but Cargo\n// insists on rerunning any build-script each compile. Tell it to\n// rebuild only if this file itself changes.\n\nfn main() {\n // If you later add code-gen (e.g. embed completions or YAML), add\n // further `cargo:rerun-if-changed=\u003cpath\u003e` lines here.\n println!(\"cargo:rerun-if-changed=build.rs\");\n}\n","traces":[],"covered":0,"coverable":0},{"path":["/","home","user","Documents","GitHub","Marlin","cli-bin","src","cli","annotate.rs"],"content":"// src/cli/annotate.rs\nuse clap::{Subcommand, Args};\nuse rusqlite::Connection;\nuse crate::cli::Format;\n\n#[derive(Subcommand, Debug)]\npub enum AnnotateCmd {\n Add (ArgsAdd),\n List(ArgsList),\n}\n\n#[derive(Args, Debug)]\npub struct ArgsAdd {\n pub file: String,\n pub note: String,\n #[arg(long)] pub range: Option\u003cString\u003e,\n #[arg(long)] pub highlight: bool,\n}\n\n#[derive(Args, Debug)]\npub struct ArgsList { pub file_pattern: String }\n\npub fn run(cmd: \u0026AnnotateCmd, _conn: \u0026mut Connection, _format: Format) -\u003e anyhow::Result\u003c()\u003e {\n match cmd {\n AnnotateCmd::Add(a) =\u003e todo!(\"annotate add {:?}\", a),\n AnnotateCmd::List(a) =\u003e todo!(\"annotate list {:?}\", a),\n }\n}\n","traces":[{"line":23,"address":[2450848],"length":1,"stats":{"Line":0}},{"line":24,"address":[2450887],"length":1,"stats":{"Line":0}}],"covered":0,"coverable":2},{"path":["/","home","user","Documents","GitHub","Marlin","cli-bin","src","cli","coll.rs"],"content":"//! `marlin coll …` – named collections of files (simple “playlists”).\n\nuse clap::{Args, Subcommand};\nuse rusqlite::Connection;\n\nuse crate::cli::Format; // local enum for text / json output\nuse libmarlin::db; // core DB helpers from the library crate\n\n#[derive(Subcommand, Debug)]\npub enum CollCmd {\n /// Create an empty collection\n Create(CreateArgs),\n /// Add files (glob) to a collection\n Add(AddArgs),\n /// List files inside a collection\n List(ListArgs),\n}\n\n#[derive(Args, Debug)]\npub struct CreateArgs {\n pub name: String,\n}\n\n#[derive(Args, Debug)]\npub struct AddArgs {\n pub name: String,\n pub file_pattern: String,\n}\n\n#[derive(Args, Debug)]\npub struct ListArgs {\n pub name: String,\n}\n\n/// Look-up an existing collection **without** implicitly creating it.\n///\n/// Returns the collection ID or an error if it doesn’t exist.\nfn lookup_collection_id(conn: \u0026Connection, name: \u0026str) -\u003e anyhow::Result\u003ci64\u003e {\n conn.query_row(\n \"SELECT id FROM collections WHERE name = ?1\",\n [name],\n |r| r.get(0),\n )\n .map_err(|_| anyhow::anyhow!(\"collection not found: {}\", name))\n}\n\npub fn run(cmd: \u0026CollCmd, conn: \u0026mut Connection, fmt: Format) -\u003e anyhow::Result\u003c()\u003e {\n match cmd {\n /* ── coll create ──────────────────────────────────────────── */\n CollCmd::Create(a) =\u003e {\n db::ensure_collection(conn, \u0026a.name)?;\n if matches!(fmt, Format::Text) {\n println!(\"Created collection '{}'\", a.name);\n }\n }\n\n /* ── coll add ─────────────────────────────────────────────── */\n CollCmd::Add(a) =\u003e {\n // Fail if the target collection does not yet exist\n let coll_id = lookup_collection_id(conn, \u0026a.name)?;\n\n let like = a.file_pattern.replace('*', \"%\");\n let mut stmt = conn.prepare(\"SELECT id FROM files WHERE path LIKE ?1\")?;\n let ids: Vec\u003ci64\u003e = stmt\n .query_map([\u0026like], |r| r.get::\u003c_, i64\u003e(0))?\n .collect::\u003cResult\u003c_, _\u003e\u003e()?;\n\n for fid in \u0026ids {\n db::add_file_to_collection(conn, coll_id, *fid)?;\n }\n\n match fmt {\n Format::Text =\u003e println!(\"Added {} file(s) → '{}'\", ids.len(), a.name),\n Format::Json =\u003e {\n #[cfg(feature = \"json\")]\n {\n println!(\n \"{{\\\"collection\\\":\\\"{}\\\",\\\"added\\\":{}}}\",\n a.name,\n ids.len()\n );\n }\n }\n }\n }\n\n /* ── coll list ────────────────────────────────────────────── */\n CollCmd::List(a) =Line truncated
|
||||
var previousData = {"files":[{"path":["/","home","user","Documents","GitHub","Marlin","cli-bin","build.rs"],"content":"// cli-bin/build.rs\n//\n// The CLI currently needs no build-time code-generation, but Cargo\n// insists on rerunning any build-script each compile. Tell it to\n// rebuild only if this file itself changes.\n\nfn main() {\n // If you later add code-gen (e.g. embed completions or YAML), add\n // further `cargo:rerun-if-changed=\u003cpath\u003e` lines here.\n println!(\"cargo:rerun-if-changed=build.rs\");\n}\n","traces":[],"covered":0,"coverable":0},{"path":["/","home","user","Documents","GitHub","Marlin","cli-bin","src","cli","annotate.rs"],"content":"// src/cli/annotate.rs\nuse clap::{Subcommand, Args};\nuse rusqlite::Connection;\nuse crate::cli::Format;\n\n#[derive(Subcommand, Debug)]\npub enum AnnotateCmd {\n Add (ArgsAdd),\n List(ArgsList),\n}\n\n#[derive(Args, Debug)]\npub struct ArgsAdd {\n pub file: String,\n pub note: String,\n #[arg(long)] pub range: Option\u003cString\u003e,\n #[arg(long)] pub highlight: bool,\n}\n\n#[derive(Args, Debug)]\npub struct ArgsList { pub file_pattern: String }\n\npub fn run(cmd: \u0026AnnotateCmd, _conn: \u0026mut Connection, _format: Format) -\u003e anyhow::Result\u003c()\u003e {\n match cmd {\n AnnotateCmd::Add(a) =\u003e todo!(\"annotate add {:?}\", a),\n AnnotateCmd::List(a) =\u003e todo!(\"annotate list {:?}\", a),\n }\n}\n","traces":[{"line":23,"address":[2282688],"length":1,"stats":{"Line":0}},{"line":24,"address":[2282727],"length":1,"stats":{"Line":0}}],"covered":0,"coverable":2},{"path":["/","home","user","Documents","GitHub","Marlin","cli-bin","src","cli","coll.rs"],"content":"//! `marlin coll …` – named collections of files (simple “playlists”).\n\nuse clap::{Args, Subcommand};\nuse rusqlite::Connection;\n\nuse crate::cli::Format; // local enum for text / json output\nuse libmarlin::db; // core DB helpers from the library crate\n\n#[derive(Subcommand, Debug)]\npub enum CollCmd {\n /// Create an empty collection\n Create(CreateArgs),\n /// Add files (glob) to a collection\n Add(AddArgs),\n /// List files inside a collection\n List(ListArgs),\n}\n\n#[derive(Args, Debug)]\npub struct CreateArgs {\n pub name: String,\n}\n\n#[derive(Args, Debug)]\npub struct AddArgs {\n pub name: String,\n pub file_pattern: String,\n}\n\n#[derive(Args, Debug)]\npub struct ListArgs {\n pub name: String,\n}\n\n/// Look-up an existing collection **without** implicitly creating it.\n///\n/// Returns the collection ID or an error if it doesn’t exist.\nfn lookup_collection_id(conn: \u0026Connection, name: \u0026str) -\u003e anyhow::Result\u003ci64\u003e {\n conn.query_row(\n \"SELECT id FROM collections WHERE name = ?1\",\n [name],\n |r| r.get(0),\n )\n .map_err(|_| anyhow::anyhow!(\"collection not found: {}\", name))\n}\n\npub fn run(cmd: \u0026CollCmd, conn: \u0026mut Connection, fmt: Format) -\u003e anyhow::Result\u003c()\u003e {\n match cmd {\n /* ── coll create ──────────────────────────────────────────── */\n CollCmd::Create(a) =\u003e {\n db::ensure_collection(conn, \u0026a.name)?;\n if matches!(fmt, Format::Text) {\n println!(\"Created collection '{}'\", a.name);\n }\n }\n\n /* ── coll add ─────────────────────────────────────────────── */\n CollCmd::Add(a) =\u003e {\n // Fail if the target collection does not yet exist\n let coll_id = lookup_collection_id(conn, \u0026a.name)?;\n\n let like = a.file_pattern.replace('*', \"%\");\n let mut stmt = conn.prepare(\"SELECT id FROM files WHERE path LIKE ?1\")?;\n let ids: Vec\u003ci64\u003e = stmt\n .query_map([\u0026like], |r| r.get::\u003c_, i64\u003e(0))?\n .collect::\u003cResult\u003c_, _\u003e\u003e()?;\n\n for fid in \u0026ids {\n db::add_file_to_collection(conn, coll_id, *fid)?;\n }\n\n match fmt {\n Format::Text =\u003e println!(\"Added {} file(s) → '{}'\", ids.len(), a.name),\n Format::Json =\u003e {\n #[cfg(feature = \"json\")]\n {\n println!(\n \"{{\\\"collection\\\":\\\"{}\\\",\\\"added\\\":{}}}\",\n a.name,\n ids.len()\n );\n }\n }\n }\n }\n\n /* ── coll list ────────────────────────────────────────────── */\n CollCmd::LLine truncated
|
||||
var data = {"files":[{"path":["/","home","user","Documents","GitHub","Marlin","cli-bin","build.rs"],"content":"// cli-bin/build.rs\n//\n// The CLI currently needs no build-time code-generation, but Cargo\n// insists on rerunning any build-script each compile. Tell it to\n// rebuild only if this file itself changes.\n\nfn main() {\n // If you later add code-gen (e.g. embed completions or YAML), add\n // further `cargo:rerun-if-changed=\u003cpath\u003e` lines here.\n println!(\"cargo:rerun-if-changed=build.rs\");\n}\n","traces":[],"covered":0,"coverable":0},{"path":["/","home","user","Documents","GitHub","Marlin","cli-bin","src","cli","annotate.rs"],"content":"// src/cli/annotate.rs\nuse clap::{Subcommand, Args};\nuse rusqlite::Connection;\nuse crate::cli::Format;\n\n#[derive(Subcommand, Debug)]\npub enum AnnotateCmd {\n Add (ArgsAdd),\n List(ArgsList),\n}\n\n#[derive(Args, Debug)]\npub struct ArgsAdd {\n pub file: String,\n pub note: String,\n #[arg(long)] pub range: Option\u003cString\u003e,\n #[arg(long)] pub highlight: bool,\n}\n\n#[derive(Args, Debug)]\npub struct ArgsList { pub file_pattern: String }\n\npub fn run(cmd: \u0026AnnotateCmd, _conn: \u0026mut Connection, _format: Format) -\u003e anyhow::Result\u003c()\u003e {\n match cmd {\n AnnotateCmd::Add(a) =\u003e todo!(\"annotate add {:?}\", a),\n AnnotateCmd::List(a) =\u003e todo!(\"annotate list {:?}\", a),\n }\n}\n","traces":[{"line":23,"address":[2450848],"length":1,"stats":{"Line":0}},{"line":24,"address":[2450887],"length":1,"stats":{"Line":0}}],"covered":0,"coverable":2},{"path":["/","home","user","Documents","GitHub","Marlin","cli-bin","src","cli","coll.rs"],"content":"//! `marlin coll …` – named collections of files (simple “playlists”).\n\nuse clap::{Args, Subcommand};\nuse rusqlite::Connection;\n\nuse crate::cli::Format; // local enum for text / json output\nuse libmarlin::db; // core DB helpers from the library crate\n\n#[derive(Subcommand, Debug)]\npub enum CollCmd {\n /// Create an empty collection\n Create(CreateArgs),\n /// Add files (glob) to a collection\n Add(AddArgs),\n /// List files inside a collection\n List(ListArgs),\n}\n\n#[derive(Args, Debug)]\npub struct CreateArgs {\n pub name: String,\n}\n\n#[derive(Args, Debug)]\npub struct AddArgs {\n pub name: String,\n pub file_pattern: String,\n}\n\n#[derive(Args, Debug)]\npub struct ListArgs {\n pub name: String,\n}\n\n/// Look-up an existing collection **without** implicitly creating it.\n///\n/// Returns the collection ID or an error if it doesn’t exist.\nfn lookup_collection_id(conn: \u0026Connection, name: \u0026str) -\u003e anyhow::Result\u003ci64\u003e {\n conn.query_row(\n \"SELECT id FROM collections WHERE name = ?1\",\n [name],\n |r| r.get(0),\n )\n .map_err(|_| anyhow::anyhow!(\"collection not found: {}\", name))\n}\n\npub fn run(cmd: \u0026CollCmd, conn: \u0026mut Connection, fmt: Format) -\u003e anyhow::Result\u003c()\u003e {\n match cmd {\n /* ── coll create ──────────────────────────────────────────── */\n CollCmd::Create(a) =\u003e {\n db::ensure_collection(conn, \u0026a.name)?;\n if matches!(fmt, Format::Text) {\n println!(\"Created collection '{}'\", a.name);\n }\n }\n\n /* ── coll add ─────────────────────────────────────────────── */\n CollCmd::Add(a) =\u003e {\n // Fail if the target collection does not yet exist\n let coll_id = lookup_collection_id(conn, \u0026a.name)?;\n\n let like = a.file_pattern.replace('*', \"%\");\n let mut stmt = conn.prepare(\"SELECT id FROM files WHERE path LIKE ?1\")?;\n let ids: Vec\u003ci64\u003e = stmt\n .query_map([\u0026like], |r| r.get::\u003c_, i64\u003e(0))?\n .collect::\u003cResult\u003c_, _\u003e\u003e()?;\n\n for fid in \u0026ids {\n db::add_file_to_collection(conn, coll_id, *fid)?;\n }\n\n match fmt {\n Format::Text =\u003e println!(\"Added {} file(s) → '{}'\", ids.len(), a.name),\n Format::Json =\u003e {\n #[cfg(feature = \"json\")]\n {\n println!(\n \"{{\\\"collection\\\":\\\"{}\\\",\\\"added\\\":{}}}\",\n a.name,\n ids.len()\n );\n }\n }\n }\n }\n\n /* ── coll list ────────────────────────────────────────────── */\n CollCmd::List(a) =Line truncated
|
||||
var previousData = {"files":[{"path":["/","home","user","Documents","GitHub","Marlin","cli-bin","build.rs"],"content":"// cli-bin/build.rs\n//\n// The CLI currently needs no build-time code-generation, but Cargo\n// insists on rerunning any build-script each compile. Tell it to\n// rebuild only if this file itself changes.\n\nfn main() {\n // If you later add code-gen (e.g. embed completions or YAML), add\n // further `cargo:rerun-if-changed=\u003cpath\u003e` lines here.\n println!(\"cargo:rerun-if-changed=build.rs\");\n}\n","traces":[],"covered":0,"coverable":0},{"path":["/","home","user","Documents","GitHub","Marlin","cli-bin","src","cli","annotate.rs"],"content":"// src/cli/annotate.rs\nuse clap::{Subcommand, Args};\nuse rusqlite::Connection;\nuse crate::cli::Format;\n\n#[derive(Subcommand, Debug)]\npub enum AnnotateCmd {\n Add (ArgsAdd),\n List(ArgsList),\n}\n\n#[derive(Args, Debug)]\npub struct ArgsAdd {\n pub file: String,\n pub note: String,\n #[arg(long)] pub range: Option\u003cString\u003e,\n #[arg(long)] pub highlight: bool,\n}\n\n#[derive(Args, Debug)]\npub struct ArgsList { pub file_pattern: String }\n\npub fn run(cmd: \u0026AnnotateCmd, _conn: \u0026mut Connection, _format: Format) -\u003e anyhow::Result\u003c()\u003e {\n match cmd {\n AnnotateCmd::Add(a) =\u003e todo!(\"annotate add {:?}\", a),\n AnnotateCmd::List(a) =\u003e todo!(\"annotate list {:?}\", a),\n }\n}\n","traces":[{"line":23,"address":[2450848],"length":1,"stats":{"Line":0}},{"line":24,"address":[2450887],"length":1,"stats":{"Line":0}}],"covered":0,"coverable":2},{"path":["/","home","user","Documents","GitHub","Marlin","cli-bin","src","cli","coll.rs"],"content":"//! `marlin coll …` – named collections of files (simple “playlists”).\n\nuse clap::{Args, Subcommand};\nuse rusqlite::Connection;\n\nuse crate::cli::Format; // local enum for text / json output\nuse libmarlin::db; // core DB helpers from the library crate\n\n#[derive(Subcommand, Debug)]\npub enum CollCmd {\n /// Create an empty collection\n Create(CreateArgs),\n /// Add files (glob) to a collection\n Add(AddArgs),\n /// List files inside a collection\n List(ListArgs),\n}\n\n#[derive(Args, Debug)]\npub struct CreateArgs {\n pub name: String,\n}\n\n#[derive(Args, Debug)]\npub struct AddArgs {\n pub name: String,\n pub file_pattern: String,\n}\n\n#[derive(Args, Debug)]\npub struct ListArgs {\n pub name: String,\n}\n\n/// Look-up an existing collection **without** implicitly creating it.\n///\n/// Returns the collection ID or an error if it doesn’t exist.\nfn lookup_collection_id(conn: \u0026Connection, name: \u0026str) -\u003e anyhow::Result\u003ci64\u003e {\n conn.query_row(\n \"SELECT id FROM collections WHERE name = ?1\",\n [name],\n |r| r.get(0),\n )\n .map_err(|_| anyhow::anyhow!(\"collection not found: {}\", name))\n}\n\npub fn run(cmd: \u0026CollCmd, conn: \u0026mut Connection, fmt: Format) -\u003e anyhow::Result\u003c()\u003e {\n match cmd {\n /* ── coll create ──────────────────────────────────────────── */\n CollCmd::Create(a) =\u003e {\n db::ensure_collection(conn, \u0026a.name)?;\n if matches!(fmt, Format::Text) {\n println!(\"Created collection '{}'\", a.name);\n }\n }\n\n /* ── coll add ─────────────────────────────────────────────── */\n CollCmd::Add(a) =\u003e {\n // Fail if the target collection does not yet exist\n let coll_id = lookup_collection_id(conn, \u0026a.name)?;\n\n let like = a.file_pattern.replace('*', \"%\");\n let mut stmt = conn.prepare(\"SELECT id FROM files WHERE path LIKE ?1\")?;\n let ids: Vec\u003ci64\u003e = stmt\n .query_map([\u0026like], |r| r.get::\u003c_, i64\u003e(0))?\n .collect::\u003cResult\u003c_, _\u003e\u003e()?;\n\n for fid in \u0026ids {\n db::add_file_to_collection(conn, coll_id, *fid)?;\n }\n\n match fmt {\n Format::Text =\u003e println!(\"Added {} file(s) → '{}'\", ids.len(), a.name),\n Format::Json =\u003e {\n #[cfg(feature = \"json\")]\n {\n println!(\n \"{{\\\"collection\\\":\\\"{}\\\",\\\"added\\\":{}}}\",\n a.name,\n ids.len()\n );\n }\n }\n }\n }\n\n /* ── coll list ────────────────────────────────────────────── */\n CollCmd::LLine truncated
|
||||
</script>
|
||||
<script crossorigin>/** @license React v16.13.1
|
||||
* react.production.min.js
|
||||
|
||||
Reference in new issue
Block a user