1pub mod commands;
2pub mod handlers;
3use crate::error::Error;
4
5pub 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
15pub 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
34pub fn print_validation_warning(message: &str) {
36 eprintln!("Warning: {message}");
37}
38
39pub 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
54pub fn initialize() -> Result<(), crate::error::Error> {
56 env_logger::init();
58
59 if std::env::var("REKOR_URL").is_err() {
61 print_validation_warning("REKOR_URL not set, using default");
62 }
63
64 Ok(())
65}
66
67pub 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}