summaryrefslogtreecommitdiff
path: root/mingling_core/src/program/setup/basic.rs
blob: 8316a336a189e30ebebf09665ae6b67b6626916a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
use std::fmt::Display;

use crate::{
    ProgramCollect,
    program::{Program, setup::ProgramSetup},
};

/// Performs basic program initialization:
///
/// - Collects `--quiet` flag to control message rendering
/// - Collects `--help` flag to enable help mode
/// - Collects `--confirm` flag to skip user confirmation
pub struct BasicProgramSetup;

impl<C, G> ProgramSetup<C, G> for BasicProgramSetup
where
    C: ProgramCollect,
    G: Display,
{
    fn setup(&mut self, program: &mut Program<C, G>) {
        program.global_flag(["--quiet", "-q"], |p| {
            p.stdout_setting.render_output = false;
            p.stdout_setting.error_output = false;
        });

        program.global_flag(["--help", "-h"], |p| {
            p.user_context.help = true;
        });

        program.global_flag(["--confirm", "-C"], |p| {
            p.user_context.confirm = true;
        });
    }
}