MCPcopy Create free account
hub / github.com/archlinux/alpm / format_packages

Function format_packages

alpm-srcinfo/src/commands.rs:120–146  ·  view source on GitHub ↗

Parses a SRCINFO file from a path or stdin and outputs all info grouped by packages for a given architecture in the specified format on stdout. # Errors Returns an error if the input can not be parsed and validated, or if the output can not be formatted in the selected output format.

(
    file: Option<&PathBuf>,
    schema: Option<SourceInfoSchema>,
    output_format: PackagesOutputFormat,
    architecture: Architecture,
    pretty: bool,
)

Source from the content-addressed store, hash-verified

118/// Returns an error if the input can not be parsed and validated, or if the output can not be
119/// formatted in the selected output format.
120pub fn format_packages(
121 file: Option<&PathBuf>,
122 schema: Option<SourceInfoSchema>,
123 output_format: PackagesOutputFormat,
124 architecture: Architecture,
125 pretty: bool,
126) -> Result<(), Error> {
127 let srcinfo = parse(file, schema)?;
128 let SourceInfo::V1(source_info) = srcinfo;
129
130 let packages: Vec<MergedPackage> = source_info
131 .packages_for_architecture(architecture)
132 .collect();
133
134 match output_format {
135 PackagesOutputFormat::Json => {
136 let json = if pretty {
137 serde_json::to_string_pretty(&packages)?
138 } else {
139 serde_json::to_string(&packages)?
140 };
141 println!("{json}");
142 }
143 }
144
145 Ok(())
146}
147
148/// Parses and interprets a SRCINFO file from a path or stdin.
149///

Callers 1

mainFunction · 0.85

Calls 2

parseFunction · 0.70

Tested by

no test coverage detected