forked from mirrors/jj
cli_util: allow extensions to run custom code before all commands
This commit is contained in:
parent
976b801208
commit
5326571cbd
1 changed files with 10 additions and 0 deletions
|
@ -2837,6 +2837,7 @@ pub struct CliRunner {
|
||||||
store_factories: Option<StoreFactories>,
|
store_factories: Option<StoreFactories>,
|
||||||
working_copy_factories: Option<HashMap<String, Box<dyn WorkingCopyFactory>>>,
|
working_copy_factories: Option<HashMap<String, Box<dyn WorkingCopyFactory>>>,
|
||||||
dispatch_fn: CliDispatchFn,
|
dispatch_fn: CliDispatchFn,
|
||||||
|
start_hook_fns: Vec<CliDispatchFn>,
|
||||||
process_global_args_fns: Vec<ProcessGlobalArgsFn>,
|
process_global_args_fns: Vec<ProcessGlobalArgsFn>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2857,6 +2858,7 @@ impl CliRunner {
|
||||||
store_factories: None,
|
store_factories: None,
|
||||||
working_copy_factories: None,
|
working_copy_factories: None,
|
||||||
dispatch_fn: Box::new(crate::commands::run_command),
|
dispatch_fn: Box::new(crate::commands::run_command),
|
||||||
|
start_hook_fns: vec![],
|
||||||
process_global_args_fns: vec![],
|
process_global_args_fns: vec![],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2888,6 +2890,11 @@ impl CliRunner {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn add_start_hook(mut self, start_hook_fn: CliDispatchFn) -> Self {
|
||||||
|
self.start_hook_fns.push(start_hook_fn);
|
||||||
|
self
|
||||||
|
}
|
||||||
|
|
||||||
/// Registers new subcommands in addition to the default ones.
|
/// Registers new subcommands in addition to the default ones.
|
||||||
pub fn add_subcommand<C, F>(mut self, custom_dispatch_fn: F) -> Self
|
pub fn add_subcommand<C, F>(mut self, custom_dispatch_fn: F) -> Self
|
||||||
where
|
where
|
||||||
|
@ -3001,6 +3008,9 @@ impl CliRunner {
|
||||||
self.store_factories.unwrap_or_default(),
|
self.store_factories.unwrap_or_default(),
|
||||||
working_copy_factories,
|
working_copy_factories,
|
||||||
);
|
);
|
||||||
|
for start_hook_fn in self.start_hook_fns {
|
||||||
|
start_hook_fn(ui, &command_helper)?;
|
||||||
|
}
|
||||||
(self.dispatch_fn)(ui, &command_helper)
|
(self.dispatch_fn)(ui, &command_helper)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue