use std::path::Path;
use crate::core::df::tabular;
use crate::error::OxenError;
use crate::opts::DFOpts;
use crate::util;
pub fn df<P: AsRef<Path>>(input: P, opts: DFOpts) -> Result<(), OxenError> {
let mut df = tabular::show_path(input, opts.clone())?;
if let Some(output) = opts.output {
println!("Writing {output:?}");
tabular::write_df(&mut df, output)?;
}
Ok(())
}
pub fn schema<P: AsRef<Path>>(input: P, flatten: bool, opts: DFOpts) -> Result<String, OxenError> {
tabular::schema_to_string(input, flatten, &opts)
}
pub fn add_row(path: &Path, data: &str) -> Result<(), OxenError> {
if util::fs::is_tabular(path) {
let mut opts = DFOpts::empty();
opts.add_row = Some(data.to_string());
opts.output = Some(path.to_path_buf());
df(path, opts)
} else {
let err = format!("{} is not a tabular file", path.display());
Err(OxenError::basic_str(err))
}
}
pub fn add_column(path: &Path, data: &str) -> Result<(), OxenError> {
if util::fs::is_tabular(path) {
let mut opts = DFOpts::empty();
opts.add_col = Some(data.to_string());
opts.output = Some(path.to_path_buf());
df(path, opts)
} else {
let err = format!("{} is not a tabular file", path.display());
Err(OxenError::basic_str(err))
}
}