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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
#![deny(unknown_lints)]
#![deny(renamed_and_removed_lints)]
#![forbid(unsafe_code)]
#![deny(deprecated)]
#![forbid(private_in_public)]
#![forbid(non_fmt_panics)]
#![deny(unreachable_code)]
#![deny(unreachable_patterns)]
#![forbid(unused_doc_comments)]
#![forbid(unused_must_use)]
#![deny(while_true)]
#![deny(unused_parens)]
#![deny(redundant_semicolons)]
#![deny(non_ascii_idents)]
#![deny(confusable_idents)]
#![warn(missing_docs)]
#![warn(clippy::missing_docs_in_private_items)]
#![warn(clippy::cargo_common_metadata)]
#![warn(rustdoc::missing_crate_level_docs)]
#![deny(rustdoc::broken_intra_doc_links)]
#![warn(missing_debug_implementations)]
#![doc = include_str!("../README.md")]
use thiserror::Error;
use std::process::Command;
use std::str::from_utf8;
use tracing::{debug, warn};
#[derive(Debug, Error)]
pub enum Error {
#[error("Error parsing JSON: {0}")]
SerdeJsonError(#[from] serde_json::Error),
#[error("Error interpreting program output as UTF-8: {0}")]
Utf8Error(#[from] std::str::Utf8Error),
#[error("I/O Error: {0}")]
StdIoError(#[from] std::io::Error),
}
#[derive(Debug, clap::Parser)]
pub struct ComposerOutdatedOptions {
#[clap(
short = 'i',
long = "ignore",
value_name = "PACKAGE_NAME",
multiple_occurrences = true,
number_of_values = 1,
help = "Dependencies that should be ignored"
)]
ignored_packages: Vec<String>,
}
#[derive(Debug, serde::Deserialize)]
pub struct ComposerOutdatedData {
pub locked: Vec<PackageStatus>,
}
#[derive(Debug, serde::Deserialize)]
pub struct PackageStatus {
pub name: String,
pub version: String,
pub latest: String,
#[serde(rename = "latest-status")]
pub latest_status: UpdateRequirement,
pub description: String,
pub warning: Option<String>,
}
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, serde::Deserialize)]
#[serde(rename_all = "kebab-case")]
pub enum UpdateRequirement {
UpToDate,
SemverSafeUpdate,
UpdatePossible,
}
#[derive(Debug, PartialEq, Eq, serde::Deserialize)]
pub enum IndicatedUpdateRequirement {
UpToDate,
UpdateRequired,
}
pub fn outdated(
options: &ComposerOutdatedOptions,
) -> Result<(IndicatedUpdateRequirement, ComposerOutdatedData), Error> {
let mut cmd = Command::new("composer");
cmd.args([
"outdated",
"-f",
"json",
"--no-plugins",
"--strict",
"--locked",
"-m",
]);
for package_name in &options.ignored_packages {
cmd.args(["--ignore", package_name]);
}
let output = cmd.output()?;
if !output.status.success() {
warn!(
"composer outdated did not return with a successful exit code: {}",
output.status
);
debug!("stdout:\n{}", from_utf8(&output.stdout)?);
if !output.stderr.is_empty() {
warn!("stderr:\n{}", from_utf8(&output.stderr)?);
}
}
let update_requirement = if output.status.success() {
IndicatedUpdateRequirement::UpdateRequired
} else {
IndicatedUpdateRequirement::UpToDate
};
let json_str = from_utf8(&output.stdout)?;
let data: ComposerOutdatedData = serde_json::from_str(json_str)?;
Ok((update_requirement, data))
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn test_run_composer_outdated() -> Result<(), Error> {
outdated(&ComposerOutdatedOptions {
ignored_packages: vec![],
})?;
Ok(())
}
}