ok/jj
1
0
Fork 0
forked from mirrors/jj

cli: move some debug commands to new (non-hidden) support group

The `jj debug` commands are hidden from help and are described as
"Low-level commands not intended for users", but e.g. `jj debug
completion` is intended for users, and should be visible in the help
output.
This commit is contained in:
Martin von Zweigbergk 2023-03-16 21:48:05 -07:00 committed by Martin von Zweigbergk
parent ce098a729a
commit e2b4d7058d
6 changed files with 114 additions and 74 deletions

View file

@ -50,6 +50,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* `jj hide` (alias for `jj abandon`) is no longer available. Use `jj abandon` * `jj hide` (alias for `jj abandon`) is no longer available. Use `jj abandon`
instead. instead.
* `jj debug completion`, `jj debug mangen` and `jj debug config-schema` have
been moved from `jj debug` to `jj support`.
### Fixed bugs ### Fixed bugs
* Modify/delete conflicts now include context lines * Modify/delete conflicts now include context lines

View file

@ -254,30 +254,30 @@ email = "martinvonz@google.com"
## Command-line completion ## Command-line completion
To set up command-line completion, source the output of To set up command-line completion, source the output of
`jj debug completion --bash/--zsh/--fish`. Exactly how to source it depends on `jj support completion --bash/--zsh/--fish`. Exactly how to source it depends on
your shell. your shell.
### Bash ### Bash
```shell script ```shell script
source <(jj debug completion) # --bash is the default source <(jj support completion) # --bash is the default
``` ```
### Zsh ### Zsh
```shell script ```shell script
autoload -U compinit autoload -U compinit
compinit compinit
source <(jj debug completion --zsh | sed '$d') # remove the last line source <(jj support completion --zsh | sed '$d') # remove the last line
compdef _jj jj compdef _jj jj
``` ```
### Fish ### Fish
```shell script ```shell script
jj debug completion --fish | source jj support completion --fish | source
``` ```
### Xonsh ### Xonsh
```shell script ```shell script
source-bash $(jj debug completion) source-bash $(jj support completion)
``` ```

View file

@ -63,14 +63,14 @@
libiconv libiconv
]; ];
postInstall = '' postInstall = ''
$out/bin/jj debug mangen > ./jj.1 $out/bin/jj support mangen > ./jj.1
installManPage ./jj.1 installManPage ./jj.1
$out/bin/jj debug completion --bash > ./completions.bash $out/bin/jj support completion --bash > ./completions.bash
installShellCompletion --bash --name ${pname}.bash ./completions.bash installShellCompletion --bash --name ${pname}.bash ./completions.bash
$out/bin/jj debug completion --fish > ./completions.fish $out/bin/jj support completion --fish > ./completions.fish
installShellCompletion --fish --name ${pname}.fish ./completions.fish installShellCompletion --fish --name ${pname}.fish ./completions.fish
$out/bin/jj debug completion --zsh > ./completions.zsh $out/bin/jj support completion --zsh > ./completions.zsh
installShellCompletion --zsh --name _${pname} ./completions.zsh installShellCompletion --zsh --name _${pname} ./completions.zsh
''; '';
}; };

View file

@ -109,6 +109,8 @@ enum Commands {
Split(SplitArgs), Split(SplitArgs),
Squash(SquashArgs), Squash(SquashArgs),
Status(StatusArgs), Status(StatusArgs),
#[command(subcommand)]
Support(SupportCommands),
/// Undo an operation (shortcut for `jj op undo`) /// Undo an operation (shortcut for `jj op undo`)
Undo(operation::OperationUndoArgs), Undo(operation::OperationUndoArgs),
Unsquash(UnsquashArgs), Unsquash(UnsquashArgs),
@ -866,13 +868,55 @@ struct SparseArgs {
list: bool, list: bool,
} }
/// Infrequently used commands such as for generating shell completions
#[derive(Subcommand, Clone, Debug)]
enum SupportCommands {
Completion(SupportCompletionArgs),
Mangen(SupportMangenArgs),
ConfigSchema(SupportConfigSchemaArgs),
}
/// Print a command-line-completion script
#[derive(clap::Args, Clone, Debug)]
struct SupportCompletionArgs {
/// Print a completion script for Bash
///
/// Apply it by running this:
///
/// source <(jj support completion)
#[arg(long, verbatim_doc_comment)]
bash: bool,
/// Print a completion script for Fish
///
/// Apply it by running this:
///
/// jj support completion --fish | source
#[arg(long, verbatim_doc_comment)]
fish: bool,
/// Print a completion script for Zsh
///
/// Apply it by running this:
///
/// autoload -U compinit
/// compinit
/// source <(jj support completion --zsh | sed '$d') # remove the last line
/// compdef _jj jj
#[arg(long, verbatim_doc_comment)]
zsh: bool,
}
/// Print a ROFF (manpage)
#[derive(clap::Args, Clone, Debug)]
struct SupportMangenArgs {}
/// Print the JSON schema for the jj TOML config format.
#[derive(clap::Args, Clone, Debug)]
struct SupportConfigSchemaArgs {}
/// Low-level commands not intended for users /// Low-level commands not intended for users
#[derive(Subcommand, Clone, Debug)] #[derive(Subcommand, Clone, Debug)]
#[command(hide = true)] #[command(hide = true)]
enum DebugCommands { enum DebugCommands {
Completion(DebugCompletionArgs),
Mangen(DebugMangenArgs),
ConfigSchema(DebugConfigSchemaArgs),
#[command(name = "resolverev")] #[command(name = "resolverev")]
ResolveRev(DebugResolveRevArgs), ResolveRev(DebugResolveRevArgs),
#[command(name = "workingcopy")] #[command(name = "workingcopy")]
@ -884,43 +928,6 @@ enum DebugCommands {
Operation(DebugOperationArgs), Operation(DebugOperationArgs),
} }
/// Print a command-line-completion script
#[derive(clap::Args, Clone, Debug)]
struct DebugCompletionArgs {
/// Print a completion script for Bash
///
/// Apply it by running this:
///
/// source <(jj debug completion)
#[arg(long, verbatim_doc_comment)]
bash: bool,
/// Print a completion script for Fish
///
/// Apply it by running this:
///
/// jj debug completion --fish | source
#[arg(long, verbatim_doc_comment)]
fish: bool,
/// Print a completion script for Zsh
///
/// Apply it by running this:
///
/// autoload -U compinit
/// compinit
/// source <(jj debug completion --zsh | sed '$d') # remove the last line
/// compdef _jj jj
#[arg(long, verbatim_doc_comment)]
zsh: bool,
}
/// Print a ROFF (manpage)
#[derive(clap::Args, Clone, Debug)]
struct DebugMangenArgs {}
/// Print the JSON schema for the jj TOML config format.
#[derive(clap::Args, Clone, Debug)]
struct DebugConfigSchemaArgs {}
/// Resolve a revision identifier to its full ID /// Resolve a revision identifier to its full ID
#[derive(clap::Args, Clone, Debug)] #[derive(clap::Args, Clone, Debug)]
struct DebugResolveRevArgs { struct DebugResolveRevArgs {
@ -3036,13 +3043,13 @@ fn make_branch_term(branch_names: &[impl AsRef<str>]) -> String {
} }
} }
fn cmd_debug( fn cmd_support(
ui: &mut Ui, ui: &mut Ui,
command: &CommandHelper, command: &CommandHelper,
subcommand: &DebugCommands, subcommand: &SupportCommands,
) -> Result<(), CommandError> { ) -> Result<(), CommandError> {
match subcommand { match subcommand {
DebugCommands::Completion(completion_matches) => { SupportCommands::Completion(completion_matches) => {
let mut app = command.app().clone(); let mut app = command.app().clone();
let mut buf = vec![]; let mut buf = vec![];
let shell = if completion_matches.zsh { let shell = if completion_matches.zsh {
@ -3055,17 +3062,27 @@ fn cmd_debug(
clap_complete::generate(shell, &mut app, "jj", &mut buf); clap_complete::generate(shell, &mut app, "jj", &mut buf);
ui.stdout_formatter().write_all(&buf)?; ui.stdout_formatter().write_all(&buf)?;
} }
DebugCommands::Mangen(_mangen_matches) => { SupportCommands::Mangen(_mangen_matches) => {
let mut buf = vec![]; let mut buf = vec![];
let man = clap_mangen::Man::new(command.app().clone()); let man = clap_mangen::Man::new(command.app().clone());
man.render(&mut buf)?; man.render(&mut buf)?;
ui.stdout_formatter().write_all(&buf)?; ui.stdout_formatter().write_all(&buf)?;
} }
DebugCommands::ConfigSchema(_config_schema_matches) => { SupportCommands::ConfigSchema(_config_schema_matches) => {
// TODO(#879): Consider generating entire schema dynamically vs. static file. // TODO(#879): Consider generating entire schema dynamically vs. static file.
let buf = include_bytes!("../config-schema.json"); let buf = include_bytes!("../config-schema.json");
ui.stdout_formatter().write_all(buf)?; ui.stdout_formatter().write_all(buf)?;
} }
}
Ok(())
}
fn cmd_debug(
ui: &mut Ui,
command: &CommandHelper,
subcommand: &DebugCommands,
) -> Result<(), CommandError> {
match subcommand {
DebugCommands::ResolveRev(resolve_matches) => { DebugCommands::ResolveRev(resolve_matches) => {
let workspace_command = command.workspace_helper(ui)?; let workspace_command = command.workspace_helper(ui)?;
let commit = workspace_command.resolve_single_rev(&resolve_matches.revision)?; let commit = workspace_command.resolve_single_rev(&resolve_matches.revision)?;
@ -3446,6 +3463,7 @@ pub fn run_command(
Commands::Workspace(sub_args) => cmd_workspace(ui, command_helper, sub_args), Commands::Workspace(sub_args) => cmd_workspace(ui, command_helper, sub_args),
Commands::Sparse(sub_args) => cmd_sparse(ui, command_helper, sub_args), Commands::Sparse(sub_args) => cmd_sparse(ui, command_helper, sub_args),
Commands::Git(sub_args) => git::cmd_git(ui, command_helper, sub_args), Commands::Git(sub_args) => git::cmd_git(ui, command_helper, sub_args),
Commands::Support(sub_args) => cmd_support(ui, command_helper, sub_args),
Commands::Debug(sub_args) => cmd_debug(ui, command_helper, sub_args), Commands::Debug(sub_args) => cmd_debug(ui, command_helper, sub_args),
} }
} }

View file

@ -19,26 +19,6 @@ use crate::common::TestEnvironment;
pub mod common; pub mod common;
#[test]
fn test_debug_config_schema() {
let test_env = TestEnvironment::default();
let stdout = test_env.jj_cmd_success(test_env.env_root(), &["debug", "config-schema"]);
// Validate partial snapshot, redacting any lines nested 2+ indent levels.
insta::with_settings!({filters => vec![(r"(?m)(^ .*$\r?\n)+", " [...]\n")]}, {
assert_snapshot!(stdout, @r###"
{
"$schema": "http://json-schema.org/draft-07/schema",
"title": "Jujutsu config",
"type": "object",
"description": "User configuration for Jujutsu VCS. See https://github.com/martinvonz/jj/blob/main/docs/config.md for details",
"properties": {
[...]
}
}
"###)
});
}
#[test] #[test]
fn test_debug_index() { fn test_debug_index() {
let test_env = TestEnvironment::default(); let test_env = TestEnvironment::default();

View file

@ -0,0 +1,39 @@
// Copyright 2023 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 insta::assert_snapshot;
use crate::common::TestEnvironment;
pub mod common;
#[test]
fn test_support_config_schema() {
let test_env = TestEnvironment::default();
let stdout = test_env.jj_cmd_success(test_env.env_root(), &["support", "config-schema"]);
// Validate partial snapshot, redacting any lines nested 2+ indent levels.
insta::with_settings!({filters => vec![(r"(?m)(^ .*$\r?\n)+", " [...]\n")]}, {
assert_snapshot!(stdout, @r###"
{
"$schema": "http://json-schema.org/draft-07/schema",
"title": "Jujutsu config",
"type": "object",
"description": "User configuration for Jujutsu VCS. See https://github.com/martinvonz/jj/blob/main/docs/config.md for details",
"properties": {
[...]
}
}
"###)
});
}