elvsc

19 commits
Updated 2026-04-30 16:50:05
src/bin
src/bin/jj.rs
use elvsc::cli::{ElvscCommand, ElvscGlobal};
use jj_cli::{
    cli_util::{CliRunner, CommandHelper},
    command_error::CommandError,
    ui::Ui,
};
use jj_lib::config::ConfigLayer;

#[derive(Debug, Clone, clap::Parser)]
enum CustomCommand {
    #[command(subcommand)]
    Elvsc(ElvscCommand),
}

async fn custom_dispatch_fn(
    ui: &mut Ui,
    ch: &CommandHelper,
    cmd: CustomCommand,
) -> Result<(), CommandError> {
    match cmd {
        CustomCommand::Elvsc(cmd) => match cmd {
            ElvscCommand::Connect {
                hub,
                public,
                output,
                repo,
                reconnect,
                dry_run,
            } => {
                elvsc::commands::connect::run(
                    ui,
                    ch,
                    (&hub).into(),
                    &public,
                    (&output).into(),
                    repo.as_deref(),
                    reconnect,
                    dry_run,
                )
                .await
            }
            ElvscCommand::Update(cmd) => elvsc::commands::update::run(ui, ch, &cmd).await,
        },
    }
}

fn main() -> std::process::ExitCode {
    CliRunner::init()
        .add_global_args(|_, _: ElvscGlobal| Ok(()))
        .add_extra_config(
            ConfigLayer::parse(
                jj_lib::config::ConfigSource::Default,
                r#"
[experimental-advance-branches]
enabled-branches = ["*"]

[remotes.origin]
auto-track-bookmarks = "*"

[remotes.elvsc]
auto-track-bookmarks = "*"

[aliases]
h = ["elvsc", "update", "hub"]
r = ["elvsc", "update" , "repo"]
"#,
            )
            .expect("Couldn't parse custom configuration"),
        )
        .add_dispatch_hook(async |ui, ch, cmd| {
            cmd.call(ui, ch).await?;
            if ch.matches().get_flag("elvsc_update") {
                elvsc::commands::update::repo::run(ui, ch).await?;
            }

            Ok(())
        })
        .add_subcommand(custom_dispatch_fn)
        .run()
        .into()
}