winbrew_cli/
lib.rs

1#![cfg(windows)]
2
3//! Command-line facade for WinBrew.
4//!
5//! `winbrew-cli` owns command parsing, command dispatch, and the terminal UI
6//! context used by the binary. It keeps the executable thin while translating
7//! parsed commands into app-layer operations.
8//!
9//! Public modules:
10//!
11//! - `cli`: Clap command definitions and argument parsing
12//! - `commands`: wrapper handlers and command-specific UI behavior
13//! - `services`: startup and bootstrap wiring used by the binary
14
15use anyhow::Result;
16use std::io;
17
18pub mod cli;
19pub mod commands;
20pub mod services;
21
22use winbrew_app::AppContext;
23use winbrew_ui::{Ui, UiSettings};
24
25pub(crate) use winbrew_app as app;
26pub use winbrew_app::core::cancel;
27pub use winbrew_app::{core, database, engines, models};
28
29#[derive(Debug, Clone)]
30pub struct CommandContext {
31    app: AppContext,
32    ui: UiSettings,
33}
34
35impl CommandContext {
36    /// Build a command context from a loaded configuration.
37    pub fn from_config(config: &database::Config) -> Result<Self> {
38        Self::from_config_with_verbosity(config, 0)
39    }
40
41    /// Build a command context with an explicit verbosity level.
42    pub fn from_config_with_verbosity(config: &database::Config, verbosity: u8) -> Result<Self> {
43        Ok(Self {
44            app: AppContext::from_config_with_verbosity(config, verbosity)?,
45            ui: UiSettings {
46                color_enabled: config.core.color,
47                default_yes: config.core.default_yes,
48            },
49        })
50    }
51
52    /// Create a terminal UI for the current command invocation.
53    pub fn ui(&self) -> Ui<io::Stdout> {
54        Ui::new(self.ui)
55    }
56
57    /// Return the application context used by the command handlers.
58    pub fn app(&self) -> &AppContext {
59        &self.app
60    }
61}
62
63/// Run a parsed command through the bootstrap pipeline.
64pub fn run_app(command: crate::cli::Command, verbosity: u8) -> Result<()> {
65    services::startup::run(command, verbosity)
66}