mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-16 00:56:23 +00:00
cli: split up cmd_util()
into one function per subcommand
This matches how most other commands with subcommands are handled.
This commit is contained in:
parent
35f718f212
commit
5e0b14a8bd
1 changed files with 44 additions and 24 deletions
|
@ -71,30 +71,50 @@ pub(crate) fn cmd_util(
|
||||||
subcommand: &UtilCommand,
|
subcommand: &UtilCommand,
|
||||||
) -> Result<(), CommandError> {
|
) -> Result<(), CommandError> {
|
||||||
match subcommand {
|
match subcommand {
|
||||||
UtilCommand::Completion(completion_args) => {
|
UtilCommand::Completion(args) => cmd_util_completion(ui, command, args),
|
||||||
|
UtilCommand::Mangen(args) => cmd_util_mangen(ui, command, args),
|
||||||
|
UtilCommand::ConfigSchema(args) => cmd_util_config_schema(ui, command, args),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn cmd_util_completion(
|
||||||
|
ui: &mut Ui,
|
||||||
|
command: &CommandHelper,
|
||||||
|
args: &UtilCompletionArgs,
|
||||||
|
) -> Result<(), CommandError> {
|
||||||
let mut app = command.app().clone();
|
let mut app = command.app().clone();
|
||||||
let mut buf = vec![];
|
let mut buf = vec![];
|
||||||
let shell = if completion_args.zsh {
|
let shell = if args.zsh {
|
||||||
clap_complete::Shell::Zsh
|
clap_complete::Shell::Zsh
|
||||||
} else if completion_args.fish {
|
} else if args.fish {
|
||||||
clap_complete::Shell::Fish
|
clap_complete::Shell::Fish
|
||||||
} else {
|
} else {
|
||||||
clap_complete::Shell::Bash
|
clap_complete::Shell::Bash
|
||||||
};
|
};
|
||||||
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)?;
|
||||||
}
|
Ok(())
|
||||||
UtilCommand::Mangen(_mangen_args) => {
|
}
|
||||||
|
|
||||||
|
fn cmd_util_mangen(
|
||||||
|
ui: &mut Ui,
|
||||||
|
command: &CommandHelper,
|
||||||
|
_args: &UtilMangenArgs,
|
||||||
|
) -> Result<(), CommandError> {
|
||||||
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)?;
|
||||||
}
|
Ok(())
|
||||||
UtilCommand::ConfigSchema(_config_schema_args) => {
|
}
|
||||||
|
|
||||||
|
fn cmd_util_config_schema(
|
||||||
|
ui: &mut Ui,
|
||||||
|
_command: &CommandHelper,
|
||||||
|
_args: &UtilConfigSchemaArgs,
|
||||||
|
) -> Result<(), CommandError> {
|
||||||
// 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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue