pijul 0.12.2

A patch-based distributed version control system, easy to use and fast. Command-line interface.
use clap::{Arg, ArgMatches, SubCommand};

use super::{default_explain, BasicOptions, StaticSubcommand};
use error::Error;

pub fn invocation() -> StaticSubcommand {
    return SubCommand::with_name("branches")
        .about("List all branches")
        .arg(
            Arg::with_name("repository")
                .long("repository")
                .help(
                    "Path to a pijul repository. Defaults to the repository containing the \
                     current directory.",
                )
                .takes_value(true),
        );
}

pub fn run(args: &ArgMatches) -> Result<(), Error> {
    let opts = BasicOptions::from_args(args)?;
    let repo = opts.open_repo()?;
    let txn = repo.txn_begin()?;
    let current_branch = opts.repo_root.get_current_branch()?;
    for branch in txn.iter_branches(None) {
        debug!("branch: {:?}", branch);
        if branch.name.as_str() == current_branch {
            println!("* {}", branch.name.as_str())
        } else {
            println!("  {}", branch.name.as_str())
        }
    }
    Ok(())
}

pub fn explain(res: Result<(), Error>) {
    default_explain(res)
}