alpm_srcinfo/
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
//! Commandline argument handling.
use std::path::PathBuf;

use alpm_types::Architecture;
use clap::{Parser, Subcommand};

#[derive(Clone, Debug, Parser)]
#[command(about, author, name = "alpm-srcinfo", version)]
pub struct Cli {
    #[command(subcommand)]
    pub command: Command,
}

/// Output format for the parse command
#[derive(Clone, Debug, Default, clap::ValueEnum, strum::Display)]
pub enum OutputFormat {
    #[default]
    #[strum(serialize = "json")]
    Json,
}

#[derive(Clone, Debug, Subcommand)]
pub enum Command {
    /// Validate a SRCINFO file from a path or `stdin`.
    ///
    /// 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 status.
    #[command()]
    Validate {
        #[arg(value_name = "FILE")]
        file: Option<PathBuf>,
    },
    /// Format a SRCINFO file from a path or `stdin`
    ///
    /// Read, validate and print all of the SRCINFO's packages in their final representation for a
    /// specific architecture. If the file is valid, the program prints the data in the
    /// requested file format to stdout and returns with an exit status of 0.
    #[command()]
    FormatPackages {
        #[arg(value_name = "FILE")]
        file: Option<PathBuf>,

        /// The selected architecture that should be used to interpret the SRCINFO file.
        ///
        /// Only [split-]packages that are applicable for this architecture will be returned.
        #[arg(short, long, alias = "arch")]
        architecture: Architecture,

        /// Provide the output format
        #[arg(
            short,
            long,
            value_name = "OUTPUT_FORMAT",
            default_value_t = OutputFormat::Json
        )]
        output_format: OutputFormat,

        /// Pretty-print the output.
        ///
        /// Only applies to formats that support pretty output and is otherwise ignored.
        #[arg(short, long)]
        pretty: bool,
    },
    /// Read a SRCINFO file from a path or `stdin` and perform linter checks on it.
    ///
    /// This ensures that the SRCINFO file is both **valid** and adheres to currently known best
    /// practices.
    ///
    /// Returns with a non-zero exit status as soon as any linting issue is encountered.
    #[command()]
    Check {
        #[arg(value_name = "FILE")]
        file: Option<PathBuf>,
    },
}