Add migrate cli command

This commit is contained in:
Joscha 2025-02-19 13:49:58 +01:00
parent 909399b276
commit 9d2d1fa3c1
9 changed files with 31 additions and 1247 deletions

View file

@ -1,29 +0,0 @@
use std::fs;
use anyhow::Context;
use clap::Parser;
use crate::Environment;
/// Initialize a note repository.
#[derive(Debug, Parser)]
pub struct Command {
repo_name: String,
}
impl Command {
pub fn run(self, env: &Environment) -> anyhow::Result<()> {
let dir = env.paths.repo_dir(&self.repo_name);
fs::create_dir_all(&dir)
.with_context(|| format!("Failed to create directory {}", dir.display()))
.context("Failed to initialize notes repo")?;
let repo = gix::init_bare(&dir)
.with_context(|| format!("Failed to initialize bare git repo at {}", dir.display()))
.context("Failed to initialize notes repo")?;
dbg!(repo);
Ok(())
}
}

View file

@ -0,0 +1,14 @@
use clap::Parser;
use crate::Environment;
/// Create or migrate the data dir, if necessary.
#[derive(Debug, Parser)]
pub struct Command {}
impl Command {
pub fn run(self, env: &Environment) -> anyhow::Result<()> {
gdn::data::open_and_migrate(env.data_dir.clone())?;
Ok(())
}
}