Skip to main content

datui_lib/
cli.rs

1//! Re-export CLI definitions from the shared datui-cli crate.
2
3pub use datui_cli::{
4    Args, CacheAction, Command, CompressionFormat, ConfigAction, FileFormat, FormatChoice,
5    FormatsAction, InferTypes, Lines, ReadMode, RemoteRead, Stored, Summary, ViewsAction,
6    completions, one_table, settings,
7};
8
9/// `argv` read as the command line is, for a host such as the Python binding that
10/// spells its options as flags and `-c`. The error is clap's, on one line.
11pub fn parse_args<I, T>(argv: I) -> Result<Args, String>
12where
13    I: IntoIterator<Item = T>,
14    T: Into<std::ffi::OsString> + Clone,
15{
16    use clap::Parser;
17    Args::try_parse_from(argv).map_err(|e| {
18        let text = e.to_string();
19        text.lines()
20            .next()
21            .unwrap_or_default()
22            .trim_start_matches("error: ")
23            .to_string()
24    })
25}