cli: set StoreFactories directly by CommandHelper::new()

This commit is contained in:
Yuya Nishihara 2023-01-04 17:16:53 +09:00
parent f89f91a18b
commit d99c299ee0

View file

@ -266,12 +266,17 @@ pub struct CommandHelper {
} }
impl CommandHelper { impl CommandHelper {
pub fn new(app: clap::Command, string_args: Vec<String>, global_args: GlobalArgs) -> Self { pub fn new(
app: clap::Command,
string_args: Vec<String>,
global_args: GlobalArgs,
store_factories: StoreFactories,
) -> Self {
Self { Self {
app, app,
string_args, string_args,
global_args, global_args,
store_factories: StoreFactories::default(), store_factories,
} }
} }
@ -287,10 +292,6 @@ impl CommandHelper {
&self.global_args &self.global_args
} }
pub fn set_store_factories(&mut self, store_factories: StoreFactories) {
self.store_factories = store_factories;
}
pub fn workspace_helper(&self, ui: &mut Ui) -> Result<WorkspaceCommandHelper, CommandError> { pub fn workspace_helper(&self, ui: &mut Ui) -> Result<WorkspaceCommandHelper, CommandError> {
let workspace = self.load_workspace(ui)?; let workspace = self.load_workspace(ui)?;
let mut workspace_command = self.resolve_operation(ui, workspace)?; let mut workspace_command = self.resolve_operation(ui, workspace)?;
@ -1752,10 +1753,12 @@ impl CliRunner {
ui.reset(crate::config::read_config()?); ui.reset(crate::config::read_config()?);
let string_args = expand_args(ui, &self.app, std::env::args_os())?; let string_args = expand_args(ui, &self.app, std::env::args_os())?;
let (matches, args) = parse_args(ui, &self.app, &self.tracing_subscription, &string_args)?; let (matches, args) = parse_args(ui, &self.app, &self.tracing_subscription, &string_args)?;
let mut command_helper = CommandHelper::new(self.app, string_args, args.global_args); let command_helper = CommandHelper::new(
if let Some(store_factories) = self.store_factories { self.app,
command_helper.set_store_factories(store_factories); string_args,
} args.global_args,
self.store_factories.unwrap_or_default(),
);
(self.dispatch_fn)(ui, &command_helper, &matches) (self.dispatch_fn)(ui, &command_helper, &matches)
} }