Commit 4a48f39c authored by Nawasan Wisitsingkhon's avatar Nawasan Wisitsingkhon

add generate auto complete for shell

parent 966347a0
......@@ -59,9 +59,9 @@ checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b"
[[package]]
name = "clap"
version = "4.5.13"
version = "4.5.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fbb260a053428790f3de475e304ff84cdbc4face759ea7a3e64c1edd938a7fc"
checksum = "ed6719fffa43d0d87e5fd8caeab59be1554fb028cd30edc88fc4369b17971019"
dependencies = [
"clap_builder",
"clap_derive",
......@@ -69,9 +69,9 @@ dependencies = [
[[package]]
name = "clap_builder"
version = "4.5.13"
version = "4.5.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "64b17d7ea74e9f833c7dbf2cbe4fb12ff26783eda4782a8975b72f895c9b4d99"
checksum = "216aec2b177652e3846684cbfe25c9964d18ec45234f0f5da5157b207ed1aab6"
dependencies = [
"anstream",
"anstyle",
......@@ -79,6 +79,15 @@ dependencies = [
"strsim",
]
[[package]]
name = "clap_complete"
version = "4.5.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "531d7959c5bbb6e266cecdd0f20213639c3a5c3e4d615f97db87661745f781ff"
dependencies = [
"clap",
]
[[package]]
name = "clap_derive"
version = "4.5.13"
......@@ -156,6 +165,7 @@ version = "0.3.2"
dependencies = [
"byteorder",
"clap",
"clap_complete",
]
[[package]]
......
......@@ -23,6 +23,7 @@ path = "src/main.rs"
[dependencies]
byteorder = "1.0.0"
clap = { version = "4.5.13", features = ["derive"] }
clap_complete = "4.5.23"
[profile.release]
strip = true
......@@ -2,8 +2,9 @@ use crate::{
example::{Controller10, Controller13},
openflow::{ofp10::ControllerFrame10, ofp13::ControllerFrame13},
};
use clap::{command, Parser, Subcommand};
use std::thread;
use clap::{command, CommandFactory, Parser, Subcommand};
use clap_complete::{generate, Shell};
use std::{io, thread};
#[derive(Parser)]
#[command(name = "tenjin",author, version, about, long_about = None)]
......@@ -13,7 +14,7 @@ struct Cli {
}
#[derive(Subcommand)]
pub enum Commands {
enum Commands {
/// Run the controller
Run {
#[command(subcommand)]
......@@ -29,6 +30,8 @@ pub enum Commands {
)]
listen: String,
},
/// Generate auto complete for shell
Generate { shell: Shell },
}
#[derive(Subcommand)]
......@@ -69,5 +72,9 @@ pub fn system() {
let _ = th.join();
}
}
Commands::Generate { shell } => {
let mut cli_gen = Cli::command();
generate(shell, &mut cli_gen, "tenjin", &mut io::stdout());
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment