mirror of
https://github.com/facebook/sapling.git
synced 2024-10-05 14:28:17 +03:00
Start implementing a non-oss subcommand for mononoke newadmin
Summary: As we need to add some functionality to `mononoke newadmin` that is not ready to be shared with `open-source`, extend the `subcommands` macro and adapt the `mononoke newadmin`'s `main` function to allow loading subcommands that are private to `facebook`. Reviewed By: RajivTS Differential Revision: D45398027 fbshipit-source-id: 493b24920c5310d67417274ab96e434a2bc0fbac
This commit is contained in:
parent
ae58899743
commit
b2685295b4
@ -64,5 +64,22 @@ macro_rules! subcommands {
|
||||
Err($crate::macro_export::anyhow::anyhow!("no subcommand specified"))
|
||||
}
|
||||
}
|
||||
|
||||
/// Confirm whether the subcommand this app was passed is covered by the subcommands
|
||||
/// registered in this scope.
|
||||
pub(crate) fn subcommand_is_in_scope(app: &$app) -> bool {
|
||||
use $crate::macro_export::heck::SnakeCase;
|
||||
use $crate::BaseApp;
|
||||
if let Some((name, matches)) = app.subcommand() {
|
||||
match name.to_snake_case().as_str() {
|
||||
$(
|
||||
stringify!($command) => true,
|
||||
)*
|
||||
_ => false,
|
||||
}
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -17,6 +17,8 @@ use mononoke_app::MononokeAppBuilder;
|
||||
mod bookmark_log_entry;
|
||||
mod commands;
|
||||
mod commit_id;
|
||||
#[cfg(fbcode_build)]
|
||||
mod facebook;
|
||||
|
||||
/// Administrate Mononoke
|
||||
#[derive(Parser)]
|
||||
@ -24,7 +26,16 @@ struct AdminArgs {}
|
||||
|
||||
#[fbinit::main]
|
||||
fn main(fb: FacebookInit) -> Result<()> {
|
||||
#[cfg(not(fbcode_build))]
|
||||
let subcommands = commands::subcommands();
|
||||
|
||||
#[cfg(fbcode_build)]
|
||||
let subcommands = {
|
||||
let mut subcommands = commands::subcommands();
|
||||
subcommands.extend(facebook::commands::subcommands());
|
||||
subcommands
|
||||
};
|
||||
|
||||
let app = MononokeAppBuilder::new(fb)
|
||||
.with_app_extension(ScrubAppExtension::new())
|
||||
.build_with_subcommands::<AdminArgs>(subcommands)?;
|
||||
@ -32,5 +43,17 @@ fn main(fb: FacebookInit) -> Result<()> {
|
||||
}
|
||||
|
||||
async fn async_main(app: MononokeApp) -> Result<()> {
|
||||
commands::dispatch(app).await
|
||||
#[cfg(not(fbcode_build))]
|
||||
commands::dispatch(app).await?;
|
||||
|
||||
#[cfg(fbcode_build)]
|
||||
{
|
||||
if commands::subcommand_is_in_scope(&app) {
|
||||
commands::dispatch(app).await?;
|
||||
} else if facebook::commands::subcommand_is_in_scope(&app) {
|
||||
facebook::commands::dispatch(app).await?;
|
||||
}
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user