-
Notifications
You must be signed in to change notification settings - Fork 319
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cli: Move flags if help command is used
The default clap's help command doesn't have the ability to accept flags (e.g --no-pager). So move them if the help command is used. Fixes: #4501
- Loading branch information
Showing
4 changed files
with
94 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright 2024 The Jujutsu Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
use crate::common::TestEnvironment; | ||
|
||
#[test] | ||
fn test_help() { | ||
let test_env = TestEnvironment::default(); | ||
|
||
let help_cmd_stdout = test_env.jj_cmd_success(test_env.env_root(), &["help"]); | ||
// The help command output should be equal to the long --help flag | ||
let help_flag_stdout = test_env.jj_cmd_success(test_env.env_root(), &["--help"]); | ||
assert_eq!(help_cmd_stdout, help_flag_stdout); | ||
|
||
// Help command should work with commands | ||
let help_cmd_stdout = test_env.jj_cmd_success(test_env.env_root(), &["help", "log"]); | ||
let help_flag_stdout = test_env.jj_cmd_success(test_env.env_root(), &["log", "--help"]); | ||
assert_eq!(help_cmd_stdout, help_flag_stdout); | ||
|
||
// Help command should work with subcommands | ||
let help_cmd_stdout = | ||
test_env.jj_cmd_success(test_env.env_root(), &["help", "workspace", "add"]); | ||
let help_flag_stdout = | ||
test_env.jj_cmd_success(test_env.env_root(), &["workspace", "add", "--help"]); | ||
assert_eq!(help_cmd_stdout, help_flag_stdout); | ||
|
||
// Help command should work recursively | ||
let help_cmd_stdout = | ||
test_env.jj_cmd_success(test_env.env_root(), &["workspace", "help", "add"]); | ||
let help_flag_stdout = | ||
test_env.jj_cmd_success(test_env.env_root(), &["workspace", "add", "--help"]); | ||
assert_eq!(help_cmd_stdout, help_flag_stdout); | ||
|
||
let _ = test_env.jj_cmd_failure(test_env.env_root(), &["workspace", "add", "help"]); | ||
} |