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/// The command-line interface handling for `alpm-srcinfo`.
10#[derive(Clone, Debug, Parser)]
11#[command(about, author, name = "alpm-srcinfo", version)]
12pub struct Cli {
13 /// The `alpm-srcinfo` commands.
14 #[command(subcommand)]
15 pub command: Command,
16}
17
18/// Output format for the `format-packages` command.
19#[derive(Clone, Debug, Default, strum::Display, clap::ValueEnum)]
20pub enum PackagesOutputFormat {
21 /// The JSON output format.
22 #[default]
23 #[strum(serialize = "json")]
24 Json,
25}
26
27/// Output format for the `format` command.
28#[derive(Clone, Debug, Default, strum::Display, clap::ValueEnum)]
29pub enum SourceInfoOutputFormat {
30 /// The JSON output format.
31 #[strum(serialize = "json")]
32 Json,
33
34 /// The SRCINFO output format
35 #[default]
36 #[strum(serialize = "srcinfo")]
37 Srcinfo,
38}
39
40/// The `alpm-srcinfo` commands.
41#[derive(Clone, Debug, Subcommand)]
42pub enum Command {
43 /// Validate a SRCINFO file from a path or `stdin`.
44 ///
45 /// If the file can be validated, the program exits with no output and a return code of 0.
46 /// If the file can not be validated, an error is emitted on stderr and the program exits with
47 /// a non-zero exit status.
48 #[command()]
49 Validate {
50 /// An optional input file path to read from
51 ///
52 /// If no file is specified, stdin is read from and expected to contain PKGINFO data to
53 /// validate.
54 #[arg(value_name = "FILE")]
55 file: Option<PathBuf>,
56
57 /// Provide the SRCINFO schema version to use.
58 ///
59 /// If no schema version is provided, it will be deduced from the file itself.
60 #[arg(short, long, value_name = "VERSION")]
61 schema: Option<SourceInfoSchema>,
62 },
63
64 /// Format a SRCINFO file from a path or `stdin`.
65 ///
66 /// If the file is valid, the program prints the data in the
67 /// requested file format to stdout and returns with an exit status of 0.
68 #[command()]
69 Format {
70 /// The file to read from.
71 ///
72 /// If no file is provided, stdin is used instead.
73 #[arg(value_name = "FILE")]
74 file: Option<PathBuf>,
75
76 /// Provide the SRCINFO schema version to use.
77 ///
78 /// If no schema version is provided, it will be deduced from the file itself.
79 #[arg(short, long, value_name = "VERSION")]
80 schema: Option<SourceInfoSchema>,
81
82 /// Provide the output format
83 #[arg(
84 short,
85 long,
86 value_name = "OUTPUT_FORMAT",
87 default_value_t = SourceInfoOutputFormat::Srcinfo,
88 )]
89 output_format: SourceInfoOutputFormat,
90
91 /// Pretty-print the output.
92 ///
93 /// Only applies to formats that support pretty output and is otherwise ignored.
94 #[arg(short, long)]
95 pretty: bool,
96 },
97
98 /// Format a SRCINFO file's packages from a path or `stdin`
99 ///
100 /// Read, validate and print all of the SRCINFO's packages in their final representation for a
101 /// specific architecture. If the file is valid, the program prints the data in the
102 /// requested file format to stdout and returns with an exit status of 0.
103 #[command()]
104 FormatPackages {
105 /// An optional input file path to read from
106 ///
107 /// If no file is specified, stdin is read from and expected to contain PKGINFO data to
108 /// validate.
109 #[arg(value_name = "FILE")]
110 file: Option<PathBuf>,
111
112 /// Provide the SRCINFO schema version to use.
113 ///
114 /// If no schema version is provided, it will be deduced from the file itself.
115 #[arg(short, long, value_name = "VERSION")]
116 schema: Option<SourceInfoSchema>,
117
118 /// The selected architecture that should be used to interpret the SRCINFO file.
119 ///
120 /// Only [split-]packages that are applicable for this architecture will be returned.
121 #[arg(short, long, alias = "arch")]
122 architecture: Architecture,
123
124 /// Provide the output format
125 #[arg(
126 short,
127 long,
128 value_name = "OUTPUT_FORMAT",
129 default_value_t = PackagesOutputFormat::Json
130 )]
131 output_format: PackagesOutputFormat,
132
133 /// Pretty-print the output.
134 ///
135 /// Only applies to formats that support pretty output and is otherwise ignored.
136 #[arg(short, long)]
137 pretty: bool,
138 },
139}