Skip to content

Commit 4ba5db0

Browse files
feat(sort): add warning messages for obsolescent keys and options (#9900)
* feat(sort): add warning messages for obsolescent keys and options Added localized warning messages in en-US.ftl for various sort command issues, including obsolescent key formats, ignored options, and locale-related warnings. Implemented LegacyKeyWarning struct and GlobalOptionFlags in sort.rs to detect deprecated key syntax (e.g., +field -field) and suggest modern -k replacements, improving user guidance and compatibility. * refactor(sort): remove stable and unique flags from GlobalOptionFlags Removes the unused `stable` and `unique` boolean fields from the GlobalOptionFlags struct and their initialization in the impl block, simplifying the code by eliminating redundant options. * feat(sort): allow multiple sort modes by removing mutual conflicts Previously, sort mode flags were mutually exclusive, preventing users from specifying more than one mode. This change removes the conflicts to enable combining sort options for more flexible sorting behavior. * refactor(sort): separate arg_index and key_index in legacy key warnings - Update LegacyKeyWarning struct to include arg_index and make key_index optional - Modify preprocess_legacy_args to set arg_index instead of key_index during parsing - Add index_legacy_warnings function to compute key_index after arg processing - Adjust emit_debug_warnings to match updated key_index type - This ensures accurate indexing for legacy key warnings in sort utility * feat(sort): add legacy sort key detection for '+' prefixed arguments - Introduce `starts_with_plus` function to check for arguments starting with '+' in a platform-specific manner - Modify `parse_sort_arguments` to detect and process legacy sort keys, enabling proper handling of deprecated options with warnings - This ensures backward compatibility for users relying on old sort syntax while guiding migration to modern flags * refactor(sort): simplify legacy args preprocessing Remove intermediate vector creation in preprocess_legacy_args and streamline the handling of legacy '+' prefixed arguments to improve efficiency and readability without altering functionality. Additionally, refactor uumain to directly index legacy warnings when present. * refactor(sort/benches): optimize locale UTF8 benchmarks by predefining args Move output file creation and argument setup outside benchmark loops in sort_locale_utf8_bench.rs to avoid measuring initialization time in each iteration, ensuring accurate performance measurements for sorting operations. --------- Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
1 parent 574f6ba commit 4ba5db0

3 files changed

Lines changed: 438 additions & 56 deletions

File tree

src/uu/sort/benches/sort_locale_utf8_bench.rs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,10 @@ fn sort_ascii_utf8_locale(bencher: Bencher) {
2121
let output_file = NamedTempFile::new().unwrap();
2222
let output_path = output_file.path().to_str().unwrap().to_string();
2323

24+
let args = ["-o", &output_path, file_path.to_str().unwrap()];
25+
black_box(run_util_function(uumain, &args));
2426
bencher.bench(|| {
25-
black_box(run_util_function(
26-
uumain,
27-
&["-o", &output_path, file_path.to_str().unwrap()],
28-
));
27+
black_box(run_util_function(uumain, &args));
2928
});
3029
}
3130

@@ -37,11 +36,10 @@ fn sort_mixed_utf8_locale(bencher: Bencher) {
3736
let output_file = NamedTempFile::new().unwrap();
3837
let output_path = output_file.path().to_str().unwrap().to_string();
3938

39+
let args = ["-o", &output_path, file_path.to_str().unwrap()];
40+
black_box(run_util_function(uumain, &args));
4041
bencher.bench(|| {
41-
black_box(run_util_function(
42-
uumain,
43-
&["-o", &output_path, file_path.to_str().unwrap()],
44-
));
42+
black_box(run_util_function(uumain, &args));
4543
});
4644
}
4745

@@ -54,12 +52,13 @@ fn sort_numeric_utf8_locale(bencher: Bencher) {
5452
data.extend_from_slice(line.as_bytes());
5553
}
5654
let file_path = setup_test_file(&data);
55+
let output_file = NamedTempFile::new().unwrap();
56+
let output_path = output_file.path().to_str().unwrap().to_string();
5757

58+
let args = ["-n", "-o", &output_path, file_path.to_str().unwrap()];
59+
black_box(run_util_function(uumain, &args));
5860
bencher.bench(|| {
59-
black_box(run_util_function(
60-
uumain,
61-
&["-n", file_path.to_str().unwrap()],
62-
));
61+
black_box(run_util_function(uumain, &args));
6362
});
6463
}
6564

@@ -68,12 +67,13 @@ fn sort_numeric_utf8_locale(bencher: Bencher) {
6867
fn sort_reverse_utf8_locale(bencher: Bencher) {
6968
let data = text_data::generate_mixed_locale_data(50_000);
7069
let file_path = setup_test_file(&data);
70+
let output_file = NamedTempFile::new().unwrap();
71+
let output_path = output_file.path().to_str().unwrap().to_string();
7172

73+
let args = ["-r", "-o", &output_path, file_path.to_str().unwrap()];
74+
black_box(run_util_function(uumain, &args));
7275
bencher.bench(|| {
73-
black_box(run_util_function(
74-
uumain,
75-
&["-r", file_path.to_str().unwrap()],
76-
));
76+
black_box(run_util_function(uumain, &args));
7777
});
7878
}
7979

@@ -82,12 +82,13 @@ fn sort_reverse_utf8_locale(bencher: Bencher) {
8282
fn sort_unique_utf8_locale(bencher: Bencher) {
8383
let data = text_data::generate_mixed_locale_data(50_000);
8484
let file_path = setup_test_file(&data);
85+
let output_file = NamedTempFile::new().unwrap();
86+
let output_path = output_file.path().to_str().unwrap().to_string();
8587

88+
let args = ["-u", "-o", &output_path, file_path.to_str().unwrap()];
89+
black_box(run_util_function(uumain, &args));
8690
bencher.bench(|| {
87-
black_box(run_util_function(
88-
uumain,
89-
&["-u", file_path.to_str().unwrap()],
90-
));
91+
black_box(run_util_function(uumain, &args));
9192
});
9293
}
9394

src/uu/sort/locales/en-US.ftl

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,22 @@ sort-error-write-failed = write failed: {$output}
5151
sort-failed-to-delete-temporary-directory = failed to delete temporary directory: {$error}
5252
sort-failed-to-set-up-signal-handler = failed to set up signal handler: {$error}
5353
54+
# Warning messages
55+
sort-warning-failed-to-set-locale = failed to set locale
56+
sort-warning-simple-byte-comparison = text ordering performed using simple byte comparison
57+
sort-warning-key-zero-width = key {$key} has zero width and will be ignored
58+
sort-warning-key-numeric-spans-fields = key {$key} is numeric and spans multiple fields
59+
sort-warning-leading-blanks-significant = leading blanks are significant in key {$key}; consider also specifying 'b'
60+
sort-warning-numbers-use-decimal-point = numbers use '.' as a decimal point in this locale
61+
sort-warning-options-ignored = options '-{$options}' are ignored
62+
sort-warning-option-ignored = option '-{$option}' is ignored
63+
sort-warning-option-reverse-last-resort = option '-r' only applies to last-resort comparison
64+
sort-warning-obsolescent-key = obsolescent key '{$key}' used; consider '-k {$replacement}' instead
65+
sort-warning-separator-grouping = field separator '{$sep}' is treated as a group separator in numbers
66+
sort-warning-separator-decimal = field separator '{$sep}' is treated as a decimal point in numbers
67+
sort-warning-separator-minus = field separator '{$sep}' is treated as a minus sign in numbers
68+
sort-warning-separator-plus = field separator '{$sep}' is treated as a plus sign in numbers
69+
5470
# Help messages
5571
sort-help-help = Print help information.
5672
sort-help-version = Print version information.

0 commit comments

Comments
 (0)