Verified Commit 5c93eccd authored by Morten Linderud's avatar Morten Linderud 🏄
Browse files

lib: Implement 'only' that creates a dependency chain from stdin



When building closed loops of packages you sometime don't want the
entire chain to be resolved to just figure out the order of 5 packages.
This implement `--only` which resolves the chain and ensures only the
packages from stdin are included in the output chain.

This is useful for rebuild lists or when building tight loops of
packages.

    $ arch-rebuild-order -o cmake meson jsoncpp
    meson jsoncpp cmake
    $ arch-rebuild-order -o jsoncpp meson cmake
    meson jsoncpp cmake

Signed-off-by: Morten Linderud's avatarMorten Linderud <morten@linderud.pw>
parent 70b24de6
Pipeline #13990 failed with stages
in 1 minute and 28 seconds
...@@ -22,4 +22,8 @@ pub struct Args { ...@@ -22,4 +22,8 @@ pub struct Args {
/// Write a dotfile into the given file /// Write a dotfile into the given file
#[structopt(short, long)] #[structopt(short, long)]
pub dotfile: Option<String>, pub dotfile: Option<String>,
/// Only use the pkgnames provided as input
#[structopt(short, long)]
pub only: bool,
} }
...@@ -79,6 +79,7 @@ pub fn run( ...@@ -79,6 +79,7 @@ pub fn run(
dbpath: Option<String>, dbpath: Option<String>,
repos: Vec<String>, repos: Vec<String>,
dotfile: Option<String>, dotfile: Option<String>,
only: bool,
) -> Result<String> { ) -> Result<String> {
let pacman = match dbpath { let pacman = match dbpath {
Some(path) => alpm::Alpm::new(ROOT_DIR, &path), Some(path) => alpm::Alpm::new(ROOT_DIR, &path),
...@@ -165,15 +166,14 @@ pub fn run( ...@@ -165,15 +166,14 @@ pub fn run(
// shows it as last package // shows it as last package
rebuild_order_packages.reverse(); rebuild_order_packages.reverse();
let mut output = String::new(); // We only retain the packages we want to when using `--only`
for elem in rebuild_order_packages.iter() { // This logic is hard to parse because retain is an inverse filter,
output.push_str(elem); // thus we use the negated form of: only && !pkgnames.contains(&pkg.to_string()
output.push(' '); rebuild_order_packages.retain(|pkg| !only || pkgnames.contains(&pkg.to_string()));
}
if let Some(filename) = dotfile { if let Some(filename) = dotfile {
write_dotfile(filename, graph)?; write_dotfile(filename, graph)?;
} }
Ok(output) Ok(rebuild_order_packages.join(" "))
} }
...@@ -4,7 +4,13 @@ use arch_rebuild_order::args::Args; ...@@ -4,7 +4,13 @@ use arch_rebuild_order::args::Args;
fn main() { fn main() {
let args = Args::from_args(); let args = Args::from_args();
match arch_rebuild_order::run(args.pkgnames, args.dbpath, args.repos, args.dotfile) { match arch_rebuild_order::run(
args.pkgnames,
args.dbpath,
args.repos,
args.dotfile,
args.only,
) {
Ok(output) => { Ok(output) => {
println!("{}", output); println!("{}", output);
std::process::exit(0); std::process::exit(0);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment