main.rs
This file
Path
src/main.rs
76 lines · 2.0 KiB · Rust
Last changed by
Merge pull request #967 from sharkdp/codex/quantity-formattingDavid Peterbefore adoptiona6c3010
History of this fileTake it
The walk stopped after 200 commits: lines older than 13357a9 point at it.
Update CI/CDDavid Peterbefore adoption13357a9
lines 1–6why, one step back1#![cfg_attr(2 all(windows, feature = "windows_process_extensions_main_thread_handle"),3 feature(windows_process_extensions_main_thread_handle)4)]56use std::env;Handle broken pipe errors on stdout gracefully (#932)jkbefore adoptionc0b3834
line 7why, one step back7use std::io::{self, Write};Update CI/CDDavid Peterbefore adoption13357a9
lines 8–11why, one step back89use benchmark::scheduler::Scheduler;10use cli::get_cli_arguments;11use command::Commands;Handle broken pipe errors on stdout gracefully (#932)jkbefore adoptionc0b3834
line 12why, one step back12use error::ConsoleOutputError;Update CI/CDDavid Peterbefore adoption13357a9
lines 13–27why, one step back13use export::ExportManager;14use options::Options;1516use anyhow::Result;17use colored::*;1819pub mod benchmark;20pub mod cli;21pub mod command;22pub mod error;23pub mod export;24pub mod options;25pub mod outlier_detection;26pub mod output;27pub mod parameter;Merge pull request #967 from sharkdp/codex/quantity-formattingDavid Peterbefore adoptiona6c3010
line 28why, one step back28pub mod quantity;Update CI/CDDavid Peterbefore adoption13357a9
lines 29–37why, one step back29pub mod timer;30pub mod util;3132fn run() -> Result<()> {33 // Enabled ANSI colors on Windows 1034 #[cfg(windows)]35 colored::control::set_virtual_terminal(true).unwrap();3637 let cli_arguments = get_cli_arguments(env::args_os());Multiple output policiesDavid Peterbefore adoption99d24b7
line 38why, one step back38 let mut options = Options::from_cli_arguments(&cli_arguments)?;Update CI/CDDavid Peterbefore adoption13357a9
line 39why, one step back39 let commands = Commands::from_cli_arguments(&cli_arguments)?;Merge pull request #950 from Likio3000/codex/preserve-exports-on-invalid-optionsDavid Peterbefore adoptiond3d67fc
lines 40–41why, one step back40 options.validate_against_command_list(&commands)?;41SortOrder fieldDavid Peterbefore adoption038f369
lines 42–46why, one step back42 let export_manager = ExportManager::from_cli_arguments(43 &cli_arguments,44 options.time_unit,45 options.sort_order_exports,46 )?;Update CI/CDDavid Peterbefore adoption13357a9
lines 47–49why, one step back4748 let mut scheduler = Scheduler::new(&commands, &options, &export_manager);49 scheduler.run_benchmarks()?;Handle broken pipe errors on stdout gracefully (#932)jkbefore adoptionc0b3834
line 50why, one step back50 scheduler.print_relative_speed_comparison()?;Do not export intermediate results to stdout, closes #640David Peterbefore adoption2793d7b
line 51why, one step back51 scheduler.final_export()?;Update CI/CDDavid Peterbefore adoption13357a9
lines 52–55why, one step back5253 Ok(())54}55Handle broken pipe errors on stdout gracefully (#932)jkbefore adoptionc0b3834
lines 56–61why, one step back56fn caused_by_broken_console_pipe(error: &anyhow::Error) -> bool {57 error58 .downcast_ref::<ConsoleOutputError>()59 .is_some_and(|e| e.0.kind() == io::ErrorKind::BrokenPipe)60}61Update CI/CDDavid Peterbefore adoption13357a9
lines 62–65why, one step back62fn main() {63 match run() {64 Ok(_) => {}65 Err(e) => {Handle broken pipe errors on stdout gracefully (#932)jkbefore adoptionc0b3834
lines 66–72why, one step back66 // Exit quietly when a reader stops consuming console output early.67 if caused_by_broken_console_pipe(&e) {68 std::process::exit(0);69 }70 // The write to stderr can itself fail if stderr is closed; the71 // error message cannot be shown in that case anyway.72 let _ = writeln!(io::stderr(), "{} {:#}", "Error:".red(), e);Update CI/CDDavid Peterbefore adoption13357a9
lines 73–76why, one step back73 std::process::exit(1);74 }75 }76}