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

add generate auto complete for shell

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