navid/veins / bc0b02d957b7af60232a5b91bf4caefba5dfba19c68970ec43e5c39830934f19 / veinsrs/src/cli/mod.rs

mod.rs

← veinsrs/src/cli · 5308 bytes · raw · download

pub mod args;
pub mod commands;
pub mod config_cmd;
pub mod diff;
pub mod history;
pub mod info;
pub mod merge_cmd;
pub mod net_cmd;
pub mod output;
pub mod refs;
pub mod status;
pub mod worktree_cmd;

use crate::Result;

pub fn run(arguments: &[String]) -> u8 {
    match dispatch(arguments) {
        Ok(code) => code,
        Err(error) => {
            eprintln!("error: {error}");
            1
        }
    }
}

fn dispatch(arguments: &[String]) -> Result<u8> {
    let Some(command) = arguments.first() else {
        usage();
        return Ok(1);
    };
    let rest = &arguments[1..];
    match command.as_str() {
        "init" => commands::init::run(rest),
        "status" | "stat" => status::run(),
        "log" => history::log(rest),
        "show" => history::show(rest),
        "hash" => history::hash(rest),
        "ls" => history::list(rest),
        "diff" => history::diff(rest),
        "new" => history::new_change(rest),
        "desc" | "describe" => history::describe(rest),
        "go" | "commit" => history::commit(rest),
        "amend" => history::amend(rest),
        "op" => history::op(rest),
        "undo" => history::undo(),
        "co" | "checkout" => commands::checkout::run(rest),
        "bmk" => refs::bookmark(rest),
        "tag" => refs::tag(rest),
        "cfg" => config_cmd::run(rest),
        "rm" => worktree_cmd::remove(rest),
        "mv" => worktree_cmd::move_path(rest),
        "ex" => worktree_cmd::exclude(rest),
        "attr" => worktree_cmd::attr(rest),
        "edit" => worktree_cmd::edit(rest),
        "fsck" => info::fsck(rest),
        "repack" | "gc" => info::repack(rest),
        "inf" => info::inf(rest),
        "self-test" => commands::selftest::run(),
        "version" | "-version" | "-v" => info::version(),
        "merge" | "rebase" | "xs" | "resolve" => merge_cmd::run(command, rest),
        "remote" | "clone" | "fetch" | "pull" | "pl" | "push" | "psh" | "gg" | "serve" | "key"
        | "auth" | "access" | "whoami" => net_cmd::run(command, rest),
        "git" => net_cmd::git(rest),
        "help" | "-help" | "-h" => info::help(rest),
        _ => Err(crate::Error::new(format!("unknown command: {command}"))),
    }
}

fn usage() {
    println!("veins is a tool for managing source code");
    println!();
    println!("commands:");
    println!("  init         create a repository");
    println!("  git          import from or export to git");
    println!("  remote       manage native remotes");
    println!("  clone        clone a repository over the native protocol");
    println!("  fetch        fetch from a native remote");
    println!("  pull         fetch and fast-forward the current bookmark; alias: pl");
    println!("  gg           fetch the active remote, or clone a URL");
    println!("  push         push a bookmark to a native remote");
    println!("  serve        run the native server over stdio or TLS");
    println!("  key          manage local Ed25519 keys");
    println!("  auth         remember keys for hosts and set a default");
    println!("  access       manage a served repository's access file");
    println!("  whoami       report the role granted by a server");
    println!("  co           write a revision into the working directory; alias: checkout");
    println!("  stat         show working-copy changes; alias: status");
    println!("  ls           list tracked files");
    println!("  inf          show a repository breakdown");
    println!("  log          show commit history");
    println!("  show         show a commit and its diff");
    println!("  hash         print the commit hash for a revision");
    println!("  diff         show a unified diff, paged on a terminal");
    println!("  merge        create a merge commit; never fails");
    println!("  rebase       rewrite changes onto a new parent");
    println!("  xs           list conflicted paths");
    println!("  resolve      resolve a conflicted path");
    println!("  new          start a new change");
    println!("  bmk          manage named branch pointers");
    println!("  tag          manage named tags");
    println!("  cfg          read and write configuration");
    println!("  edit         open paths in the configured text editor");
    println!("  rm           untrack paths, keeping files on disk by default");
    println!("  mv           move a tracked file and record the rename");
    println!("  ex           add paths or globs to .vnexclude");
    println!("  attr         add or remove .vnattribs rules");
    println!("  desc         set the working-copy commit message; alias: describe");
    println!("  go           describe and start a new change; alias: commit");
    println!("  amend        rewrite a revision's message and its descendants");
    println!("  undo         restore the previous operation view");
    println!("  op           operation log commands");
    println!("  fsck         verify repository integrity");
    println!("  repack       rewrite packs into one delta-compressed pack; alias: gc");
    println!("  self-test    run the format self-tests");
    println!("  version      print version information");
    println!("  help         show help for a command");
    println!();
    println!("run 'vn help <command>' for details");
}