mirror of
https://github.com/sharkdp/hexyl.git
synced 2026-10-28 08:05:52 +00:00
Add shell completion (#251)
* add commandline argument to generate shell completion * update changelog * fixup! add commandline argument to generate shell completion * Update option name and description --------- Co-authored-by: David Peter <mail@david-peter.de>
This commit is contained in:
1 parent
909dd7d947
commit
585d06293a
4 files changed
+25
-1
No files matched your search
@@ -1,6 +1,7 @@
|
|||||||
# unreleased
|
# unreleased
|
||||||
|
|
||||||
- Fix memory allocation bug when terminal width is less than 10, see #244 (@selfup)
|
- Fix memory allocation bug when terminal width is less than 10, see #244 (@selfup)
|
||||||
|
- Add command line argument to generate shell completion, see #155 (@friedz)
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
|
|||||||
Generated
+10
@@ -128,6 +128,15 @@ dependencies = [
|
|||||||
"terminal_size",
|
"terminal_size",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap_complete"
|
||||||
|
version = "4.5.55"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a5abde44486daf70c5be8b8f8f1b66c49f86236edf6fa2abadb4d961c4c6229a"
|
||||||
|
dependencies = [
|
||||||
|
"clap",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clap_derive"
|
name = "clap_derive"
|
||||||
version = "4.5.18"
|
version = "4.5.18"
|
||||||
@@ -222,6 +231,7 @@ dependencies = [
|
|||||||
"anyhow",
|
"anyhow",
|
||||||
"assert_cmd",
|
"assert_cmd",
|
||||||
"clap",
|
"clap",
|
||||||
|
"clap_complete",
|
||||||
"const_format",
|
"const_format",
|
||||||
"libc",
|
"libc",
|
||||||
"owo-colors",
|
"owo-colors",
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ owo-colors = "4"
|
|||||||
supports-color = "3"
|
supports-color = "3"
|
||||||
thiserror = "1.0"
|
thiserror = "1.0"
|
||||||
terminal_size = "0.4"
|
terminal_size = "0.4"
|
||||||
|
clap_complete = "4"
|
||||||
|
|
||||||
[dependencies.clap]
|
[dependencies.clap]
|
||||||
version = "4"
|
version = "4"
|
||||||
|
|||||||
+13
-1
@@ -4,7 +4,8 @@ use std::num::{NonZeroI64, NonZeroU64};
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use clap::builder::ArgPredicate;
|
use clap::builder::ArgPredicate;
|
||||||
use clap::{ArgAction, Parser, ValueEnum};
|
use clap::{ArgAction, CommandFactory, Parser, ValueEnum};
|
||||||
|
use clap_complete::aot::{generate, Shell};
|
||||||
|
|
||||||
use anyhow::{anyhow, bail, Context, Result};
|
use anyhow::{anyhow, bail, Context, Result};
|
||||||
|
|
||||||
@@ -192,6 +193,10 @@ struct Opt {
|
|||||||
/// Print a table showing how different types of bytes are colored.
|
/// Print a table showing how different types of bytes are colored.
|
||||||
#[arg(long)]
|
#[arg(long)]
|
||||||
print_color_table: bool,
|
print_color_table: bool,
|
||||||
|
|
||||||
|
/// Show shell completion for a certain shell
|
||||||
|
#[arg(long, value_name("SHELL"))]
|
||||||
|
completion: Option<Shell>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, ValueEnum)]
|
#[derive(Clone, Debug, Default, ValueEnum)]
|
||||||
@@ -248,6 +253,13 @@ fn run() -> Result<()> {
|
|||||||
return print_color_table().map_err(|e| anyhow!(e));
|
return print_color_table().map_err(|e| anyhow!(e));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(sh) = opt.completion {
|
||||||
|
let mut cmd = Opt::command();
|
||||||
|
let name = cmd.get_name().to_string();
|
||||||
|
generate(sh, &mut cmd, name, &mut io::stdout());
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
let stdin = io::stdin();
|
let stdin = io::stdin();
|
||||||
|
|
||||||
let mut reader = match opt.file {
|
let mut reader = match opt.file {
|
||||||
|
|||||||
Reference in new issue
Block a user