mirror of
https://github.com/containers/youki
synced 2024-06-10 08:46:21 +02:00
Add shell completion (#515)
This commit is contained in:
parent
2d67f68c7e
commit
2eef38dfc7
|
@ -126,6 +126,15 @@ dependencies = [
|
|||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "clap_generate"
|
||||
version = "3.0.0-beta.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "097ab5db1c3417442270cd57c8dd39f6c3114d3ce09d595f9efddbb1fcfaa799"
|
||||
dependencies = [
|
||||
"clap",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "combine"
|
||||
version = "2.5.2"
|
||||
|
@ -1333,6 +1342,7 @@ dependencies = [
|
|||
"anyhow",
|
||||
"chrono",
|
||||
"clap",
|
||||
"clap_generate",
|
||||
"libcgroups",
|
||||
"libcontainer",
|
||||
"liboci-cli",
|
||||
|
|
|
@ -26,6 +26,7 @@ procfs = "0.11.1"
|
|||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
tabwriter = "1"
|
||||
clap_generate = { version = "3.0.0-beta.5" }
|
||||
|
||||
[dev-dependencies]
|
||||
serial_test = "0.5.1"
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
use anyhow::Result;
|
||||
use clap::{App, Parser};
|
||||
use clap_generate::{generate, Shell};
|
||||
use std::io;
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
/// Generate scripts for shell completion
|
||||
pub struct Completion {
|
||||
#[clap(long = "shell", short = 's', arg_enum)]
|
||||
pub shell: Shell,
|
||||
}
|
||||
|
||||
pub fn completion(args: Completion, app: &mut App) -> Result<()> {
|
||||
generate(
|
||||
args.shell,
|
||||
app,
|
||||
app.get_name().to_string(),
|
||||
&mut io::stdout(),
|
||||
);
|
||||
|
||||
Ok(())
|
||||
}
|
|
@ -3,6 +3,7 @@ use std::{fs, path::Path};
|
|||
|
||||
use libcontainer::container::Container;
|
||||
|
||||
pub mod completion;
|
||||
pub mod create;
|
||||
pub mod delete;
|
||||
pub mod events;
|
||||
|
|
|
@ -4,13 +4,13 @@
|
|||
mod commands;
|
||||
mod logger;
|
||||
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use anyhow::bail;
|
||||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use clap::IntoApp;
|
||||
use clap::{crate_version, Parser};
|
||||
use std::fs;
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use crate::commands::info;
|
||||
use libcontainer::rootless::rootless_required;
|
||||
|
@ -46,6 +46,7 @@ enum SubCommand {
|
|||
|
||||
// Youki specific extensions
|
||||
Info(info::Info),
|
||||
Completion(commands::completion::Completion),
|
||||
}
|
||||
|
||||
/// This is the entry point in the container runtime. The binary is run by a high-level container runtime,
|
||||
|
@ -64,6 +65,7 @@ fn main() -> Result<()> {
|
|||
pentacle::ensure_sealed().context("failed to seal /proc/self/exe")?;
|
||||
|
||||
let opts = Opts::parse();
|
||||
let mut app = Opts::into_app();
|
||||
|
||||
if let Err(e) = crate::logger::init(opts.global.debug, opts.global.log, opts.global.log_format)
|
||||
{
|
||||
|
@ -100,6 +102,9 @@ fn main() -> Result<()> {
|
|||
},
|
||||
|
||||
SubCommand::Info(info) => commands::info::info(info),
|
||||
SubCommand::Completion(completion) => {
|
||||
commands::completion::completion(completion, &mut app)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue