4 releases (breaking)

0.4.0 Dec 18, 2023
0.3.0 Apr 22, 2023
0.2.0 Apr 22, 2023
0.1.0 Apr 19, 2023

#244 in Asynchronous

Download history 6/week @ 2024-01-01 23/week @ 2024-01-08 76/week @ 2024-01-15 81/week @ 2024-01-22 106/week @ 2024-01-29 195/week @ 2024-02-05 27/week @ 2024-02-12 139/week @ 2024-02-19 76/week @ 2024-02-26 51/week @ 2024-03-04 90/week @ 2024-03-11 52/week @ 2024-03-18 49/week @ 2024-03-25 96/week @ 2024-04-01 56/week @ 2024-04-08 47/week @ 2024-04-15

253 downloads per month
Used in 4 crates

MIT license

69KB
729 lines

Project Status: Active – The project has reached a stable, usable state and is being actively developed. CI Status codecov.io Minimum Supported Rust Version MIT License

GitHub | crates.io | Documentation | Issues | Changelog

Most CLI commands that take file paths as arguments follow the convention of treating a path of - (a single hyphen/dash) as referring to either standard input or standard output (depending on whether the path is read from or written to). The patharg crate lets your programs follow this convention too: it provides InputArg and OutputArg types that wrap command-line arguments, with methods for reading from/writing to either the given path or — if the argument is just a hyphen — the appropriate standard stream.

InputArg and OutputArg implement From<OsString>, From<String>, and FromStr, so you can use them seamlessly with your favorite Rust source of command-line arguments, be it clap, lexopt, plain old std::env::args/std::env::args_os, or whatever else is out there. The source repository contains examples of two of these:

Comparison with clio

The only other library I am aware of that provides similar functionality to patharg is clio. Compared to clio, patharg aims to be a much simpler, smaller library that doesn't try to be too clever. Major differences between the libraries include:

  • When a clio path instance is created, clio will either (depending on the type used) open the path immediately — which can lead to empty files being needlessly left behind if an output file is constructed during argument processing but an error occurs before the file is actually used — or else check that the path can be opened — which is vulnerable to TOCTTOU bugs. patharg does no such thing.

  • clio supports reading from & writing to HTTP(S) URLs and has special treatment for FIFOs. patharg sees no need for such excesses.

  • patharg has a feature for allowing async I/O with tokio. clio does not.

  • patharg has optional support for serde. clio does not.

Dependencies

~0–1.7MB
~29K SLoC