Skip to content

Commit 4e590b2

Browse files
committed
cargo +nightly fmt
rustfmt has changed its formatting rules, apply it project wide
1 parent 21cebc4 commit 4e590b2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+1902
-1743
lines changed

src/cmd/dedup.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,12 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
119119
};
120120
let a = sel.select(&record);
121121
let b = sel.select(&next_record);
122-
let comparison = if ignore_case {
123-
iter_cmp_ignore_case(a, b)
124-
} else {
125-
iter_cmp(a, b)
126-
};
122+
let comparison =
123+
if ignore_case {
124+
iter_cmp_ignore_case(a, b)
125+
} else {
126+
iter_cmp(a, b)
127+
};
127128
match comparison {
128129
cmp::Ordering::Equal => {
129130
dupe_count += 1;

src/cmd/describegpt.rs

+69-66
Original file line numberDiff line numberDiff line change
@@ -185,61 +185,63 @@ fn is_valid_model(client: &Client, api_key: Option<&str>, args: &Args) -> CliRes
185185

186186
fn get_prompt_file(args: &Args) -> CliResult<PromptFile> {
187187
// Get prompt file if --prompt-file is used
188-
let prompt_file = if let Some(prompt_file) = args.flag_prompt_file.clone() {
189-
// Read prompt file
190-
let prompt_file = fs::read_to_string(prompt_file)?;
191-
// Try to parse prompt file as JSON, if error then show it in JSON format
192-
let prompt_file: PromptFile = match serde_json::from_str(&prompt_file) {
193-
Ok(val) => val,
194-
Err(e) => {
195-
let error_json = json!({"error": e.to_string()});
196-
return fail_clierror!("{error_json}");
197-
},
198-
};
199-
prompt_file
200-
}
201-
// Otherwise, get default prompt file
202-
else {
203-
#[allow(clippy::let_and_return)]
204-
let default_prompt_file = PromptFile {
205-
name: "My Prompt File".to_string(),
206-
description: "My prompt file for qsv's describegpt command.".to_string(),
207-
author: "My Name".to_string(),
208-
version: "1.0.0".to_string(),
209-
tokens: 50,
210-
dictionary_prompt: "Here are the columns for each field in a data dictionary:\n\n- \
211-
Type: the data type of this column\n- Label: a human-friendly \
212-
label for this column\n- Description: a full description for \
213-
this column (can be multiple sentences)\n\nGenerate a data \
214-
dictionary as aforementioned (in JSON output) where each field \
215-
has Name, Type, Label, and Description (so four columns in \
216-
total) based on the following summary statistics and frequency \
217-
data from a CSV file.\n\nSummary \
218-
Statistics:\n\n{stats}\n\nFrequency:\n\n{frequency}"
219-
.to_string(),
220-
description_prompt: "Generate only a description that is within 8 sentences about the \
221-
entire dataset{json_add} based on the following summary \
222-
statistics and frequency data derived from the CSV file it came \
223-
from.\n\nSummary \
224-
Statistics:\n\n{stats}\n\nFrequency:\n\n{frequency}\n\nDo not \
225-
output the summary statistics for each field. Do not output the \
226-
frequency for each field. Do not output data about each field \
227-
individually, but instead output about the dataset as a whole in \
228-
one 1-8 sentence description."
229-
.to_string(),
230-
tags_prompt: "A tag is a keyword or label that categorizes datasets with \
231-
other, similar datasets. Using the right tags makes it easier \
232-
for others to find and use datasets.\n\nGenerate single-word \
233-
tags{json_add} about the dataset (lowercase only and remove all \
234-
whitespace) based on the following summary statistics and \
235-
frequency data from a CSV file.\n\nSummary \
236-
Statistics:\n\n{stats}\n\nFrequency:\n\n{frequency}"
237-
.to_string(),
238-
json: true,
239-
jsonl: false,
188+
let prompt_file =
189+
if let Some(prompt_file) = args.flag_prompt_file.clone() {
190+
// Read prompt file
191+
let prompt_file = fs::read_to_string(prompt_file)?;
192+
// Try to parse prompt file as JSON, if error then show it in JSON format
193+
let prompt_file: PromptFile = match serde_json::from_str(&prompt_file) {
194+
Ok(val) => val,
195+
Err(e) => {
196+
let error_json = json!({"error": e.to_string()});
197+
return fail_clierror!("{error_json}");
198+
},
199+
};
200+
prompt_file
201+
}
202+
// Otherwise, get default prompt file
203+
else {
204+
#[allow(clippy::let_and_return)]
205+
let default_prompt_file = PromptFile {
206+
name: "My Prompt File".to_string(),
207+
description: "My prompt file for qsv's describegpt command.".to_string(),
208+
author: "My Name".to_string(),
209+
version: "1.0.0".to_string(),
210+
tokens: 50,
211+
dictionary_prompt: "Here are the columns for each field in a data \
212+
dictionary:\n\n- Type: the data type of this column\n- \
213+
Label: a human-friendly label for this column\n- \
214+
Description: a full description for this column (can be \
215+
multiple sentences)\n\nGenerate a data dictionary as \
216+
aforementioned (in JSON output) where each field has Name, \
217+
Type, Label, and Description (so four columns in total) \
218+
based on the following summary statistics and frequency data \
219+
from a CSV file.\n\nSummary \
220+
Statistics:\n\n{stats}\n\nFrequency:\n\n{frequency}"
221+
.to_string(),
222+
description_prompt: "Generate only a description that is within 8 sentences about \
223+
the entire dataset{json_add} based on the following summary \
224+
statistics and frequency data derived from the CSV file it \
225+
came from.\n\nSummary \
226+
Statistics:\n\n{stats}\n\nFrequency:\n\n{frequency}\n\nDo \
227+
not output the summary statistics for each field. Do not \
228+
output the frequency for each field. Do not output data \
229+
about each field individually, but instead output about the \
230+
dataset as a whole in one 1-8 sentence description."
231+
.to_string(),
232+
tags_prompt: "A tag is a keyword or label that categorizes datasets with \
233+
other, similar datasets. Using the right tags makes it \
234+
easier for others to find and use datasets.\n\nGenerate \
235+
single-word tags{json_add} about the dataset (lowercase only \
236+
and remove all whitespace) based on the following summary \
237+
statistics and frequency data from a CSV file.\n\nSummary \
238+
Statistics:\n\n{stats}\n\nFrequency:\n\n{frequency}"
239+
.to_string(),
240+
json: true,
241+
jsonl: false,
242+
};
243+
default_prompt_file
240244
};
241-
default_prompt_file
242-
};
243245
Ok(prompt_file)
244246
}
245247

@@ -297,18 +299,19 @@ fn get_completion(
297299
}
298300

299301
// If --max-tokens is specified, use it
300-
let max_tokens = if arg_is_some("--max-tokens") {
301-
args.flag_max_tokens
302-
}
303-
// If --prompt-file is used, use the tokens field from the prompt file
304-
else if args.flag_prompt_file.clone().is_some() {
305-
let prompt_file = get_prompt_file(args)?;
306-
prompt_file.tokens
307-
}
308-
// Else use the default max tokens value in USAGE
309-
else {
310-
args.flag_max_tokens
311-
};
302+
let max_tokens =
303+
if arg_is_some("--max-tokens") {
304+
args.flag_max_tokens
305+
}
306+
// If --prompt-file is used, use the tokens field from the prompt file
307+
else if args.flag_prompt_file.clone().is_some() {
308+
let prompt_file = get_prompt_file(args)?;
309+
prompt_file.tokens
310+
}
311+
// Else use the default max tokens value in USAGE
312+
else {
313+
args.flag_max_tokens
314+
};
312315

313316
// Create request data
314317
let request_data = json!({

src/cmd/excel.rs

+30-27
Original file line numberDiff line numberDiff line change
@@ -226,32 +226,34 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
226226
.and_then(std::ffi::OsStr::to_str)
227227
.unwrap_or_default()
228228
.to_lowercase();
229-
let ods_flag = match format.as_str() {
230-
"xls" | "xlsx" | "xlsm" | "xlsb" => false,
231-
"ods" => true,
232-
_ => {
233-
return fail_incorrectusage_clierror!(
234-
"\"{format}\" not supported. The excel command only supports the following file \
235-
formats - xls, xlsx, xlsm, xlsb and ods."
236-
);
237-
},
238-
};
229+
let ods_flag =
230+
match format.as_str() {
231+
"xls" | "xlsx" | "xlsm" | "xlsb" => false,
232+
"ods" => true,
233+
_ => {
234+
return fail_incorrectusage_clierror!(
235+
"\"{format}\" not supported. The excel command only supports the following \
236+
file formats - xls, xlsx, xlsm, xlsb and ods."
237+
);
238+
},
239+
};
239240

240241
let requested_range = args.flag_range.to_lowercase();
241242

242-
let mut workbook = match open_workbook_auto(path) {
243-
Ok(workbook) => workbook,
244-
Err(e) => {
245-
let es = e.to_string();
246-
// password protected errors come in different flavors for Excel
247-
if es.starts_with("Xls error: Cfb error")
248-
|| es.starts_with("Xlsx error: Zip error: invalid Zip archive")
249-
{
250-
return fail_clierror!("{path} may be a password-protected workbook: {e}.");
251-
}
252-
return fail_clierror!("Cannot open workbook: {e}.");
253-
},
254-
};
243+
let mut workbook =
244+
match open_workbook_auto(path) {
245+
Ok(workbook) => workbook,
246+
Err(e) => {
247+
let es = e.to_string();
248+
// password protected errors come in different flavors for Excel
249+
if es.starts_with("Xls error: Cfb error")
250+
|| es.starts_with("Xlsx error: Zip error: invalid Zip archive")
251+
{
252+
return fail_clierror!("{path} may be a password-protected workbook: {e}.");
253+
}
254+
return fail_clierror!("Cannot open workbook: {e}.");
255+
},
256+
};
255257

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

267-
let mut wtr = Config::new(&args.flag_output)
268-
.flexible(args.flag_flexible)
269-
.delimiter(args.flag_delimiter)
270-
.writer()?;
269+
let mut wtr =
270+
Config::new(&args.flag_output)
271+
.flexible(args.flag_flexible)
272+
.delimiter(args.flag_delimiter)
273+
.writer()?;
271274

272275
// set Metadata Mode
273276
let first_letter = args.flag_metadata.chars().next().unwrap_or_default();

src/cmd/extdedup.rs

+14-11
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,14 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
6363
// if we can detect the total memory, use 10% of it by default
6464
// and up to --memory-limit (capped at 50%),
6565
// otherwise, if we cannot detect the free memory use a default of 100 MB
66-
let mem_limited_buffer = if System::IS_SUPPORTED {
67-
let mut sys = System::new();
68-
sys.refresh_memory();
69-
(sys.total_memory() * 1000) / u8::min(args.flag_memory_limit.unwrap_or(10), 50) as u64
70-
} else {
71-
MEMORY_LIMITED_BUFFER
72-
};
66+
let mem_limited_buffer =
67+
if System::IS_SUPPORTED {
68+
let mut sys = System::new();
69+
sys.refresh_memory();
70+
(sys.total_memory() * 1000) / u8::min(args.flag_memory_limit.unwrap_or(10), 50) as u64
71+
} else {
72+
MEMORY_LIMITED_BUFFER
73+
};
7374
log::info!("{mem_limited_buffer} bytes used for memory buffer for on-disk hash table...");
7475

7576
let input_reader: Box<dyn BufRead> = match &args.arg_input {
@@ -93,10 +94,12 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
9394
config::DEFAULT_WTR_BUFFER_CAPACITY,
9495
fs::File::create(output_path)?,
9596
)),
96-
None => Box::new(io::BufWriter::with_capacity(
97-
config::DEFAULT_WTR_BUFFER_CAPACITY,
98-
stdout().lock(),
99-
)),
97+
None => {
98+
Box::new(io::BufWriter::with_capacity(
99+
config::DEFAULT_WTR_BUFFER_CAPACITY,
100+
stdout().lock(),
101+
))
102+
},
100103
};
101104

102105
let mut write_dupes = false;

src/cmd/extsort.rs

+9-11
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,14 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
5555
// if we can detect the total memory, use 10% of it by default
5656
// and up to --memory-limit (capped at 50%),
5757
// otherwise, if we cannot detect the free memory use a default of 100 MB
58-
let mem_limited_buffer = if System::IS_SUPPORTED {
59-
let mut sys = System::new();
60-
sys.refresh_memory();
61-
(sys.total_memory() * 1000) / u8::min(args.flag_memory_limit.unwrap_or(10), 50) as u64
62-
} else {
63-
MEMORY_LIMITED_BUFFER
64-
};
58+
let mem_limited_buffer =
59+
if System::IS_SUPPORTED {
60+
let mut sys = System::new();
61+
sys.refresh_memory();
62+
(sys.total_memory() * 1000) / u8::min(args.flag_memory_limit.unwrap_or(10), 50) as u64
63+
} else {
64+
MEMORY_LIMITED_BUFFER
65+
};
6566
log::info!("{mem_limited_buffer} bytes used for in memory mergesort buffer...");
6667

6768
let mut input_reader: Box<dyn BufRead> = match &args.arg_input {
@@ -93,10 +94,7 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
9394
fs::File::create(output_path)?,
9495
))
9596
},
96-
None => Box::new(io::BufWriter::with_capacity(
97-
RW_BUFFER_CAPACITY,
98-
stdout().lock(),
99-
)),
97+
None => Box::new(io::BufWriter::with_capacity(RW_BUFFER_CAPACITY, stdout().lock())),
10098
};
10199

102100
let sorter: ExternalSorter<String, io::Error, MemoryLimitedBufferBuilder> =

src/cmd/fetch.rs

+19-19
Original file line numberDiff line numberDiff line change
@@ -500,10 +500,7 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
500500
.template("{bar:37.red/white} {percent}%{msg} ({per_sec:7})")
501501
.unwrap(),
502502
);
503-
error_progress.set_message(format!(
504-
" of {} max errors",
505-
HumanCount(args.flag_max_errors)
506-
));
503+
error_progress.set_message(format!(" of {} max errors", HumanCount(args.flag_max_errors)));
507504
} else {
508505
error_progress.set_draw_target(ProgressDrawTarget::hidden());
509506
}
@@ -544,11 +541,12 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
544541
.unwrap_or_else(|| "stdin.csv".to_string());
545542

546543
report_wtr = Config::new(&Some(report_path.clone() + FETCH_REPORT_SUFFIX)).writer()?;
547-
let mut report_headers = if report == ReportKind::Detailed {
548-
headers.clone()
549-
} else {
550-
csv::ByteRecord::new()
551-
};
544+
let mut report_headers =
545+
if report == ReportKind::Detailed {
546+
headers.clone()
547+
} else {
548+
csv::ByteRecord::new()
549+
};
552550
let rptcol_prefix = if report == ReportKind::Detailed {
553551
FETCH_REPORT_PREFIX
554552
} else {
@@ -594,16 +592,18 @@ pub fn run(argv: &[&str]) -> CliResult<()> {
594592
},
595593
};
596594
let mut final_value = String::with_capacity(150);
597-
let mut final_response = FetchResponse {
598-
response: String::new(),
599-
status_code: 0_u16,
600-
retries: 0_u8,
601-
};
602-
let empty_response = FetchResponse {
603-
response: String::new(),
604-
status_code: 0_u16,
605-
retries: 0_u8,
606-
};
595+
let mut final_response =
596+
FetchResponse {
597+
response: String::new(),
598+
status_code: 0_u16,
599+
retries: 0_u8,
600+
};
601+
let empty_response =
602+
FetchResponse {
603+
response: String::new(),
604+
status_code: 0_u16,
605+
retries: 0_u8,
606+
};
607607
let mut running_error_count = 0_u64;
608608
let mut running_success_count = 0_u64;
609609
let mut was_cached;

0 commit comments

Comments
 (0)