cargo_update/lib.rs
1//! A [`cargo` subcommand](https://github.com/rust-lang/cargo/wiki/Third-party-cargo-subcommands) for checking and applying
2//! updates to installed executables
3//!
4//! # Special thanks
5//!
6//! To all who support further development on [Patreon](https://patreon.com/nabijaczleweli), in particular:
7//!
8//! * ThePhD
9//! * Embark Studios
10//! * Lars Strojny
11//! * EvModder
12//!
13//! # Library doc
14//!
15//! This library is used by `cargo-update` itself for all its function and is therefore contains all necessary functions.
16//!
17//! ## Example
18//!
19//! See the [`src/main.rs`](https://github.com/nabijaczleweli/cargo-update/blob/master/src/main.rs) file in the git repository.
20//!
21//! # Executable manpage
22//!
23//! ## SYNOPSIS
24//!
25//! [`cargo install-update`](https://github.com/nabijaczleweli/cargo-update) [OPTIONS] [PACKAGE...]
26//!
27//! ## DESCRIPTION
28//!
29//!
30//! Cargo subcommand for checking and applying updates to installed executables.
31//!
32//! This was mostly built out of a frustration with periodically checking for
33//! updates for my cargo-installed executables, which was long and boring.
34//!
35//! Updates packages from the main repository and git repositories.
36//!
37//! See
38//! [cargo-install-update-config(1)](https://rawcdn.githack.com/nabijaczleweli/cargo-update/man/cargo-install-update-config.1.html)
39//! for further configuring updates.
40//!
41//! The `CARGO_INSTALL_OPTS` environment variable can be set,
42//! containing options to forward to the end of `cargo install` invocations'
43//! argument lists.
44//! Note, that
45//! [cargo-install-update-config(1)](https://rawcdn.githack.com/nabijaczleweli/cargo-update/man/cargo-install-update-config.1.html)
46//! is preferred in the general case.
47//!
48//! Exit values and possible errors:
49//!
50//! ```text
51//! -1 - cargo subprocess was terminated by a signal (Linux-only)
52//! 1 - option parsing error
53//! 2 - registry repository error
54//! X - bubbled-up cargo install exit value
55//! ```
56//!
57//! ## OPTIONS
58//!
59//! -a --all
60//!
61//! ```text
62//! Update all currently installed executables.
63//!
64//! Required if list of packages not given.
65//! ```
66//!
67//! [PACKAGE...]
68//!
69//! ```text
70//! List of packages to update in the [(registry_url):]package_name[:version] format.
71//!
72//! Registry defaults to the default crates.io registry,
73//! and can be a name from ~/.cargo/config.
74//!
75//! If specified in addition to --all,
76//! will add the specified packages to the update list
77//! (useful, e.g., in conjunction with --allow-no-update).
78//!
79//! Required if --all not given.
80//! ```
81//!
82//! -l --list
83//!
84//! ```text
85//! Don't update any packages, just list them.
86//!
87//! If PACKAGE is empty, act as if --all was specified.
88//! ```
89//!
90//! -f --force
91//!
92//! ```text
93//! Update all packages, regardless of whether they need to be version-wise.
94//! ```
95//!
96//! -i --allow-no-update
97//!
98//! ```text
99//! Allow to fresh install packages passed as PACKAGE argument.
100//!
101//! This is useful, for example, in pairing with cargo-install-update-config(1).
102//!
103//! Off by default.
104//! ```
105//!
106//! -g --git
107//!
108//! ```text
109//! Also update git-originating packages.
110//!
111//! Off by default, because it's expensive.
112//! ```
113//!
114//! -q --quiet
115//!
116//! ```text
117//! Don't print status messages to stdout
118//! and pass down --quiet to cargo subprocesses.
119//! ```
120//!
121//! -s --filter <PACKAGE_FILTER>...
122//!
123//! ```text
124//! Only consider packages matching all filters.
125//!
126//! PACKAGE_FILTER is in the form "key=value", where key is any of:
127//! - "toolchain": the package must be configured to be compiled with
128//! the specified toolchain via cargo-install-update-config(1).
129//! ```
130//!
131//! -c --cargo-dir <CARGO_DIR>
132//!
133//! ```text
134//! Set the directory containing cargo metadata.
135//!
136//! Required. Default: "$CARGO_HOME", then "$HOME/.cargo", otherwise manual.
137//! ```
138//!
139//! -t --temp-dir <TEMP_DIR>
140//!
141//! ```text
142//! Set the directory in which to clone git repositories.
143//!
144//! Adjoined with "cargo-update.$(id -un)" as last segment.
145//!
146//! Required. Default: system temp, otherwise manual.
147//! ```
148//!
149//! ## ENVIRONMENT VARIABLES
150//!
151//! ##### CARGO_REGISTRIES_CRATES_IO_PROTOCOL
152//!
153//! Overrides the `registries.crates-io.protocol` Cargo configuration key.
154//!
155//! The default is `sparse`, and the crates.io URL is
156//! sparse+https://index.crates.io/.
157//! Set to some other value to use the git registry
158//! (https://github.com/rust-lang/crates.io-index) for crates.io.
159//!
160//! ##### CARGO_NET_GIT_FETCH_WITH_CLI
161//!
162//! Overrides the `net.git-fetch-with-cli` Cargo configuration key.
163//!
164//! ##### GIT
165//!
166//! Overrides the git executable in `net.git-fetch-with-cli=true` mode.
167//!
168//! ## EXAMPLES
169//!
170//! `cargo install-update -a`
171//!
172//! ```text
173//! Update all installed packages.
174//!
175//! Example output:
176//! Updating registry `https://github.com/rust-lang/crates.io-index`
177//!
178//! Package Installed Latest Needs update
179//! checksums v0.5.0 v0.5.2 Yes
180//! treesize v0.2.0 v0.2.1 Yes
181//! cargo-count v0.2.2 v0.2.2 No
182//! cargo-graph v0.3.0 v0.3.0 No
183//! cargo-outdated v0.2.0 v0.2.0 No
184//! identicon v0.1.1 v0.1.1 No
185//! racer v1.2.10 v1.2.10 No
186//! rustfmt v0.6.2 v0.6.2 No
187//!
188//! Updating checksums
189//! Updating registry `https://github.com/rust-lang/crates.io-index`
190//! Downloading checksums v0.5.2
191//! [...]
192//! Compiling checksums v0.5.2
193//! Finished release [optimized] target(s) in 95.2 secs
194//! Replacing D:\Users\nabijaczleweli\.cargo\bin\checksums.exe
195//!
196//! Updating treesize
197//! Updating registry `https://github.com/rust-lang/crates.io-index`
198//! Downloading treesize v0.2.1
199//! [...]
200//! Compiling treesize v0.2.1
201//! Finished release [optimized] target(s) in 76.77 secs
202//! Replacing D:\Users\nabijaczleweli\.cargo\bin\treesize.exe
203//!
204//! Updated 2 packages.
205//! ```
206//!
207//! `cargo install-update` *racer treesize cargo-cln*
208//!
209//! ```text
210//! Only consider racer, treesize and cargo-cln for updates.
211//! Since cargo-cln is not installed, it'll be ignored.
212//!
213//! Example output:
214//! Updating registry `https://github.com/rust-lang/crates.io-index`
215//!
216//! Package Installed Latest Needs update
217//! treesize v0.2.0 v0.2.1 Yes
218//! racer v1.2.10 v1.2.10 No
219//!
220//! Updating treesize
221//! Updating registry `https://github.com/rust-lang/crates.io-index`
222//! Downloading treesize v0.2.1
223//! [...]
224//! Compiling treesize v0.2.1
225//! Finished release [optimized] target(s) in 76.77 secs
226//! Replacing D:\Users\nabijaczleweli\.cargo\bin\treesize.exe
227//!
228//! Updated 1 package.
229//! ```
230//!
231//! `cargo install-update -al`
232//!
233//! ```text
234//! List all installed packages, don't update any.
235//!
236//! Example output:
237//! Updating registry `https://github.com/rust-lang/crates.io-index`
238//!
239//! Package Installed Latest Needs update
240//! checksums v0.5.0 v0.5.2 Yes
241//! treesize v0.2.0 v0.2.1 Yes
242//! cargo-count v0.2.2 v0.2.2 No
243//! cargo-graph v0.3.0 v0.3.0 No
244//! cargo-outdated v0.2.0 v0.2.0 No
245//! identicon v0.1.1 v0.1.1 No
246//! racer v1.2.10 v1.2.10 No
247//! rustfmt v0.6.2 v0.6.2 No
248//! ```
249//!
250//! `cargo install-update -af`
251//!
252//! ```text
253//! Update all installed packages.
254//! Example output:
255//! Updating registry `https://github.com/rust-lang/crates.io-index`
256//!
257//! Package Installed Latest Needs update
258//! treesize v0.2.0 v0.2.1 Yes
259//! racer v1.2.10 v1.2.10 No
260//!
261//! Updating racer
262//! Updating registry `https://github.com/rust-lang/crates.io-index`
263//! Downloading racer v1.2.10
264//! [...]
265//! Compiling racer v1.2.10
266//! Finished release [optimized] target(s) in 51.43 secs
267//! Replacing D:\Users\nabijaczleweli\.cargo\bin\racer.exe
268//!
269//! Updating clippy
270//! Updating registry `https://github.com/rust-lang/crates.io-index`
271//! Downloading clippy v0.0.99
272//! [...]
273//! Compiling clippy v0.0.99
274//! [...]
275//! error: failed to compile `clippy v0.0.99`
276//!
277//! Updating treesize
278//! Updating registry `https://github.com/rust-lang/crates.io-index`
279//! Downloading treesize v0.2.1
280//! [...]
281//! Compiling treesize v0.2.1
282//! Finished release [optimized] target(s) in 76.77 secs
283//! Replacing D:\Users\nabijaczleweli\.cargo\bin\treesize.exe
284//!
285//! Updating clippy_lints
286//! Updating registry `https://github.com/rust-lang/crates.io-index`
287//! error: specified package has no binaries
288//!
289//! Updated 2 packages.
290//! Failed to update clippy, clippy_lints.
291//! ```
292//!
293//! `cargo install-update -i checksums rustfmt treesize`
294//!
295//! ```text
296//! Install specified packages, their installation status notwithstanding
297//!
298//! Example output:
299//! Updating registry `https://github.com/rust-lang/crates.io-index`
300//!
301//! Package Installed Latest Needs update
302//! checksums v0.5.2 Yes
303//! treesize v0.2.0 v0.2.1 Yes
304//! rustfmt v0.6.2 v0.6.2 No
305//!
306//! Installing checksums
307//! Updating registry `https://github.com/rust-lang/crates.io-index`
308//! Downloading checksums v0.5.2
309//! [...]
310//! Compiling checksums v0.5.2
311//! Finished release [optimized] target(s) in 95.2 secs
312//! Replacing D:\Users\nabijaczleweli\.cargo\bin\checksums.exe
313//!
314//! Updating treesize
315//! Updating registry `https://github.com/rust-lang/crates.io-index`
316//! Downloading treesize v0.2.1
317//! [...]
318//! Compiling treesize v0.2.1
319//! Finished release [optimized] target(s) in 76.77 secs
320//! Replacing D:\Users\nabijaczleweli\.cargo\bin\treesize.exe
321//!
322//! Updated 2 packages.
323//! ```
324//!
325//! `cargo install-update -i (file:///usr/local/share/cargo):zram-generator:0.1.1`
326//!
327//! ```text
328//! Install zram-generator from a local repository in /usr/local/share/cargo
329//! (but a remote one or a short name will work just as well), at most version 0.1.1.
330//!
331//! Example output:
332//! Updating registry `file:///usr/local/share/cargo`
333//!
334//! Package Installed Latest Needs update
335//! zram-generator v0.1.1 Yes
336//!
337//! Installing zram-generator
338//! Updating registry `https://github.com/rust-lang/crates.io-index`
339//! Downloading zram-generator v0.1.1
340//! [...]
341//! Compiling zram-generator v0.1.1
342//! Finished release [optimized] target(s) in 21.62 secs
343//! Installing /home/nabijaczleweli/.cargo/bin/zram-generator
344//! Installed package `zram-generator v0.1.1` (executable `zram-generator`)
345//!
346//! Updated 1 package.
347//! ```
348//!
349//! `cargo install-update -ag`
350//!
351//! ```text
352//! Update all installed packages, including ones from git.
353//!
354//! Example output:
355//! Updating registry `https://github.com/rust-lang/crates.io-index`
356//!
357//! Package Installed Latest Needs update
358//! checksums v0.5.0 v0.5.2 Yes
359//! cargo-count v0.2.2 v0.2.2 No
360//!
361//! Updating checksums
362//! Updating registry `https://github.com/rust-lang/crates.io-index`
363//! Downloading checksums v0.5.2
364//! [...]
365//! Compiling checksums v0.5.2
366//! Finished release [optimized] target(s) in 95.2 secs
367//! Replacing D:\Users\nabijaczleweli\.cargo\bin\checksums.exe
368//!
369//! Updated 1 package.
370//!
371//! Package Installed Latest Needs update
372//! alacritty eb231b3 5f78857 Yes
373//! chattium-oxide-client 108a7b9 108a7b9 No
374//!
375//! Updating alacritty from https://github.com/jwilm/alacritty
376//! Updating git repository `https://github.com/jwilm/alacritty`
377//! Installing alacritty v0.1.0 (https://github.com/jwilm/alacritty#5f788574)
378//! [...]
379//! Compiling alacritty v0.1.0
380//! Finished release [optimized] target(s) in 127.6 secs
381//! Replacing D:\Users\nabijaczleweli\.cargo\bin\alacritty.exe
382//!
383//! Updated 1 package.
384//! ```
385
386
387#[cfg(target_vendor = "apple")]
388extern crate security_framework;
389#[allow(unused_imports)]
390#[macro_use]
391extern crate serde_derive;
392extern crate serde_json;
393#[cfg(target_os = "windows")]
394extern crate windows;
395extern crate semver;
396extern crate whoami;
397extern crate serde;
398extern crate git2;
399#[macro_use]
400extern crate clap;
401extern crate curl;
402extern crate home;
403#[cfg(all(unix, not(target_vendor = "apple")))]
404extern crate libc;
405extern crate toml;
406extern crate hex;
407extern crate url;
408
409mod options;
410
411pub mod ops;
412
413pub use options::{ConfigOptions, Options};