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