grove

@2 Keep config in ~/.grove2; never overwrite a config grove didn't write

by claude for antonky · landed by antonky · · from #1 · files at @2

Files

src/cli.rsmodified+15 −3
11//! The `grove` command. For now it works directly on a store on this machine; the same
22//! operations will go over HTTP once grove runs as a server.
33//!
4//! Who's acting: `~/.grove/config.json` names a person and, usually, the agent acting for them.
4//! Who's acting: `~/.grove2/config.json` names a person and, usually, the agent acting for them.
5//! (`~/.grove2`, not `~/.grove`: the old grove CLI keeps its own config in `~/.grove`.)
56//! Every command acts as that agent, except `land` and `decline`, which are decisions and act
67//! as the person. Locally this rests on trust; on a server, tokens will enforce it.
78
6667 PathBuf::from(std::env::var("HOME").unwrap_or_else(|_| ".".into()))
6768}
6869
70fn grove_home() -> PathBuf {
71 home().join(".grove2")
72}
73
6974fn config_path() -> PathBuf {
70 home().join(".grove").join("config.json")
75 grove_home().join("config.json")
7176}
7277
7378struct Config {
274279
275280fn setup(args: &Args) -> Result<()> {
276281 let username = args.pos(0).ok_or("usage: grove setup <username> [--agent NAME]")?;
277 let store_dir = args.value(&["--store"]).map(PathBuf::from).unwrap_or_else(|| home().join(".grove").join("store"));
282 // Never overwrite a config grove didn't write.
283 if let Ok(existing) = fs::read_to_string(config_path()) {
284 let ours = json::parse(&existing).map(|v| v.get("store").is_some() && v.get("person").is_some()).unwrap_or(false);
285 if !ours {
286 return e!("{} exists and isn't a grove config; move it aside first", config_path().display());
287 }
288 }
289 let store_dir = args.value(&["--store"]).map(PathBuf::from).unwrap_or_else(|| grove_home().join("store"));
278290 let mut store = Store::open(&store_dir).map_err(|e| e.to_string())?;
279291 if store.state().person(username).is_none() {
280292 s(store.add_person(username, args.value(&["--display"]).unwrap_or(username)))?;