alpm_srcinfo/cli.rs
1//! Commandline argument handling.
2use std::path::PathBuf;
3
4use alpm_types::Architecture;
5use clap::{Parser, Subcommand};
6
7use crate::SourceInfoSchema;
8
9#[derive(Clone, Debug, Parser)]
10#[command(about, author, name = "alpm-srcinfo", version)]
11pub struct Cli {
12 #[command(subcommand)]
13 pub command: Command,
14}
15
16/// Output format for the parse command
17#[derive(Clone, Debug, Default, clap::ValueEnum, strum::Display)]
18pub enum OutputFormat {
19 #[default]
20 #[strum(serialize = "json")]
21 Json,
22}
23
24#[derive(Clone, Debug, Subcommand)]
25pub enum Command {
26 /// Validate a SRCINFO file from a path or `stdin`.
27 ///
28 /// If the file can be validated, the program exits with no output and a return code of 0.
29 /// If the file can not be validated, an error is emitted on stderr and the program exits with
30 /// a non-zero exit status.
31 #[command()]
32 Validate {
33 #[arg(value_name = "FILE")]
34 file: Option<PathBuf>,
35
36 /// Provide the SRCINFO schema version to use.
37 ///
38 /// If no schema version is provided, it will be deduced from the file itself.
39 #[arg(short, long, value_name = "VERSION")]
40 schema: Option<SourceInfoSchema>,
41 },
42 /// Format a SRCINFO file from a path or `stdin`
43 ///
44 /// Read, validate and print all of the SRCINFO's packages in their final representation for a
45 /// specific architecture. If the file is valid, the program prints the data in the
46 /// requested file format to stdout and returns with an exit status of 0.
47 #[command()]
48 FormatPackages {
49 #[arg(value_name = "FILE")]
50 file: Option<PathBuf>,
51
52 /// Provide the SRCINFO schema version to use.
53 ///
54 /// If no schema version is provided, it will be deduced from the file itself.
55 #[arg(short, long, value_name = "VERSION")]
56 schema: Option<SourceInfoSchema>,
57
58 /// The selected architecture that should be used to interpret the SRCINFO file.
59 ///
60 /// Only [split-]packages that are applicable for this architecture will be returned.
61 #[arg(short, long, alias = "arch")]
62 architecture: Architecture,
63
64 /// Provide the output format
65 #[arg(
66 short,
67 long,
68 value_name = "OUTPUT_FORMAT",
69 default_value_t = OutputFormat::Json
70 )]
71 output_format: OutputFormat,
72
73 /// Pretty-print the output.
74 ///
75 /// Only applies to formats that support pretty output and is otherwise ignored.
76 #[arg(short, long)]
77 pretty: bool,
78 },
79}