Add migrate cli command
This commit is contained in:
parent
909399b276
commit
9d2d1fa3c1
9 changed files with 31 additions and 1247 deletions
|
|
@ -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(())
|
||||
}
|
||||
}
|
||||
14
gdn-cli/src/commands/migrate.rs
Normal file
14
gdn-cli/src/commands/migrate.rs
Normal 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(())
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue