Skip to content

Commit 2168230

Browse files
committed
refactor: more cleanup
1 parent b160f91 commit 2168230

File tree

3 files changed

+50
-54
lines changed

3 files changed

+50
-54
lines changed

src/lib.rs

Lines changed: 48 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -126,32 +126,30 @@ impl<'a> FlatpakManager<'a> {
126126
buildsystem,
127127
config_opts,
128128
build_commands,
129+
post_install,
129130
..
130-
} => match buildsystem.as_deref() {
131-
Some("meson") => self.run_meson(repo_dir_str, config_opts.as_ref())?,
132-
Some("cmake") | Some("cmake-ninja") => {
133-
self.run_cmake(repo_dir_str, config_opts.as_ref())?
131+
} => {
132+
match buildsystem.as_deref() {
133+
Some("meson") => self.run_meson(repo_dir_str, config_opts.as_ref())?,
134+
Some("cmake") | Some("cmake-ninja") => {
135+
self.run_cmake(repo_dir_str, config_opts.as_ref())?
136+
}
137+
Some("simple") => self.run_simple(repo_dir_str, build_commands.as_ref())?,
138+
_ => self.run_autotools(repo_dir_str, config_opts.as_ref())?,
134139
}
135-
Some("simple") => self.run_simple(repo_dir_str, build_commands.as_ref())?,
136-
_ => self.run_autotools(repo_dir_str, config_opts.as_ref())?,
137-
},
140+
if let Some(post_install) = post_install {
141+
for command in post_install {
142+
let args: Vec<&str> = command.split_whitespace().collect();
143+
run_command(args[0], &args[1..], Some(self.state.base_dir.as_path()))?;
144+
}
145+
}
146+
}
138147
Module::Reference(_) => {
139148
// Skip string references for build_application
140149
}
141150
}
142151
}
143152

144-
if let Some(Module::Object {
145-
post_install: Some(post_install),
146-
..
147-
}) = manifest.modules.last()
148-
{
149-
for command in post_install {
150-
let args: Vec<&str> = command.split_whitespace().collect();
151-
run_command(args[0], &args[1..], Some(self.state.base_dir.as_path()))?;
152-
}
153-
}
154-
155153
Ok(())
156154
}
157155

@@ -377,31 +375,30 @@ impl<'a> FlatpakManager<'a> {
377375
let manifest = self.manifest.as_ref().unwrap();
378376
let repo_dir = self.build_dir().join("repo");
379377

380-
let mut args = vec![
381-
"build".to_string(),
382-
"--with-appdir".to_string(),
383-
"--allow=devel".to_string(),
384-
"--talk-name=org.freedesktop.portal.*".to_string(),
385-
"--talk-name=org.a11y.Bus".to_string(),
386-
];
387-
388-
for (key, value) in get_host_env() {
389-
args.push(format!("--env={key}={value}"));
390-
}
378+
let mut args: Vec<String> = [
379+
"build",
380+
"--with-appdir",
381+
"--allow=devel",
382+
"--talk-name=org.freedesktop.portal.*",
383+
"--talk-name=org.a11y.Bus",
384+
]
385+
.iter()
386+
.map(|s| s.to_string())
387+
.collect();
388+
389+
args.extend(
390+
get_host_env()
391+
.into_iter()
392+
.map(|(key, value)| format!("--env={key}={value}")),
393+
);
391394

392-
for arg in get_a11y_bus_args() {
393-
args.push(arg);
394-
}
395+
args.extend(get_a11y_bus_args());
395396

396-
for arg in &manifest.finish_args {
397-
args.push(arg.clone());
398-
}
397+
args.extend(manifest.finish_args.clone());
399398
args.push(repo_dir.to_str().unwrap().to_string());
400399
args.push(manifest.command.clone());
401400
if let Some(x_run_args) = &manifest.x_run_args {
402-
for arg in x_run_args {
403-
args.push(arg.clone());
404-
}
401+
args.extend(x_run_args.clone());
405402
}
406403

407404
let args_str: Vec<&str> = args.iter().map(|s| s.as_str()).collect();
@@ -449,12 +446,10 @@ impl<'a> FlatpakManager<'a> {
449446
)?;
450447

451448
// Finalize build
452-
let mut args = vec!["build-finish".to_string()];
449+
let mut args: Vec<String> = vec!["build-finish".to_string()];
453450

454-
for arg in &manifest.finish_args {
455-
args.push(arg.clone());
456-
}
457-
args.push(format!("--command={}", manifest.command.clone()));
451+
args.extend(manifest.finish_args.clone());
452+
args.push(format!("--command={}", manifest.command));
458453
args.push(finalized_repo_dir.to_str().unwrap().to_string());
459454

460455
let args_str: Vec<&str> = args.iter().map(|s| s.as_str()).collect();
@@ -556,22 +551,23 @@ impl<'a> FlatpakManager<'a> {
556551
return Ok(());
557552
}
558553

559-
let mut default_selection = 0;
560554
let manifest_strings: Vec<String> = manifests
561555
.iter()
562-
.enumerate()
563-
.map(|(i, p)| {
556+
.map(|p| {
564557
let path_str = p.to_str().unwrap().to_string();
565-
if let Some(active_manifest) = &self.state.active_manifest {
566-
if active_manifest == p {
567-
default_selection = i;
568-
return format!("{} {}", "*".green().bold(), path_str);
569-
}
558+
if self.state.active_manifest.as_ref() == Some(p) {
559+
format!("{} {}", "*".green().bold(), path_str)
560+
} else {
561+
format!(" {path_str}")
570562
}
571-
format!(" {path_str}")
572563
})
573564
.collect();
574565

566+
let default_selection = manifests
567+
.iter()
568+
.position(|p| self.state.active_manifest.as_ref() == Some(p))
569+
.unwrap_or(0);
570+
575571
let theme = ColorfulTheme::default();
576572
let selection = Select::with_theme(&theme)
577573
.with_prompt("Select a manifest")

src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fn get_base_dir() -> PathBuf {
6969
return PathBuf::from(String::from_utf8_lossy(&output.stdout).trim());
7070
}
7171
}
72-
std::env::current_dir().unwrap()
72+
PathBuf::from(".")
7373
}
7474

7575
fn main() {

src/manifest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub fn find_manifests_in_path(path: &Path, exclude_prefix: Option<&Path>) -> Res
9797
if e.depth() == 0 {
9898
return true;
9999
}
100-
if e.file_name().to_str().map_or(false, |s| s.starts_with('.')) {
100+
if e.file_name().to_str().is_some_and(|s| s.starts_with('.')) {
101101
return false;
102102
}
103103
if let Some(prefix) = &exclude_prefix {

0 commit comments

Comments
 (0)