From 5abee664b2b9e86f23ac795410e168a1a10f6aa0 Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Thu, 19 Mar 2015 00:42:06 +0100 Subject: [PATCH 1/3] Deduplicate docs --- Makefile | 20 ++++++++++++ src/lib.rs | 95 +----------------------------------------------------- 2 files changed, 21 insertions(+), 94 deletions(-) create mode 100644 Makefile diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..001af134 --- /dev/null +++ b/Makefile @@ -0,0 +1,20 @@ +THIS_MAKEFILE_PATH:=$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)) +THIS_DIR:=$(shell cd $(dir $(THIS_MAKEFILE_PATH));pwd) + +test: + cargo test + +build: + cargo build + +doc: + cd "$(THIS_DIR)" + cp src/lib.rs code.bak + cat README.md | sed -e 's/^/\/\/! /g' > readme.bak + sed -i '/\/\/ DOCS/r readme.bak' src/lib.rs + (cargo doc --no-deps && make clean) || (make clean && false) + +clean: + cd "$(THIS_DIR)" + mv code.bak src/lib.rs || true + rm *.bak || true diff --git a/src/lib.rs b/src/lib.rs index a9224151..d701eaba 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,100 +2,7 @@ #![feature(libc, exit_status)] -//! A simply library for parsing command line arguments when writing -//! command line and console applications. -//! -//! -//! You can use `clap` to lay out a list of possible valid command line arguments and let `clap` parse the string given by the user at runtime. -//! When using `clap` you define a set of parameters and rules for your arguments and at runtime `clap` will determine their validity. -//! Also, `clap` provides the traditional version and help switches 'for free' by parsing the list of possible valid arguments lazily at runtime. -//! i.e. only when it's been determined that the user wants or needs to see the help and version information. -//! -//! After defining a list of possible valid arguments you get a list of matches that the user supplied at runtime. You can then use this list to -//! determine the functioning of your program. -//! -//! Example: -//! -//! ```no_run -//! use clap::{Arg, App, SubCommand}; -//! -//! // ... -//! -//! let matches = App::new("MyApp") -//! .version("1.0") -//! .author("Kevin K. ") -//! .about("Does awesome things") -//! .arg(Arg::new("config") -//! .short("c") -//! .long("config") -//! .help("Sets a custom config file") -//! .takes_value(true)) -//! .arg(Arg::new("output") -//! .help("Sets an optional output file") -//! .index(1)) -//! .arg(Arg::new("debug") -//! .short("d") -//! .multiple(true) -//! .help("Turn debugging information on")) -//! .subcommand(SubCommand::new("test") -//! .about("Has test sub functionality") -//! .arg(Arg::new("verbose") -//! .short("v") -//! .help("Display verbose information"))) -//! .get_matches(); -//! -//! if let Some(o) = matches.value_of("output") { -//! println!("Value for output: {}", o); -//! } -//! -//! if let Some(c) = matches.value_of("config") { -//! println!("Value for config: {}", c); -//! } -//! -//! match matches.occurrences_of("debug") { -//! 0 => println!("Debug mode is off"), -//! 1 => println!("Debug mode is kind of on"), -//! 2 => println!("Debug mode is on"), -//! 3 | _ => println!("Don't be crazy"), -//! } -//! -//! if let Some(ref matches) = matches.subcommand_matches("test") { -//! if matches.is_present("verbose") { -//! println!("Printing verbose test info..."); -//! } else { -//! println!("Not printing regular test info..."); -//! } -//! } -//! -//! // more porgram logic goes here... -//! ``` -//! -//! If you were to compile the above program and run it with the flag `--help` or `-h` the following output woud be presented -//! -//! ```sh -//! $ myprog --help -//! MyApp 1.0 -//! Kevin K. -//! Does awesome things -//! -//! USAGE: -//! MyApp [FLAGS] [OPTIONS] [POSITIONAL] [SUBCOMMANDS] -//! -//! FLAGS: -//! -d Turn debugging information on -//! -h,--help Prints this message -//! -v,--version Prints version information -//! -//! OPTIONS: -//! -c,--config Sets a custom config file -//! -//! POSITIONAL ARGUMENTS: -//! output Sets an optional output file -//! -//! SUBCOMMANDS: -//! help Prints this message -//! test Has test sub-functionality -//! ``` +// DOCS pub use args::{Arg, SubCommand, ArgMatches}; pub use app::App; From 40175241579b40b0c4ba6352dbfa85e8f36b21fd Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Thu, 19 Mar 2015 00:43:33 +0100 Subject: [PATCH 2/3] This breaks for rustdoc --- README.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 7c925e82..53d22c20 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ -# clap ![Travis-CI](https://travis-ci.org/kbknapp/clap-rs.svg?branch=master) +# clap + +![Travis-CI](https://travis-ci.org/kbknapp/clap-rs.svg?branch=master) + Command Line Argument Parser written in Rust A simply library for parsing command line arguments and subcommands when writing command line and console applications. From 7ca46bc708a8cfcbd9f3eb8c5221eccb4d621442 Mon Sep 17 00:00:00 2001 From: Markus Unterwaditzer Date: Thu, 19 Mar 2015 00:45:30 +0100 Subject: [PATCH 3/3] Add build instructions --- README.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/README.md b/README.md index 53d22c20..de82278a 100644 --- a/README.md +++ b/README.md @@ -122,3 +122,19 @@ Add `extern crate clap;` to your crate root. ## More Information You can find complete documentation on the [github-pages site](http://kbknapp.github.io/clap-rs/docs/clap/index.html) for this project. + +## How to build + +### Running the tests + +``` +cargo test +``` + +### Building the documentation + +Run this instead of `cargo doc` to generate the proper module docstring: + +``` +make doc +```