//! CLI support functions shared between `ktstr` and `cargo-ktstr`.
//!
//! Validation, configuration, and kernel/KVM resolution logic used
//! by both binaries.

mod kernel_build;
mod kernel_cmd;
mod kernel_list;
mod locks;
mod parse;
pub(crate) mod progress;
mod resolve;
mod stats_cmds;
mod util;

#[cfg(test)]
mod testing;

pub use kernel_cmd::{
    CPU_CAP_HELP, DIRTY_TREE_CACHE_SKIP_HINT, EMBEDDED_KCONFIG, EOL_EXPLANATION,
    EXTRA_KCONFIG_HELP, INCLUDE_EOL_HELP, KERNEL_HELP_BUILD, KERNEL_HELP_NO_RAW,
    KERNEL_HELP_RAW_OK, KERNEL_LIST_LONG_ABOUT, KernelCommand, NON_GIT_TREE_CACHE_SKIP_HINT,
    STALE_KCONFIG_EXPLANATION, UNTRACKED_KCONFIG_EXPLANATION, embedded_kconfig_hash,
};

pub use kernel_list::{format_entry_row, kernel_clean, kernel_list, kernel_list_range_preview};

pub use kernel_build::{
    KernelBuildResult, append_extra_kconfig_suffix, kernel_build_pipeline, make_kernel_with_output,
    read_extra_kconfig, run_make, run_make_with_output, validate_kernel_config,
};

pub use parse::{DISK_HELP, parse_disk_arg, parse_disk_size_mib, parse_topology_string};

pub use resolve::{
    KernelDirCacheHit, KernelDirOutcome, KernelResolvePolicy, auto_download_kernel, cache_lookup,
    check_kvm, check_tools, download_and_cache_version, expand_kernel_range, resolve_cached_kernel,
    resolve_git_kernel, resolve_include_files, resolve_kernel_dir, resolve_kernel_dir_to_entry,
    resolve_kernel_image, resolve_kernel_parallelism,
};

pub use stats_cmds::{
    compare_partitions, compare_partitions_noise, explain_sidecar, list_metrics, list_runs,
    list_values, print_stats_report, show_host, show_run_host, show_thresholds,
};

pub use locks::list_locks;

pub use util::{
    Spinner, new_table, new_wrapped_table, restore_sigpipe_default, stderr_color, stdout_color,
};

/// `FetchProgress` is the public handle the `ktstr` / `cargo-ktstr`
/// binaries construct to render kernel-fetch progress (the parallel
/// `resolve_kernel_set` and the single-shot `kernel build` paths).
/// It must be `pub` (not `pub(crate)`) because those call sites live
/// in the binary crates and thread `&FetchProgress` into the library
/// resolvers — the same lib/bin-boundary reason [`Spinner`] is `pub`.
/// The child-bar types (`GroupBar`, `CloneProgress`) stay
/// `pub(crate)`: only the in-crate fetch path constructs them.
pub use progress::FetchProgress;

/// Re-export of the internal `vmm::host_topology::CpuCap` type so
/// the `ktstr` and `cargo-ktstr` CLI binaries (which import this
/// module through the `pub mod cli` surface) can resolve
/// `--cpu-cap N` without depending on the `pub(crate)` `vmm`
/// module. Keeping the canonical definition in `vmm::host_topology`
/// (so the `acquire_llc_plan` internal call site consumes its own
/// type without needing `cli`) and re-exporting here — versus
/// inverting the dependency — avoids pulling the CLI module into
/// the VMM internals.
pub use crate::vmm::host_topology::CpuCap;

/// Re-exports of the dimensional-slicing types used by
/// `cargo-ktstr`'s `BuildCompareFilters::build()` plumbing. The
/// `stats` module is `pub(crate)` (its tabular reporting types
/// have no stable surface yet), but the `cargo-ktstr` binary needs
/// `Dimension` and `derive_slicing_dims` to unit-test the
/// filter-builder shape (the `BuildCompareFilters` tests assert
/// which slicing dim a per-side filter pair derives). Same
/// pattern as `CpuCap` above: keep the canonical definitions in
/// `stats` (where the comparison plumbing consumes them
/// internally) and re-export the slim slicing surface through
/// `cli` so the binaries reach them through the public `cli`
/// module.
pub use crate::stats::{Dimension, derive_slicing_dims};

/// Re-export of the comparison-policy types so downstream crates
/// using `ktstr::cli` as their public surface don't need to reach
/// into the internal `ktstr::stats` module (which is `pub(crate)` —
/// see `lib.rs` — and therefore not a stable public path). The
/// policy is the only item in `stats` that a CLI or external
/// consumer constructs directly; every other item is internal
/// plumbing reached via `cli::compare_partitions`.
pub use crate::stats::{
    AveragedGroup, ComparisonPolicy, GateOptions, PhaseDisplayOptions, RowFilter,
    is_render_suppressed_component, metric_def,
};
