Closed azzamsa closed 1 year ago
podman system prune -f
podman system prune -f
I know about --force
flag. I use it just to demonstrate. This doesn't answer my original question.
If you want to inherit stdin
, that doesn't seem possible at the moment: https://github.com/matklad/xshell/blob/ca9a6d6ed92a573564349a943c61924c082ff1bf/src/lib.rs#L1011-L1014.
You have read the answer yourself, then pass it using https://docs.rs/xshell/latest/xshell/struct.Cmd.html#method.stdin.
Yeah. We can use stdin()
such as this https://github.com/matklad/config/blob/0b4e7f1f31678a5f7aee27d212f0832baed722b2/xtool/src/autowatch.rs#L29. If the answer is hard coded / static / certain.
What I want is that I want to react based on the situation, it could be yes, or it could be no.
This is my issue:
cmd!(sh, "flatpak update").run()?;
Because my internet is metered, I want to pass y
or n
based on how big the update candidate is.
One solution is to list the update candidate and then use yes-or-no
function to prompt the user. However, flatpak doesn't have such command. All it has is --assumeyes
https://docs.flatpak.org/en/latest/flatpak-command-reference.html#flatpak-update.
What's wrong with
if yes_or_no("Update?") {
cmd.stdin("y");
} else {
cmd.stdin("n");
}
?
EDIT: okay, you want to see the output of the command before responding. Yeah, that's not possible at this moment, and is probably out of scope, similar to https://github.com/matklad/xshell/issues/43.
is probably out of scope, similar to #43.
Oh, I see.
xshell
#!/usr/bin/env rust-script
//! ```cargo
//! [dependencies]
//! duct = "0.13.6"
//! xshell = "0.2"
//! anyhow = "1.0"
//! ```
use xshell::{cmd, Shell};
// use duct::cmd;
fn run() -> anyhow::Result<()> {
let sh = Shell::new()?;
cmd!(sh, "podman system prune").run()?;
// cmd!("podman", "system", "prune").run()?;
Ok(())
}
fn main() -> anyhow::Result<()> {
run()?;
println!("✨ You have a new shiny machine!");
Ok(())
}
~
❯ cclean
$ podman system prune
WARNING! This command removes:
- all stopped containers
- all networks not used by at least one container
- all dangling images
- all dangling build cache
Are you sure you want to continue? [y/N] Error: EOF
Error: command exited with non-zero code `podman system prune`: 125
duct
#!/usr/bin/env rust-script
//! ```cargo
//! [dependencies]
//! duct = "0.13.6"
//! xshell = "0.2"
//! anyhow = "1.0"
//! ```
// use xshell::{cmd, Shell};
use duct::cmd;
fn run() -> anyhow::Result<()> {
// let sh = Shell::new()?;
// cmd!(sh, "podman system prune").run()?;
cmd!("podman", "system", "prune").run()?;
Ok(())
}
fn main() -> anyhow::Result<()> {
run()?;
println!("✨ You have a new shiny machine!");
Ok(())
}
❯ cclean
WARNING! This command removes:
- all stopped containers
- all networks not used by at least one container
- all dangling images
- all dangling build cache
Are you sure you want to continue? [y/N] n
✨ You have a new shiny machine!
Oh, I see. duct
will pipe correctly and act no different than normal shell.
I will probably just use duct
.
Thanks a lot for help :heart: @lnicola
Hi.
I would like to make
podman system prune
prompt[y/N]
to user as it is executed in shell.Shell:
Xshell:
One option is to use
yes-or-no
function such https://github.com/matklad/config/blob/0b4e7f1f31678a5f7aee27d212f0832baed722b2/xtool/src/amend.rs#L14, but it doesn't solve the original problem. It will not work with the command that has no-y
or--assumeyes
flag.Thanks for xshell :heart: