Parses a SRCINFO file from a path or stdin and outputs it 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: SourceInfoOutputFormat,
pretty: bool,
)
| 85 | /// Returns an error if the input can not be parsed and validated, or if the output can not be |
| 86 | /// formatted in the selected output format. |
| 87 | pub fn format_source_info( |
| 88 | file: Option<&PathBuf>, |
| 89 | schema: Option<SourceInfoSchema>, |
| 90 | output_format: SourceInfoOutputFormat, |
| 91 | pretty: bool, |
| 92 | ) -> Result<(), Error> { |
| 93 | let srcinfo = parse(file, schema)?; |
| 94 | let SourceInfo::V1(source_info) = srcinfo; |
| 95 | |
| 96 | match output_format { |
| 97 | SourceInfoOutputFormat::Json => { |
| 98 | let json = if pretty { |
| 99 | serde_json::to_string_pretty(&source_info)? |
| 100 | } else { |
| 101 | serde_json::to_string(&source_info)? |
| 102 | }; |
| 103 | println!("{json}"); |
| 104 | } |
| 105 | SourceInfoOutputFormat::Srcinfo => { |
| 106 | println!("{}", source_info.as_srcinfo()) |
| 107 | } |
| 108 | } |
| 109 | |
| 110 | Ok(()) |
| 111 | } |
| 112 | |
| 113 | /// Parses a SRCINFO file from a path or stdin and outputs all info grouped by packages for a given |
| 114 | /// architecture in the specified format on stdout. |