forked from mirrors/jj
cli: initialize ui with merged config containing defaults and envs
Since CliRunner knows both defaults and envs, it makes sense to feed them to initialize ui.
This commit is contained in:
parent
3557622b09
commit
39d5ce97ad
2 changed files with 9 additions and 16 deletions
|
@ -1779,9 +1779,8 @@ impl CliRunner {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn run(self, ui: &mut Ui) -> Result<(), CommandError> {
|
||||
pub fn run(self, ui: &mut Ui, mut layered_configs: LayeredConfigs) -> Result<(), CommandError> {
|
||||
let cwd = env::current_dir().unwrap(); // TODO: maybe map_err to CommandError?
|
||||
let mut layered_configs = LayeredConfigs::from_environment();
|
||||
layered_configs.read_user_config()?;
|
||||
let config = layered_configs.merge();
|
||||
ui.reset(&config);
|
||||
|
@ -1807,8 +1806,9 @@ impl CliRunner {
|
|||
}
|
||||
|
||||
pub fn run_and_exit(self) -> ! {
|
||||
let mut ui = Ui::new();
|
||||
let result = self.run(&mut ui);
|
||||
let layered_configs = LayeredConfigs::from_environment();
|
||||
let mut ui = Ui::with_config(&layered_configs.merge());
|
||||
let result = self.run(&mut ui, layered_configs);
|
||||
let exit_code = handle_command_result(&mut ui, result);
|
||||
ui.finalize_writes();
|
||||
std::process::exit(exit_code);
|
||||
|
|
17
src/ui.rs
17
src/ui.rs
|
@ -106,22 +106,15 @@ fn pager_setting(config: &config::Config) -> FullCommandArgs {
|
|||
.unwrap_or_else(|_| "less -FRX".into())
|
||||
}
|
||||
|
||||
impl Default for Ui {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
}
|
||||
}
|
||||
|
||||
impl Ui {
|
||||
pub fn new() -> Ui {
|
||||
let config = crate::config::default_config();
|
||||
let color = use_color(color_setting(&config));
|
||||
let progress_indicator = progress_indicator_setting(&config);
|
||||
let formatter_factory = FormatterFactory::prepare(&config, color);
|
||||
pub fn with_config(config: &config::Config) -> Ui {
|
||||
let color = use_color(color_setting(config));
|
||||
let progress_indicator = progress_indicator_setting(config);
|
||||
let formatter_factory = FormatterFactory::prepare(config, color);
|
||||
Ui {
|
||||
color,
|
||||
formatter_factory,
|
||||
pager_cmd: pager_setting(&config),
|
||||
pager_cmd: pager_setting(config),
|
||||
paginate: PaginationChoice::Auto,
|
||||
progress_indicator,
|
||||
output: UiOutput::new_terminal(),
|
||||
|
|
Loading…
Reference in a new issue