pub trait Generator {
// Required methods
fn file_name(name: &str) -> String;
fn generate(app: &App<'_>, buf: &mut dyn Write);
// Provided methods
fn all_subcommands(app: &App<'_>) -> Vec<(String, String)> { ... }
fn find_subcommand_with_path<'help, 'app>(
p: &'app App<'help>,
path: Vec<&str>,
) -> &'app App<'help> { ... }
fn subcommands(p: &App<'_>) -> Vec<(String, String)> { ... }
fn shorts_and_visible_aliases(p: &App<'_>) -> Vec<char> { ... }
fn longs_and_visible_aliases(p: &App<'_>) -> Vec<String> { ... }
fn flags<'help>(p: &App<'help>) -> Vec<Arg<'help>> { ... }
}
Expand description
Generator trait which can be used to write generators
Required Methods§
Sourcefn file_name(name: &str) -> String
fn file_name(name: &str) -> String
Returns the file name that is created when this generator is called during compile time.
§Examples
use clap_generate::Generator;
pub struct Fish;
impl Generator for Fish {
fn file_name(name: &str) -> String {
format!("{}.fish", name)
}
}
Sourcefn generate(app: &App<'_>, buf: &mut dyn Write)
fn generate(app: &App<'_>, buf: &mut dyn Write)
Generates output out of clap::App
.
§Examples
The following example generator displays the clap::App
as if it is printed using std::println
.
use std::{io::Write, fmt::write};
use clap::App;
use clap_generate::Generator;
pub struct ClapDebug;
impl Generator for ClapDebug {
fn generate(app: &App, buf: &mut dyn Write) {
write!(buf, "{}", app).unwrap();
}
}
Provided Methods§
Sourcefn all_subcommands(app: &App<'_>) -> Vec<(String, String)>
fn all_subcommands(app: &App<'_>) -> Vec<(String, String)>
Gets all subcommands including child subcommands in the form of ("name", "bin_name")
.
Subcommand rustup toolchain install
would be converted to
("install", "rustup toolchain install")
.
Sourcefn find_subcommand_with_path<'help, 'app>(
p: &'app App<'help>,
path: Vec<&str>,
) -> &'app App<'help>
fn find_subcommand_with_path<'help, 'app>( p: &'app App<'help>, path: Vec<&str>, ) -> &'app App<'help>
Sourcefn subcommands(p: &App<'_>) -> Vec<(String, String)>
fn subcommands(p: &App<'_>) -> Vec<(String, String)>
Gets subcommands of clap::App
in the form of ("name", "bin_name")
.
Subcommand rustup toolchain install
would be converted to
("install", "rustup toolchain install")
.
Sourcefn shorts_and_visible_aliases(p: &App<'_>) -> Vec<char>
fn shorts_and_visible_aliases(p: &App<'_>) -> Vec<char>
Gets all the short options, their visible aliases and flags of a clap::App
.
Includes h
and V
depending on the clap::AppSettings
.
Sourcefn longs_and_visible_aliases(p: &App<'_>) -> Vec<String>
fn longs_and_visible_aliases(p: &App<'_>) -> Vec<String>
Gets all the long options, their visible aliases and flags of a clap::App
.
Includes help
and version
depending on the clap::AppSettings
.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.