atlas_cli/cli/
mod.rs

1pub mod commands;
2pub mod handlers;
3use crate::error::Error;
4
5// Re-export commonly used items
6pub use commands::{
7    CCAttestationCommands, DatasetCommands, ManifestCommands, ModelCommands, PipelineCommands,
8    SoftwareCommands,
9};
10pub use handlers::{
11    handle_cc_attestation_command, handle_dataset_command, handle_manifest_command,
12    handle_model_command, handle_pipeline_command, handle_software_command,
13};
14
15// Optional: Add any CLI-specific constants or shared utilities
16pub const CLI_VERSION: &str = env!("CARGO_PKG_VERSION");
17pub const CLI_NAME: &str = "atlas-cli";
18
19pub fn format_error(error: &Error) -> String {
20    match error {
21        Error::Io(err) => format!("IO error: {err}"),
22        Error::Storage(msg) => format!("Storage error: {msg}"),
23        Error::Validation(msg) => format!("Validation error: {msg}"),
24        Error::Manifest(msg) => format!("Manifest error: {msg}"),
25        Error::Signing(msg) => format!("Signing error: {msg}"),
26        Error::Serialization(msg) => format!("Serialization error: {msg}"),
27        Error::InitializationError(msg) => format!("Initialization error: {msg}"),
28        Error::HexDecode(err) => format!("Hex decode error: {err}"),
29        Error::CCAttestationError(msg) => format!("CC attestation error: {msg}"),
30        Error::Json(err) => format!("JSON error: {err}"),
31    }
32}
33
34/// Helper function to print validation warnings to the user
35pub fn print_validation_warning(message: &str) {
36    eprintln!("Warning: {message}");
37}
38
39/// Helper function to confirm actions with the user
40pub fn confirm_action(prompt: &str) -> bool {
41    use std::io::{self, Write};
42
43    print!("{prompt} [y/N]: ");
44    io::stdout().flush().unwrap();
45
46    let mut input = String::new();
47    if io::stdin().read_line(&mut input).is_ok() {
48        input.trim().to_lowercase() == "y"
49    } else {
50        false
51    }
52}
53
54/// Function to initialize any CLI-specific requirements
55pub fn initialize() -> Result<(), crate::error::Error> {
56    // Set up logging if needed
57    env_logger::init();
58
59    // Check for required environment variables
60    if std::env::var("REKOR_URL").is_err() {
61        print_validation_warning("REKOR_URL not set, using default");
62    }
63
64    Ok(())
65}
66
67// Shared functionality for progress indication
68pub mod progress {
69    use indicatif::{ProgressBar, ProgressStyle};
70
71    pub fn create_progress_bar(len: u64) -> ProgressBar {
72        let pb = ProgressBar::new(len);
73        pb.set_style(
74            ProgressStyle::default_bar()
75                .template("[{elapsed_precise}] {bar:40.cyan/blue} {pos:>7}/{len:7} {msg}")
76                .expect("Invalid progress bar template")
77                .progress_chars("=>-"),
78        );
79        pb
80    }
81}