alpm_mtree/cli.rs
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
use std::path::PathBuf;
use clap::{Parser, Subcommand, ValueEnum};
use crate::MtreeSchema;
#[derive(Clone, Debug, Parser)]
#[command(about, author, name = "alpm-mtree", version)]
pub struct Cli {
#[command(subcommand)]
pub command: Command,
}
/// Output format for the parse command
#[derive(Clone, Debug, Default, ValueEnum, strum::Display)]
pub enum OutputFormat {
#[default]
#[strum(serialize = "json")]
Json,
}
#[allow(clippy::large_enum_variant)]
#[derive(Clone, Debug, Subcommand)]
pub enum Command {
/// Read an MTREE file and return it in another file format
///
/// Reads and validates an MTREE file according to a schema and outputs it in another file
/// format (currently, only JSON is supported). If the file can be validated, the program
/// exits with the data returned in another file format on stdout and a return code of 0.
/// If the file can not be validated, an error is emitted on stderr and the program exits with
/// a non-zero exit code.
#[command()]
Format {
#[arg(value_name = "FILE")]
file: Option<PathBuf>,
/// Provide the MTREE schema version to use.
///
/// If no schema version is provided, it will be deduced from the file itself.
///
/// Valid values are ['1', '2'].
#[arg(short, long, value_name = "VERSION")]
schema: Option<MtreeSchema>,
/// Provide the output format
#[arg(
short,
long,
value_name = "OUTPUT_FORMAT",
default_value_t = OutputFormat::Json
)]
output_format: OutputFormat,
/// Determines whether the output will be displayed in a pretty non-minimized fashion.
///
/// Only applies to formats that support pretty output, otherwise it's just ignored.
#[arg(short, long)]
pretty: bool,
},
/// Validate an MTREE file
///
/// Validate an MTREE file according to a schema.
/// If the file can be validated, the program exits with no output and a return code of 0.
/// If the file can not be validated, an error is emitted on stderr and the program exits with
/// a non-zero exit code.
#[command()]
Validate {
#[arg(value_name = "FILE")]
file: Option<PathBuf>,
/// Provide the MTREE schema version to use.
///
/// If no schema version is provided, it will be deduced from the file itself.
///
/// Valid values are ['1', '2'].
#[arg(short, long, value_name = "VERSION")]
schema: Option<MtreeSchema>,
},
}