Skip to content

Commit

Permalink
Add crate documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
YS-L committed Jul 20, 2024
1 parent 3f5fd55 commit 825a306
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
//! # csvlens
//!
//! This crate allows you to use csvlens as a library.
//!
//! ## Example
//!
//! ```rust,no_run
//! use csvlens::run_csvlens;
//!
//! let out = run_csvlens(&["/path/to/your.csv"]).unwrap();
//! if let Some(selected_cell) = out {
//! println!("Selected: {}", selected_cell);
//! }
//! ```
mod app;
mod common;
mod csv;
Expand Down
21 changes: 19 additions & 2 deletions src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,30 @@ impl Drop for AppRunner {
}
}

pub fn run_csvlens<I, T>(itr: I) -> Result<Option<String>>
/// Run csvlens with a list of arguments. The accepted arguments are the same as the command line
/// arguments for the csvlens binary.
///
/// On success, the result contains an optional string that is the value of the selected cell if
/// any. If csvlens exits without selecting a cell, the result is None.
///
/// Example:
///
/// ```
/// use csvlens::run_csvlens;
///
/// match run_csvlens(&["/path/to/your.csv", "--delimiter", "\t"]) {
/// Ok(Some(selected_cell)) => println!("Selected: {}", selected_cell),
/// Ok(None) => {},
/// Err(e) => eprintln!("Error: {:?}", e),
/// }
/// ```
pub fn run_csvlens<I, T>(args: I) -> Result<Option<String>>
where
I: IntoIterator<Item = T>,
T: Into<OsString> + Clone,
{
let mut args_items = vec![OsString::from("csvlens")];
for item in itr {
for item in args {
args_items.push(item.into());
}
let args = Args::parse_from(args_items);
Expand Down

0 comments on commit 825a306

Please sign in to comment.