You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
vibed/nbd/.beans/nbd-9vrn--add-nbdconfigtoml...

77 lines
2.5 KiB
Markdown

---
# nbd-9vrn
title: Add .nbd/config.toml for per-project defaults
status: todo
type: feature
priority: normal
created_at: 2026-03-10T23:30:30Z
updated_at: 2026-03-10T23:30:30Z
---
## Problem
All defaults (output format, file type, default status) are hard-coded in the CLI. Users in a project that always uses `--json` or always creates `md`-format tickets must pass these flags repeatedly. A per-project config file would let them set these once.
## Config file
Location: `.nbd/config.toml` (inside the `.nbd/` root, alongside `tickets/` and `cache.db`).
Format (all keys optional — missing keys fall back to compiled defaults):
```toml
[nbd]
json = false # default: false — use tabular output
ftype = "json" # default: "json" — ticket storage format
status = "todo" # default: "todo" — initial status for new tickets
```
## Precedence (highest to lowest)
1. Explicit CLI flag (e.g., `--json`, `--ftype md`)
2. Environment variable (not in scope for this ticket)
3. `.nbd/config.toml`
4. Compiled-in default
## Implementation
**`src/store.rs`** (or a new `src/config.rs`)
Add a `NbdConfig` struct and a `load_config(root: &Path) -> NbdConfig` function:
```rust
pub struct NbdConfig {
pub json: bool,
pub ftype: FileFormat,
pub status: Status,
}
impl Default for NbdConfig { /* compiled-in defaults */ }
pub fn load_config(root: &Path) -> NbdConfig { /* read .nbd/config.toml, fall back to Default */ }
```
Parse with the `toml` crate (already in `Cargo.toml`). Errors in the config file should produce a helpful message to stderr and fall back to defaults rather than aborting.
**`src/main.rs`** — `dispatch()`
After `find_nbd_root()`, call `load_config`. Merge config values with CLI flags:
- `cli.json = cli.json || config.json` (CLI flag wins)
- For `--ftype`: if the user did not pass `--ftype`, use `config.ftype`
- For `--status` in `create`: if the user did not pass `--status`, use `config.status`
**`src/main.rs`** — `cmd_init`
After creating the tickets directory, write `.nbd/config.toml` with default values if it does not already exist.
**`tests/integration.rs`**
- Test that a config with `json = true` causes tabular commands to emit JSON.
- Test that a config with `ftype = "md"` causes `create` to write `.md` files.
- Test that explicit CLI flags override config values.
- Test idempotency of `nbd init` (does not overwrite existing config).
## Dependencies
None. Can be implemented independently of other tickets.