[][src]Attribute Macro overrider::override_flag

#[override_flag]

Override a base implimentation, but only when runtime is called with certain flags

Attaching this attribute to a fn or impl block enables it to be overriden at runtime depending on what flags are passed to the executable. Flags require lazy_static and clap to work properly. The expected format is as follows:

lazy_static! {
    static ref CLAP_FLAGS: ArgMatches<'static> = {
	App::new("Overrider example - flag")
            .arg(Arg::with_name("change").long("change"))
            .get_matches()
    };
}

overrider expects this format. CLAP_FLAGS must be a clap::ArgMatches object, and it must be done through lazy_static. This object must be referenced consistantly, so if work is spread across multiple files, the single CLAP_FLAGS instant must be imported. overrider expects CLAP_FLAGS in the local namespace. It's a bit annoying, but it offers unparalleled performance and ease of use after the setup stage.

Syntax

After the CLAP_FLAGS definition mentioned above, the #[override_flag] attribute can be attached to an item. A #[default] implimentation is required. This is so the item is not left undefined if no flags are passed.

override_flag takes two arguements:

  • flag
  • priority
    Priority allows for overriding a previous flag definition. The full syntax is as follows:
    #[override_flag(flag = FLAGNAME, priority = n)], where FLAGNAME is a UTF8 string containing no spaces, and n is a positive integer.