Skip to content

Commit

Permalink
Merge pull request #53 from InnocentZero/flatpak_remotes
Browse files Browse the repository at this point in the history
feat: Add remote ref option to flatpak
  • Loading branch information
InnocentZero authored Nov 19, 2024
2 parents 2c5fb0c + c5436e4 commit 26ef02f
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ dnf = [
]
flatpak = [
"metapac",
{ package = "metapac" }
{ package = "metapac", remote = "flathub" }
]
pipx = [
"metapac",
Expand Down
37 changes: 34 additions & 3 deletions src/backends/flatpak.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ pub struct FlatpakQueryInfo {
}

#[derive(Debug, Clone, Default, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
pub struct FlatpakInstallOptions {}
pub struct FlatpakInstallOptions {
pub remote: String,
}

impl Backend for Flatpak {
type QueryInfo = FlatpakQueryInfo;
Expand Down Expand Up @@ -138,7 +140,35 @@ impl Backend for Flatpak {
no_confirm: bool,
config: &Config,
) -> Result<()> {
if !packages.is_empty() {
let mut no_remotes = Vec::new();
let mut remote_packages = BTreeMap::new();
for (package, remote) in packages {
if remote.remote.is_empty() {
no_remotes.push(package);
} else {
remote_packages.insert(package, remote);
}
}

if !no_remotes.is_empty() {
run_command(
[
"flatpak",
"install",
if config.flatpak_systemwide {
"--system"
} else {
"--user"
},
]
.into_iter()
.chain(Some("--assumeyes").filter(|_| no_confirm))
.chain(no_remotes.into_iter().map(String::as_str)),
Perms::Same,
)?;
}

for (package, remote) in remote_packages {
run_command(
[
"flatpak",
Expand All @@ -151,7 +181,8 @@ impl Backend for Flatpak {
]
.into_iter()
.chain(Some("--assumeyes").filter(|_| no_confirm))
.chain(packages.keys().map(String::as_str)),
.chain([remote.remote.as_str()])
.chain([package.as_str()]),
Perms::Same,
)?;
}
Expand Down

0 comments on commit 26ef02f

Please sign in to comment.