Skip to content

Commit 91b78ba

Browse files
committed
refactor: 优化代码格式,调整导入顺序和函数调用的排版
1 parent 5ca88b8 commit 91b78ba

6 files changed

Lines changed: 27 additions & 39 deletions

File tree

ostool/src/bin/cargo-osrun.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ use clap::{Parser, Subcommand};
99
use colored::Colorize as _;
1010
use log::debug;
1111
use ostool::{
12-
logger,
13-
resolve_manifest_context,
14-
Tool, ToolConfig,
12+
Tool, ToolConfig, logger, resolve_manifest_context,
1513
run::{qemu, uboot::RunUbootArgs},
1614
};
1715

ostool/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ use colored::Colorize as _;
66

77
use log::info;
88
use ostool::{
9-
logger,
10-
resolve_manifest_context,
119
Tool, ToolConfig,
1210
build::{self, CargoRunnerKind},
11+
logger,
1312
menuconfig::{MenuConfigHandler, MenuConfigMode},
13+
resolve_manifest_context,
1414
run::{qemu::RunQemuArgs, uboot::RunUbootArgs},
1515
};
1616

ostool/src/run/qemu.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ use tokio::fs;
4343
use crate::{
4444
Tool,
4545
run::{
46-
output_matcher::{ByteStreamMatcher, StreamMatch, StreamMatchKind, compile_regexes, print_match_event},
46+
output_matcher::{
47+
ByteStreamMatcher, StreamMatch, StreamMatchKind, compile_regexes, print_match_event,
48+
},
4749
ovmf_prebuilt::{Arch, FileType, Prebuilt, Source},
4850
shell_init::{ShellAutoInitMatcher, normalize_shell_init_config, spawn_delayed_send},
4951
},
@@ -173,8 +175,9 @@ async fn load_or_create_qemu_config(
173175

174176
let config_content = match fs::read_to_string(&config_path).await {
175177
Ok(content) => {
176-
let mut config: QemuConfig = toml::from_str(&content)
177-
.with_context(|| format!("failed to parse QEMU config: {}", config_path.display()))?;
178+
let mut config: QemuConfig = toml::from_str(&content).with_context(|| {
179+
format!("failed to parse QEMU config: {}", config_path.display())
180+
})?;
178181
config.normalize(&format!("QEMU config {}", config_path.display()))?;
179182
return Ok(config);
180183
}
@@ -923,12 +926,8 @@ mod tests {
923926
std::fs::write(tmp.path().join("qemu-aarch64.toml"), "").unwrap();
924927
std::fs::write(tmp.path().join("qemu.toml"), "").unwrap();
925928

926-
let result = resolve_qemu_config_path_in_dir(
927-
tmp.path(),
928-
Some(Architecture::Aarch64),
929-
None,
930-
)
931-
.unwrap();
929+
let result =
930+
resolve_qemu_config_path_in_dir(tmp.path(), Some(Architecture::Aarch64), None).unwrap();
932931
assert_eq!(result, tmp.path().join("qemu-aarch64.toml"));
933932
}
934933

@@ -938,8 +937,7 @@ mod tests {
938937
std::fs::write(tmp.path().join(".qemu.toml"), "").unwrap();
939938

940939
let result =
941-
resolve_qemu_config_path_in_dir(tmp.path(), Some(Architecture::Aarch64), None)
942-
.unwrap();
940+
resolve_qemu_config_path_in_dir(tmp.path(), Some(Architecture::Aarch64), None).unwrap();
943941
assert_eq!(result, tmp.path().join(".qemu.toml"));
944942
}
945943

@@ -948,8 +946,7 @@ mod tests {
948946
let tmp = TempDir::new().unwrap();
949947

950948
let result =
951-
resolve_qemu_config_path_in_dir(tmp.path(), Some(Architecture::Aarch64), None)
952-
.unwrap();
949+
resolve_qemu_config_path_in_dir(tmp.path(), Some(Architecture::Aarch64), None).unwrap();
953950
assert_eq!(result, tmp.path().join(".qemu-aarch64.toml"));
954951
}
955952

ostool/src/run/tftp.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,7 @@ fn ensure_tftpd_hpa_service_ready(is_root: bool) -> anyhow::Result<()> {
338338
program: "systemctl".into(),
339339
args: vec!["restart".into(), "tftpd-hpa".into()],
340340
};
341-
run_privileged_command(&restart, is_root)
342-
.context("failed to restart tftpd-hpa service")?;
341+
run_privileged_command(&restart, is_root).context("failed to restart tftpd-hpa service")?;
343342

344343
if udp_port_69_is_listening()? {
345344
info!("tftpd-hpa is now listening on UDP port 69");
@@ -348,9 +347,7 @@ fn ensure_tftpd_hpa_service_ready(is_root: bool) -> anyhow::Result<()> {
348347

349348
let active = run_capture("systemctl", &["is-active", "tftpd-hpa"])
350349
.unwrap_or_else(|_| "unknown".to_string());
351-
bail!(
352-
"tftpd-hpa 服务重启后仍未监听 UDP 69(systemctl is-active: {active})"
353-
);
350+
bail!("tftpd-hpa 服务重启后仍未监听 UDP 69(systemctl is-active: {active})");
354351
}
355352

356353
bail!("未检测到可用的服务管理器,且 tftpd-hpa 当前未监听 UDP 69,请手动启动服务");

ostool/src/run/uboot.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ use uboot_shell::UbootShell;
2121
use crate::{
2222
Tool,
2323
run::{
24-
output_matcher::{ByteStreamMatcher, MATCH_DRAIN_DURATION, StreamMatchKind, compile_regexes, print_match_event},
24+
output_matcher::{
25+
ByteStreamMatcher, MATCH_DRAIN_DURATION, StreamMatchKind, compile_regexes,
26+
print_match_event,
27+
},
2528
shell_init::{ShellAutoInitMatcher, normalize_shell_init_config, spawn_delayed_send},
2629
tftp,
2730
},
@@ -128,9 +131,10 @@ impl Tool {
128131
Ok(content) => {
129132
println!("Using U-Boot config: {}", config_path.display());
130133
let config_content = replace_env_placeholders(&content)?;
131-
let mut config: UbootConfig = toml::from_str(&config_content).with_context(|| {
132-
format!("failed to parse U-Boot config: {}", config_path.display())
133-
})?;
134+
let mut config: UbootConfig =
135+
toml::from_str(&config_content).with_context(|| {
136+
format!("failed to parse U-Boot config: {}", config_path.display())
137+
})?;
134138
config.normalize(&format!("U-Boot config {}", config_path.display()))?;
135139
config
136140
}

ostool/src/tool.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
use std::{
2-
env::current_dir,
3-
ffi::OsStr,
4-
path::PathBuf,
5-
sync::Arc,
6-
};
1+
use std::{env::current_dir, ffi::OsStr, path::PathBuf, sync::Arc};
72

83
use anyhow::{Context, anyhow, bail};
94
use cargo_metadata::Metadata;
@@ -646,12 +641,9 @@ mod tests {
646641
.unwrap();
647642

648643
let package_dir = tool.resolve_package_manifest_dir("kernel").unwrap();
649-
let resolved = resolve_qemu_config_path_in_dir(
650-
&package_dir,
651-
Some(Architecture::Aarch64),
652-
None,
653-
)
654-
.unwrap();
644+
let resolved =
645+
resolve_qemu_config_path_in_dir(&package_dir, Some(Architecture::Aarch64), None)
646+
.unwrap();
655647

656648
assert_eq!(resolved, kernel_dir.join(".qemu-aarch64.toml"));
657649
}

0 commit comments

Comments
 (0)