Skip to content

Commit

Permalink
Introduce more helpful CLI using clap-rs.
Browse files Browse the repository at this point in the history
  • Loading branch information
frewsxcv committed Nov 20, 2017
1 parent 462f615 commit c9537ea
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@ rustc_version = "0.2"

[dependencies]
cc = "1.0"
clap = "2.27"
rustc_version = "0.2"
xdg = "2.1"
99 changes: 99 additions & 0 deletions src/bin/cargo-afl.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#[macro_use]
extern crate clap;
extern crate rustc_version;
extern crate xdg;

Expand All @@ -9,6 +11,8 @@ use std::process::{self, Command};
mod dirs;

fn main() {
let _ = clap_app().get_matches();

let mut args = env::args().skip(2).peekable(); // skip `cargo` and `afl`
match args.peek().map(|s| &**s) {
Some("analyze") => run_afl(args, "afl-analyze"),
Expand All @@ -23,6 +27,101 @@ fn main() {
}
}

fn clap_app() -> clap::App<'static, 'static> {
clap::App::new("cargo afl").bin_name("cargo").subcommand(
clap::SubCommand::with_name("afl")
.version(crate_version!())
.setting(clap::AppSettings::ArgRequiredElseHelp)
.setting(clap::AppSettings::TrailingVarArg)
.setting(clap::AppSettings::AllowExternalSubcommands)
.usage("cargo afl [SUBCOMMAND or Cargo SUBCOMMAND]")
.after_help(
"In addition to the subcommands above, Cargo subcommands are also \
supported (see `cargo help` for a list of all Cargo subcommands).",
)
.subcommand(
clap::SubCommand::with_name("analyze")
.about("Invoke afl-analyze")
.setting(clap::AppSettings::AllowLeadingHyphen)
.setting(clap::AppSettings::DisableHelpSubcommand)
.setting(clap::AppSettings::DisableVersion)
.arg(clap::Arg::with_name("h").short("h").hidden(true))
.arg(clap::Arg::with_name("help").long("help").help("known bug! rewrite as '-- --help' to see AFL help"))
.arg(clap::Arg::with_name("afl-analyze args").multiple(true)),
)
.subcommand(
clap::SubCommand::with_name("cmin")
.about("Invoke afl-cmin")
.setting(clap::AppSettings::AllowLeadingHyphen)
.setting(clap::AppSettings::DisableHelpSubcommand)
.setting(clap::AppSettings::DisableVersion)
.arg(clap::Arg::with_name("h").short("h").hidden(true))
.arg(clap::Arg::with_name("help").long("help").help("known bug! rewrite as '-- --help' to see AFL help"))
.arg(clap::Arg::with_name("afl-cmin args").multiple(true)),
)
.subcommand(
clap::SubCommand::with_name("fuzz")
.about("Invoke afl-fuzz")
.setting(clap::AppSettings::AllowLeadingHyphen)
.setting(clap::AppSettings::DisableHelpSubcommand)
.setting(clap::AppSettings::DisableVersion)
.arg(clap::Arg::with_name("h").short("h").hidden(true))
.arg(clap::Arg::with_name("help").long("help").help("known bug! rewrite as '-- --help' to see AFL help"))
.arg(clap::Arg::with_name("afl-fuzz args").multiple(true)),
)
.subcommand(
clap::SubCommand::with_name("gotcpu")
.about("Invoke afl-gotcpu")
.setting(clap::AppSettings::AllowLeadingHyphen)
.setting(clap::AppSettings::DisableHelpSubcommand)
.setting(clap::AppSettings::DisableVersion)
.arg(clap::Arg::with_name("h").short("h").hidden(true))
.arg(clap::Arg::with_name("help").long("help").help("known bug! rewrite as '-- --help' to see AFL help"))
.arg(clap::Arg::with_name("afl-gotcpu args").multiple(true)),
)
.subcommand(
clap::SubCommand::with_name("plot")
.about("Invoke afl-plot")
.setting(clap::AppSettings::AllowLeadingHyphen)
.setting(clap::AppSettings::DisableHelpSubcommand)
.setting(clap::AppSettings::DisableVersion)
.arg(clap::Arg::with_name("h").short("h").hidden(true))
.arg(clap::Arg::with_name("help").long("help").help("known bug! rewrite as '-- --help' to see AFL help"))
.arg(clap::Arg::with_name("afl-plot args").multiple(true)),
)
.subcommand(
clap::SubCommand::with_name("showmap")
.about("Invoke afl-showmap")
.setting(clap::AppSettings::AllowLeadingHyphen)
.setting(clap::AppSettings::DisableHelpSubcommand)
.setting(clap::AppSettings::DisableVersion)
.arg(clap::Arg::with_name("h").short("h").hidden(true))
.arg(clap::Arg::with_name("help").long("help").help("known bug! rewrite as '-- --help' to see AFL help"))
.arg(clap::Arg::with_name("afl-showmap args").multiple(true)),
)
.subcommand(
clap::SubCommand::with_name("tmin")
.about("Invoke afl-tmin")
.setting(clap::AppSettings::AllowLeadingHyphen)
.setting(clap::AppSettings::DisableHelpSubcommand)
.setting(clap::AppSettings::DisableVersion)
.arg(clap::Arg::with_name("h").short("h").hidden(true))
.arg(clap::Arg::with_name("help").long("help").help("known bug! rewrite as '-- --help' to see AFL help"))
.arg(clap::Arg::with_name("afl-tmin args").multiple(true)),
)
.subcommand(
clap::SubCommand::with_name("whatsup")
.about("Invoke afl-whatsup")
.setting(clap::AppSettings::AllowLeadingHyphen)
.setting(clap::AppSettings::DisableHelpSubcommand)
.setting(clap::AppSettings::DisableVersion)
.arg(clap::Arg::with_name("h").short("h").hidden(true))
.arg(clap::Arg::with_name("help").long("help").help("known bug! rewrite as '-- --help' to see AFL help"))
.arg(clap::Arg::with_name("afl-whatsup args").multiple(true)),
),
)
}

fn run_afl<I, S>(args: I, cmd: &str)
where
I: IntoIterator<Item = S>,
Expand Down

0 comments on commit c9537ea

Please sign in to comment.