pijul 1.0.0-alpha

The sound distributed version control system.
use crate::repository::*;
use libanu::pristine::MutTxnT;
use std::path::PathBuf;

#[derive(Clap, Debug)]
pub struct Init {
    #[clap(long = "channel")]
    channel: Option<String>,
    path: Option<PathBuf>,
}

impl Init {
    pub fn run(self) -> Result<(), anyhow::Error> {
        let mut repo = Repository::init(self.path)?;
        let mut txn = repo.pristine.mut_txn_begin();
        let channel_name = self.channel.unwrap_or(crate::DEFAULT_CHANNEL.to_string());
        txn.open_or_create_channel(&channel_name)?;
        repo.config.current_channel = Some(channel_name);
        repo.save_config()?;
        txn.commit()?;
        Ok(())
    }
}