1
0
mirror of https://github.com/sharkdp/bat.git synced 2025-09-28 08:02:28 +01:00

Compare commits

...

5 Commits

Author SHA1 Message Date
Keith Hall
6540f38827 cargo fmt 2025-09-27 23:54:52 +03:00
Keith Hall
f605db22e3 Fix help/version/diagnostic commands with invalid config 2025-09-27 23:33:10 +03:00
Keith Hall
2c87b9480f Bump jsonnet syntax dependency 2025-09-27 16:41:05 +03:00
Keith Hall
2ae4253577 Merge pull request #3397 from sharkdp/dependabot/submodules/assets/syntaxes/02_Extra/VimL-fe5bf5e
build(deps): bump assets/syntaxes/02_Extra/VimL from `ee85822` to `fe5bf5e`
2025-09-27 16:12:39 +03:00
dependabot[bot]
0d468b023a build(deps): bump assets/syntaxes/02_Extra/VimL
Bumps [assets/syntaxes/02_Extra/VimL](https://github.com/SalGnt/Sublime-VimL) from `ee85822` to `fe5bf5e`.
- [Release notes](https://github.com/SalGnt/Sublime-VimL/releases)
- [Commits](ee85822cbe...fe5bf5ea70)

---
updated-dependencies:
- dependency-name: assets/syntaxes/02_Extra/VimL
  dependency-version: fe5bf5ea7055b35035438c64d822aae1f1dfdb41
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2025-09-27 15:59:52 +03:00
4 changed files with 97 additions and 5 deletions

View File

@@ -57,15 +57,30 @@ impl App {
}
fn matches(interactive_output: bool) -> Result<ArgMatches> {
// Check if we should skip config file processing for special arguments
// that don't require full application setup (help, version, diagnostic)
let should_skip_config = wild::args_os().any(|arg| {
matches!(
arg.to_str(),
Some("-h" | "--help" | "-V" | "--version" | "--diagnostic" | "--diagnostics")
)
});
let args = if wild::args_os().nth(1) == Some("cache".into()) {
// Skip the config file and env vars
wild::args_os().collect::<Vec<_>>()
} else if wild::args_os().any(|arg| arg == "--no-config") {
// Skip the arguments in bats config file
} else if wild::args_os().any(|arg| arg == "--no-config") || should_skip_config {
// Skip the arguments in bats config file when --no-config is present
// or when user requests help, version, or diagnostic information
let mut cli_args = wild::args_os();
let mut args = get_args_from_env_vars();
let mut args = if should_skip_config {
// For special commands, don't even try to load env vars that might fail
vec![]
} else {
get_args_from_env_vars()
};
// Put the zero-th CLI argument (program name) first
args.insert(0, cli_args.next().unwrap());

View File

@@ -1286,6 +1286,83 @@ fn diagnostic_sanity_check() {
.stderr("");
}
#[test]
fn help_works_with_invalid_config() {
let tmp_dir = tempdir().expect("can create temporary directory");
let tmp_config_path = tmp_dir.path().join("invalid-config.conf");
// Write an invalid config file
std::fs::write(&tmp_config_path, "--invalid-option").expect("can write config file");
// --help should work despite invalid config
bat_with_config()
.env("BAT_CONFIG_PATH", tmp_config_path.to_str().unwrap())
.arg("--help")
.assert()
.success()
.stdout(predicate::str::contains(
"A cat(1) clone with syntax highlighting",
));
// -h should also work
bat_with_config()
.env("BAT_CONFIG_PATH", tmp_config_path.to_str().unwrap())
.arg("-h")
.assert()
.success()
.stdout(predicate::str::contains("A cat(1) clone with wings"));
}
#[test]
fn version_works_with_invalid_config() {
let tmp_dir = tempdir().expect("can create temporary directory");
let tmp_config_path = tmp_dir.path().join("invalid-config.conf");
// Write an invalid config file
std::fs::write(&tmp_config_path, "--invalid-option").expect("can write config file");
// --version should work despite invalid config
bat_with_config()
.env("BAT_CONFIG_PATH", tmp_config_path.to_str().unwrap())
.arg("--version")
.assert()
.success()
.stdout(predicate::str::contains("bat "));
// -V should also work
bat_with_config()
.env("BAT_CONFIG_PATH", tmp_config_path.to_str().unwrap())
.arg("-V")
.assert()
.success()
.stdout(predicate::str::contains("bat "));
}
#[test]
fn diagnostic_works_with_invalid_config() {
let tmp_dir = tempdir().expect("can create temporary directory");
let tmp_config_path = tmp_dir.path().join("invalid-config.conf");
// Write an invalid config file
std::fs::write(&tmp_config_path, "--invalid-option").expect("can write config file");
// --diagnostic should work despite invalid config
bat_with_config()
.env("BAT_CONFIG_PATH", tmp_config_path.to_str().unwrap())
.arg("--diagnostic")
.assert()
.success()
.stdout(predicate::str::contains("#### Software version"));
// --diagnostics (alias) should also work
bat_with_config()
.env("BAT_CONFIG_PATH", tmp_config_path.to_str().unwrap())
.arg("--diagnostics")
.assert()
.success()
.stdout(predicate::str::contains("#### Software version"));
}
#[test]
fn config_location_test() {
bat_with_config()