mirror of
https://github.com/ChrisTitusTech/linutil.git
synced 2024-11-21 21:09:42 +00:00
feat: Add --skip-confirmation
flag (#834)
* feat: Add --skip-confirmation flag * add `--skip-confirmation` to the manpage --------- Co-authored-by: Adam Perkowski <adas1per@protonmail.com>
This commit is contained in:
parent
472c85eb79
commit
d033b0f36d
|
@ -32,6 +32,10 @@ Possible values:
|
||||||
.br
|
.br
|
||||||
Defaults to \fIdefault\fR.
|
Defaults to \fIdefault\fR.
|
||||||
|
|
||||||
|
.TP
|
||||||
|
\fB\-y\fR, \fB\-\-skip\-confirmation\fR
|
||||||
|
Skip confirmation prompt before executing commands.
|
||||||
|
|
||||||
.TP
|
.TP
|
||||||
\fB\-\-override\-validation\fR
|
\fB\-\-override\-validation\fR
|
||||||
Show all available entries, disregarding compatibility checks. (\fBUNSAFE\fR)
|
Show all available entries, disregarding compatibility checks. (\fBUNSAFE\fR)
|
||||||
|
|
|
@ -34,6 +34,12 @@ struct Args {
|
||||||
#[arg(default_value_t = Theme::Default)]
|
#[arg(default_value_t = Theme::Default)]
|
||||||
#[arg(help = "Set the theme to use in the application")]
|
#[arg(help = "Set the theme to use in the application")]
|
||||||
theme: Theme,
|
theme: Theme,
|
||||||
|
#[arg(
|
||||||
|
short = 'y',
|
||||||
|
long,
|
||||||
|
help = "Skip confirmation prompt before executing commands"
|
||||||
|
)]
|
||||||
|
skip_confirmation: bool,
|
||||||
#[arg(long, default_value_t = false)]
|
#[arg(long, default_value_t = false)]
|
||||||
#[clap(help = "Show all available options, disregarding compatibility checks (UNSAFE)")]
|
#[clap(help = "Show all available options, disregarding compatibility checks (UNSAFE)")]
|
||||||
override_validation: bool,
|
override_validation: bool,
|
||||||
|
@ -45,7 +51,12 @@ struct Args {
|
||||||
fn main() -> io::Result<()> {
|
fn main() -> io::Result<()> {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
|
||||||
let mut state = AppState::new(args.theme, args.override_validation, args.size_bypass);
|
let mut state = AppState::new(
|
||||||
|
args.theme,
|
||||||
|
args.override_validation,
|
||||||
|
args.size_bypass,
|
||||||
|
args.skip_confirmation,
|
||||||
|
);
|
||||||
|
|
||||||
stdout().execute(EnterAlternateScreen)?;
|
stdout().execute(EnterAlternateScreen)?;
|
||||||
enable_raw_mode()?;
|
enable_raw_mode()?;
|
||||||
|
|
|
@ -61,6 +61,7 @@ pub struct AppState {
|
||||||
#[cfg(feature = "tips")]
|
#[cfg(feature = "tips")]
|
||||||
tip: String,
|
tip: String,
|
||||||
size_bypass: bool,
|
size_bypass: bool,
|
||||||
|
skip_confirmation: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Focus {
|
pub enum Focus {
|
||||||
|
@ -85,7 +86,12 @@ enum SelectedItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AppState {
|
impl AppState {
|
||||||
pub fn new(theme: Theme, override_validation: bool, size_bypass: bool) -> Self {
|
pub fn new(
|
||||||
|
theme: Theme,
|
||||||
|
override_validation: bool,
|
||||||
|
size_bypass: bool,
|
||||||
|
skip_confirmation: bool,
|
||||||
|
) -> Self {
|
||||||
let tabs = linutil_core::get_tabs(!override_validation);
|
let tabs = linutil_core::get_tabs(!override_validation);
|
||||||
let root_id = tabs[0].tree.root().id();
|
let root_id = tabs[0].tree.root().id();
|
||||||
|
|
||||||
|
@ -103,6 +109,7 @@ impl AppState {
|
||||||
#[cfg(feature = "tips")]
|
#[cfg(feature = "tips")]
|
||||||
tip: get_random_tip(),
|
tip: get_random_tip(),
|
||||||
size_bypass,
|
size_bypass,
|
||||||
|
skip_confirmation,
|
||||||
};
|
};
|
||||||
|
|
||||||
state.update_items();
|
state.update_items();
|
||||||
|
@ -756,6 +763,9 @@ impl AppState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if self.skip_confirmation {
|
||||||
|
self.handle_confirm_command();
|
||||||
|
} else {
|
||||||
let cmd_names = self
|
let cmd_names = self
|
||||||
.selected_commands
|
.selected_commands
|
||||||
.iter()
|
.iter()
|
||||||
|
@ -765,6 +775,7 @@ impl AppState {
|
||||||
let prompt = ConfirmPrompt::new(&cmd_names[..]);
|
let prompt = ConfirmPrompt::new(&cmd_names[..]);
|
||||||
self.focus = Focus::ConfirmationPrompt(Float::new(Box::new(prompt), 40, 40));
|
self.focus = Focus::ConfirmationPrompt(Float::new(Box::new(prompt), 40, 40));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
SelectedItem::None => {}
|
SelectedItem::None => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user