Skip to content

Commit

Permalink
cargo +nightly fmt
Browse files Browse the repository at this point in the history
rustfmt has changed its formatting rules, apply it project wide
  • Loading branch information
jqnatividad committed Nov 21, 2023
1 parent 21cebc4 commit 4e590b2
Show file tree
Hide file tree
Showing 59 changed files with 1,902 additions and 1,743 deletions.
11 changes: 6 additions & 5 deletions src/cmd/dedup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,12 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
};
let a = sel.select(&record);
let b = sel.select(&next_record);
let comparison = if ignore_case {
iter_cmp_ignore_case(a, b)
} else {
iter_cmp(a, b)
};
let comparison =
if ignore_case {
iter_cmp_ignore_case(a, b)
} else {
iter_cmp(a, b)
};
match comparison {
cmp::Ordering::Equal => {
dupe_count += 1;
Expand Down
135 changes: 69 additions & 66 deletions src/cmd/describegpt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,61 +185,63 @@ fn is_valid_model(client: &Client, api_key: Option<&str>, args: &Args) -> CliRes

fn get_prompt_file(args: &Args) -> CliResult<PromptFile> {
// Get prompt file if --prompt-file is used
let prompt_file = if let Some(prompt_file) = args.flag_prompt_file.clone() {
// Read prompt file
let prompt_file = fs::read_to_string(prompt_file)?;
// Try to parse prompt file as JSON, if error then show it in JSON format
let prompt_file: PromptFile = match serde_json::from_str(&prompt_file) {
Ok(val) => val,
Err(e) => {
let error_json = json!({"error": e.to_string()});
return fail_clierror!("{error_json}");
},
};
prompt_file
}
// Otherwise, get default prompt file
else {
#[allow(clippy::let_and_return)]
let default_prompt_file = PromptFile {
name: "My Prompt File".to_string(),
description: "My prompt file for qsv's describegpt command.".to_string(),
author: "My Name".to_string(),
version: "1.0.0".to_string(),
tokens: 50,
dictionary_prompt: "Here are the columns for each field in a data dictionary:\n\n- \
Type: the data type of this column\n- Label: a human-friendly \
label for this column\n- Description: a full description for \
this column (can be multiple sentences)\n\nGenerate a data \
dictionary as aforementioned (in JSON output) where each field \
has Name, Type, Label, and Description (so four columns in \
total) based on the following summary statistics and frequency \
data from a CSV file.\n\nSummary \
Statistics:\n\n{stats}\n\nFrequency:\n\n{frequency}"
.to_string(),
description_prompt: "Generate only a description that is within 8 sentences about the \
entire dataset{json_add} based on the following summary \
statistics and frequency data derived from the CSV file it came \
from.\n\nSummary \
Statistics:\n\n{stats}\n\nFrequency:\n\n{frequency}\n\nDo not \
output the summary statistics for each field. Do not output the \
frequency for each field. Do not output data about each field \
individually, but instead output about the dataset as a whole in \
one 1-8 sentence description."
.to_string(),
tags_prompt: "A tag is a keyword or label that categorizes datasets with \
other, similar datasets. Using the right tags makes it easier \
for others to find and use datasets.\n\nGenerate single-word \
tags{json_add} about the dataset (lowercase only and remove all \
whitespace) based on the following summary statistics and \
frequency data from a CSV file.\n\nSummary \
Statistics:\n\n{stats}\n\nFrequency:\n\n{frequency}"
.to_string(),
json: true,
jsonl: false,
let prompt_file =
if let Some(prompt_file) = args.flag_prompt_file.clone() {
// Read prompt file
let prompt_file = fs::read_to_string(prompt_file)?;
// Try to parse prompt file as JSON, if error then show it in JSON format
let prompt_file: PromptFile = match serde_json::from_str(&prompt_file) {
Ok(val) => val,
Err(e) => {
let error_json = json!({"error": e.to_string()});
return fail_clierror!("{error_json}");
},
};
prompt_file
}
// Otherwise, get default prompt file
else {
#[allow(clippy::let_and_return)]
let default_prompt_file = PromptFile {
name: "My Prompt File".to_string(),
description: "My prompt file for qsv's describegpt command.".to_string(),
author: "My Name".to_string(),
version: "1.0.0".to_string(),
tokens: 50,
dictionary_prompt: "Here are the columns for each field in a data \
dictionary:\n\n- Type: the data type of this column\n- \
Label: a human-friendly label for this column\n- \
Description: a full description for this column (can be \
multiple sentences)\n\nGenerate a data dictionary as \
aforementioned (in JSON output) where each field has Name, \
Type, Label, and Description (so four columns in total) \
based on the following summary statistics and frequency data \
from a CSV file.\n\nSummary \
Statistics:\n\n{stats}\n\nFrequency:\n\n{frequency}"
.to_string(),
description_prompt: "Generate only a description that is within 8 sentences about \
the entire dataset{json_add} based on the following summary \
statistics and frequency data derived from the CSV file it \
came from.\n\nSummary \
Statistics:\n\n{stats}\n\nFrequency:\n\n{frequency}\n\nDo \
not output the summary statistics for each field. Do not \
output the frequency for each field. Do not output data \
about each field individually, but instead output about the \
dataset as a whole in one 1-8 sentence description."
.to_string(),
tags_prompt: "A tag is a keyword or label that categorizes datasets with \
other, similar datasets. Using the right tags makes it \
easier for others to find and use datasets.\n\nGenerate \
single-word tags{json_add} about the dataset (lowercase only \
and remove all whitespace) based on the following summary \
statistics and frequency data from a CSV file.\n\nSummary \
Statistics:\n\n{stats}\n\nFrequency:\n\n{frequency}"
.to_string(),
json: true,
jsonl: false,
};
default_prompt_file
};
default_prompt_file
};
Ok(prompt_file)
}

Expand Down Expand Up @@ -297,18 +299,19 @@ fn get_completion(
}

// If --max-tokens is specified, use it
let max_tokens = if arg_is_some("--max-tokens") {
args.flag_max_tokens
}
// If --prompt-file is used, use the tokens field from the prompt file
else if args.flag_prompt_file.clone().is_some() {
let prompt_file = get_prompt_file(args)?;
prompt_file.tokens
}
// Else use the default max tokens value in USAGE
else {
args.flag_max_tokens
};
let max_tokens =
if arg_is_some("--max-tokens") {
args.flag_max_tokens
}
// If --prompt-file is used, use the tokens field from the prompt file
else if args.flag_prompt_file.clone().is_some() {
let prompt_file = get_prompt_file(args)?;
prompt_file.tokens
}
// Else use the default max tokens value in USAGE
else {
args.flag_max_tokens
};

// Create request data
let request_data = json!({
Expand Down
57 changes: 30 additions & 27 deletions src/cmd/excel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,32 +226,34 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
.and_then(std::ffi::OsStr::to_str)
.unwrap_or_default()
.to_lowercase();
let ods_flag = match format.as_str() {
"xls" | "xlsx" | "xlsm" | "xlsb" => false,
"ods" => true,
_ => {
return fail_incorrectusage_clierror!(
"\"{format}\" not supported. The excel command only supports the following file \
formats - xls, xlsx, xlsm, xlsb and ods."
);
},
};
let ods_flag =
match format.as_str() {
"xls" | "xlsx" | "xlsm" | "xlsb" => false,
"ods" => true,
_ => {
return fail_incorrectusage_clierror!(
"\"{format}\" not supported. The excel command only supports the following \
file formats - xls, xlsx, xlsm, xlsb and ods."
);
},
};

let requested_range = args.flag_range.to_lowercase();

let mut workbook = match open_workbook_auto(path) {
Ok(workbook) => workbook,
Err(e) => {
let es = e.to_string();
// password protected errors come in different flavors for Excel
if es.starts_with("Xls error: Cfb error")
|| es.starts_with("Xlsx error: Zip error: invalid Zip archive")
{
return fail_clierror!("{path} may be a password-protected workbook: {e}.");
}
return fail_clierror!("Cannot open workbook: {e}.");
},
};
let mut workbook =
match open_workbook_auto(path) {
Ok(workbook) => workbook,
Err(e) => {
let es = e.to_string();
// password protected errors come in different flavors for Excel
if es.starts_with("Xls error: Cfb error")
|| es.starts_with("Xlsx error: Zip error: invalid Zip archive")
{
return fail_clierror!("{path} may be a password-protected workbook: {e}.");
}
return fail_clierror!("Cannot open workbook: {e}.");
},
};

let sheet_names = workbook.sheet_names();
if sheet_names.is_empty() {
Expand All @@ -264,10 +266,11 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
#[allow(clippy::redundant_clone)]
let sheet_vec = sheet_names.clone();

let mut wtr = Config::new(&args.flag_output)
.flexible(args.flag_flexible)
.delimiter(args.flag_delimiter)
.writer()?;
let mut wtr =
Config::new(&args.flag_output)
.flexible(args.flag_flexible)
.delimiter(args.flag_delimiter)
.writer()?;

// set Metadata Mode
let first_letter = args.flag_metadata.chars().next().unwrap_or_default();
Expand Down
25 changes: 14 additions & 11 deletions src/cmd/extdedup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,14 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
// if we can detect the total memory, use 10% of it by default
// and up to --memory-limit (capped at 50%),
// otherwise, if we cannot detect the free memory use a default of 100 MB
let mem_limited_buffer = if System::IS_SUPPORTED {
let mut sys = System::new();
sys.refresh_memory();
(sys.total_memory() * 1000) / u8::min(args.flag_memory_limit.unwrap_or(10), 50) as u64
} else {
MEMORY_LIMITED_BUFFER
};
let mem_limited_buffer =
if System::IS_SUPPORTED {
let mut sys = System::new();
sys.refresh_memory();
(sys.total_memory() * 1000) / u8::min(args.flag_memory_limit.unwrap_or(10), 50) as u64
} else {
MEMORY_LIMITED_BUFFER
};
log::info!("{mem_limited_buffer} bytes used for memory buffer for on-disk hash table...");

let input_reader: Box<dyn BufRead> = match &args.arg_input {
Expand All @@ -93,10 +94,12 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
config::DEFAULT_WTR_BUFFER_CAPACITY,
fs::File::create(output_path)?,
)),
None => Box::new(io::BufWriter::with_capacity(
config::DEFAULT_WTR_BUFFER_CAPACITY,
stdout().lock(),
)),
None => {
Box::new(io::BufWriter::with_capacity(
config::DEFAULT_WTR_BUFFER_CAPACITY,
stdout().lock(),
))
},
};

let mut write_dupes = false;
Expand Down
20 changes: 9 additions & 11 deletions src/cmd/extsort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,14 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
// if we can detect the total memory, use 10% of it by default
// and up to --memory-limit (capped at 50%),
// otherwise, if we cannot detect the free memory use a default of 100 MB
let mem_limited_buffer = if System::IS_SUPPORTED {
let mut sys = System::new();
sys.refresh_memory();
(sys.total_memory() * 1000) / u8::min(args.flag_memory_limit.unwrap_or(10), 50) as u64
} else {
MEMORY_LIMITED_BUFFER
};
let mem_limited_buffer =
if System::IS_SUPPORTED {
let mut sys = System::new();
sys.refresh_memory();
(sys.total_memory() * 1000) / u8::min(args.flag_memory_limit.unwrap_or(10), 50) as u64
} else {
MEMORY_LIMITED_BUFFER
};
log::info!("{mem_limited_buffer} bytes used for in memory mergesort buffer...");

let mut input_reader: Box<dyn BufRead> = match &args.arg_input {
Expand Down Expand Up @@ -93,10 +94,7 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
fs::File::create(output_path)?,
))
},
None => Box::new(io::BufWriter::with_capacity(
RW_BUFFER_CAPACITY,
stdout().lock(),
)),
None => Box::new(io::BufWriter::with_capacity(RW_BUFFER_CAPACITY, stdout().lock())),
};

let sorter: ExternalSorter<String, io::Error, MemoryLimitedBufferBuilder> =
Expand Down
38 changes: 19 additions & 19 deletions src/cmd/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -500,10 +500,7 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
.template("{bar:37.red/white} {percent}%{msg} ({per_sec:7})")
.unwrap(),
);
error_progress.set_message(format!(
" of {} max errors",
HumanCount(args.flag_max_errors)
));
error_progress.set_message(format!(" of {} max errors", HumanCount(args.flag_max_errors)));
} else {
error_progress.set_draw_target(ProgressDrawTarget::hidden());
}
Expand Down Expand Up @@ -544,11 +541,12 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
.unwrap_or_else(|| "stdin.csv".to_string());

report_wtr = Config::new(&Some(report_path.clone() + FETCH_REPORT_SUFFIX)).writer()?;
let mut report_headers = if report == ReportKind::Detailed {
headers.clone()
} else {
csv::ByteRecord::new()
};
let mut report_headers =
if report == ReportKind::Detailed {
headers.clone()
} else {
csv::ByteRecord::new()
};
let rptcol_prefix = if report == ReportKind::Detailed {
FETCH_REPORT_PREFIX
} else {
Expand Down Expand Up @@ -594,16 +592,18 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
},
};
let mut final_value = String::with_capacity(150);
let mut final_response = FetchResponse {
response: String::new(),
status_code: 0_u16,
retries: 0_u8,
};
let empty_response = FetchResponse {
response: String::new(),
status_code: 0_u16,
retries: 0_u8,
};
let mut final_response =
FetchResponse {
response: String::new(),
status_code: 0_u16,
retries: 0_u8,
};
let empty_response =
FetchResponse {
response: String::new(),
status_code: 0_u16,
retries: 0_u8,
};
let mut running_error_count = 0_u64;
let mut running_success_count = 0_u64;
let mut was_cached;
Expand Down
Loading

0 comments on commit 4e590b2

Please sign in to comment.