Skip to content
This repository has been archived by the owner on May 11, 2020. It is now read-only.

Ported all the commits from structopt #23

Merged
merged 63 commits into from
Jan 7, 2020
Merged
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
cd62806
Automatic naming of fields and subcommands (#143)
0ndorio Nov 1, 2018
c7fe201
Introduce smarter parsing of doc comments. (#146)
0ndorio Dec 10, 2018
61d86cd
Fix invalid structopt syntax error message (#154)
roblabla Dec 10, 2018
abddfc2
Fix spelling: occurences -> occurrences, (#158)
florianjacob Dec 22, 2018
4688779
Remove line-ending periods from short help. (#161)
TedDriggs Jan 11, 2019
c339423
Fix #168
TeXitoi Mar 8, 2019
828df27
Support Option<Option<T>> field types (#190)
sphynx May 29, 2019
78fe217
Support Option<Vec<T>> field type (#191)
sphynx May 30, 2019
a5f6e6d
Update deprecated function and provide more info about the parsing er…
sphynx Jun 1, 2019
151de7d
Improve ChangeLog as suggested by @ErichDonGubler (#194)
sphynx Jun 1, 2019
b3dc31e
Fix use of deprecated function
owenthewizard Apr 24, 2019
4a32c23
Fix some clippy lints
owenthewizard Apr 24, 2019
d1ae347
[Casing] Change default from verbatim to kebab. (#204)
0ndorio Jun 19, 2019
bc93686
Use trybuild for testing expected proc macro errors (#205)
sphynx Jun 19, 2019
77150a0
Custom attributes parser (#198)
sphynx Jun 24, 2019
5efe630
update README.md for 0.3
TeXitoi Jun 30, 2019
b30b0b3
Small fixes: clippy and typos (#215)
sphynx Jul 4, 2019
325eba6
Add example for environment variables (#160) (#216)
robinst Jul 4, 2019
b684266
Support skipping struct fields (#213)
sphynx Jul 4, 2019
83e0a25
Now error messages highlight the error location (#225)
CreepySkeleton Aug 13, 2019
704fd97
Minor fixes
pksunkara Dec 15, 2019
ac18c4d
Change behavior of `about/author/version` and ad `no_version`
CreepySkeleton Aug 23, 2019
9bb21fd
Emit error about `raw` removal
CreepySkeleton Aug 23, 2019
8c6ac97
Update changelog
CreepySkeleton Aug 23, 2019
6ae22ed
Update keyvalue example (#234)
lovasoa Aug 26, 2019
0ee05bf
Update documentation and changelog (#236)
CreepySkeleton Aug 30, 2019
e971d60
Update dependencies (#227)
CreepySkeleton Aug 30, 2019
4fd38d9
Fix issues
pksunkara Dec 15, 2019
396954c
Bump minimum rustc version to 1.36
Aug 30, 2019
5f4aa28
Fix structopt-derive permissions (#239)
kpcyrd Aug 30, 2019
2609ddf
Fix #245 (#246)
CreepySkeleton Sep 1, 2019
8e6a91d
Emit dummy impls on error (#248)
CreepySkeleton Sep 2, 2019
be15e0f
Fix changelog example (#250)
CreepySkeleton Sep 3, 2019
84121bb
Do not call .verison() when CARGO_PKG_VERSION is not set
CreepySkeleton Sep 5, 2019
bff57ed
Update and improve docs
CreepySkeleton Sep 5, 2019
1a99766
Fix nightly tests
CreepySkeleton Sep 17, 2019
b49452d
Propagate span info from origin code to generated code
CreepySkeleton Sep 9, 2019
a07ef9d
Do not mangle `author` string inside `<...>`
CreepySkeleton Sep 9, 2019
549cc70
Support `skip = value` syntax
CreepySkeleton Sep 17, 2019
ae9793c
Fix code formatting
luizdepra Oct 5, 2019
9c4abc2
Fix nightly tests
CreepySkeleton Sep 21, 2019
25a0e83
Run ui tests only on stable
CreepySkeleton Oct 9, 2019
3fbcf46
Add from_flag parser (#271)
rokob Oct 10, 2019
e2c639b
Clarify docs and error messages (#277)
CreepySkeleton Nov 3, 2019
fc67e1e
Fix parse for OptionVec (#279)
xiaoniu-578fa6bff964d005 Nov 8, 2019
b80f355
Fix #269 and #265 (#278)
CreepySkeleton Nov 8, 2019
c5e1f53
Pass the try_from_str functions a &str instead of a &String. (#282)
m-ou-se Nov 22, 2019
ff8e80c
Fix #283 (#284)
CreepySkeleton Nov 26, 2019
911161a
Add an example of a negative flag (i.e. --no-verbose)
TeXitoi Nov 20, 2019
68e1702
Add `examples/README.md` and do some cleanup
CreepySkeleton Nov 27, 2019
26e7865
Handle special types correctly
CreepySkeleton Nov 28, 2019
11cb2f7
cargo clippy
CreepySkeleton Dec 2, 2019
c4774ec
Handle inter-expansion top-level args properly
CreepySkeleton Dec 2, 2019
93d3451
Cleanup tests
CreepySkeleton Nov 29, 2019
91e1187
Update proc-macro-error to v0.4
CreepySkeleton Dec 3, 2019
30090a4
Offer helpful suggestion on `raw(...)` error
CreepySkeleton Dec 4, 2019
1e2f374
Add `after_help` example
CreepySkeleton Dec 5, 2019
ce1d678
Prohibit positional `bool` args
CreepySkeleton Dec 5, 2019
0371a27
Add tests/utils.rs
CreepySkeleton Dec 5, 2019
e8435b2
fixed typo, removed misleading doc
renecouto Dec 12, 2019
2555529
Remove CHANGELOG additions
pksunkara Dec 18, 2019
8821202
Rust 2018
pksunkara Dec 18, 2019
510d10f
Addressed review
pksunkara Dec 29, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "clap_derive"
version = "0.3.0"
edition = "2018"
authors = [
"Guillaume Pinot <texitoi@texitoi.eu>",
"Kevin K. <kbknapp@gmail.com>",
pksunkara marked this conversation as resolved.
Show resolved Hide resolved
@@ -22,17 +23,20 @@ travis-ci = { repository = "clap-rs/clap_derive" }
appveyor = { repository = "https://github.com/clap-rs/clap_derive", service = "github" }

[dependencies]
syn = "0.15.39"
quote = "0.6"
proc-macro2 = "0.4"
clippy = {version = "0.0.174", optional = true }
syn = { version = "1", features = ["full"] }
quote = "1"
proc-macro2 = "1"
heck = "0.3.0"
proc-macro-error = "0.4.3"

[dev-dependencies]
clap = { git = "https://github.com/clap-rs/clap", branch = "master"} # ONLY FOR INITIAL DEVELOPMENT...change to real crates.io ver for rlease!
trybuild = "1.0.5"
rustversion = "0.1"

[features]
default = []
nightly = []
lints = ["clippy"]
lints = []
debug = []
doc = []
68 changes: 49 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -34,30 +34,33 @@ use clap::Clap;
#[clap(name = "basic")]
struct Opt {
// A flag, true if used in the command line. Note doc comment will
// be used for the help message of the flag.
// be used for the help message of the flag. The name of the
// argument will be, by default, based on the name of the field.
/// Activate debug mode
#[clap(short = "d", long = "debug")]
#[clap(short, long)]
debug: bool,

// The number of occurences of the `v/verbose` flag
// The number of occurrences of the `v/verbose` flag
/// Verbose mode (-v, -vv, -vvv, etc.)
#[clap(short = "v", long = "verbose", parse(from_occurrences))]
#[clap(short, long, parse(from_occurrences))]
verbose: u8,

/// Set speed
#[clap(short = "s", long = "speed", default_value = "42")]
#[clap(short, long, default_value = "42")]
speed: f64,

/// Output file
#[clap(short = "o", long = "output", parse(from_os_str))]
#[clap(short, long, parse(from_os_str))]
output: PathBuf,

// the long option will be translated by default to kebab case,
// i.e. `--nb-cars`.
/// Number of cars
#[clap(short = "c", long = "nb-cars")]
#[clap(short = "c", long)]
nb_cars: Option<i32>,

/// admin_level to consider
#[clap(short = "l", long = "level")]
#[clap(short, long)]
level: Vec<String>,

/// Files to process
@@ -67,7 +70,7 @@ struct Opt {

fn main() {
let opt = Opt::parse();
println!("{:?}", opt);
println!("{:#?}", opt);
}
```

@@ -82,12 +85,12 @@ USAGE:

For more information try --help
$ ./basic --help
basic 0.2.0
Guillaume Pinot <texitoi@texitoi.eu>
basic 0.3.0
Guillaume Pinot <texitoi@texitoi.eu>, others
pksunkara marked this conversation as resolved.
Show resolved Hide resolved
A basic example

USAGE:
basic [FLAGS] [OPTIONS] --output <output> [--] [FILE]...
basic [FLAGS] [OPTIONS] --output <output> [--] [file]...

ARGS:
<FILE>... Files to process
@@ -96,17 +99,44 @@ FLAGS:
-d, --debug Activate debug mode
-h, --help Prints help information
-V, --version Prints version information
-v, --verbose Verbose mode
-v, --verbose Verbose mode (-v, -vv, -vvv, etc.)

OPTIONS:
-c, --nb-cars <nb_cars> Number of cars
-l, --level <level>... admin_level to consider
-o, --output <output> Output file
-s, --speed <speed> Set speed [default: 42]
-l, --level <level>... admin_level to consider
-c, --nb-cars <nb-cars> Number of cars
-o, --output <output> Output file
-s, --speed <speed> Set speed [default: 42]

ARGS:
<file>... Files to process
$ ./basic -o foo.txt
Opt { debug: false, verbose: 0, speed: 42, output: "foo.txt", car: None, level: [], files: [] }
Opt {
debug: false,
verbose: 0,
speed: 42.0,
output: "foo.txt",
nb_cars: None,
level: [],
files: [],
}
$ ./basic -o foo.txt -dvvvs 1337 -l alice -l bob --nb-cars 4 bar.txt baz.txt
Opt { debug: true, verbose: 3, speed: 1337, output: "foo.txt", nb_cars: Some(4), level: ["alice", "bob"], files: ["bar.txt", "baz.txt"] }
Opt {
debug: true,
verbose: 3,
speed: 1337.0,
output: "foo.txt",
nb_cars: Some(
4,
),
level: [
"alice",
"bob",
],
files: [
"bar.txt",
"baz.txt",
],
}
```

## clap_derive rustc version policy
78 changes: 78 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Collection of examples "how to use `clap_derive`"

### [Help on the bottom](after_help.rs)

How to append a postscript to the help message generated.

### [At least N](at_least_two.rs)

How to require presence of at least N values, like `val1 val2 ... valN ... valM`.

### [Basic](basic.rs)

A basic example how to use `clap_derive`.

### [Deny missing docs](deny_missing_docs.rs)

**This is not an example but a test**, it should be moved to `tests` folder
as soon as [this](https://github.com/rust-lang/rust/issues/24584) is fixed (if ever).

### [Doc comments](doc_comments.rs)

How to use doc comments in place of `help/long_help`.

### [Enums as arguments](enum_in_args.rs)

How to use `arg_enum!` with `clap_derive`.
pksunkara marked this conversation as resolved.
Show resolved Hide resolved

### [Arguments of subcommands in separate `struct`](enum_tuple.rs)

How to extract subcommands' args into external structs.

### [Environment variables](env.rs)

How to use environment variable fallback an how it interacts with `default_value`.

### [Advanced](example.rs)

Somewhat complex example of usage of `clap_derive`.

### [Flatten](flatten.rs)

How to use `#[clap(flatten)]`

### [Git](git.rs)

Pseudo-`git` example, shows how to use subcommands and how to document them.

### [Groups](group.rs)

Using `clap::Arg::group` with `clap`.

### [`key=value` pairs](keyvalue.rs)

How to parse `key=value` pairs.

### [`--no-*` flags](negative_flag.rs)

How to add `no-thing` flag which is `true` by default and `false` if passed.

### [No version](no_version.rs)

How to completely remove version.

### [Rename all](rename_all.rs)

How `#[clap(rename_all)]` works.

### [Skip](skip.rs)

How to use `#[clap(skip)]`.

### [Aliases](subcommand_aliases.rs)

How to use aliases

### [`true` or `false`](true_or_false.rs)

How to express "`"true"` or `"false"` argument.
19 changes: 19 additions & 0 deletions examples/after_help.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//! How to append a postscript to the help message generated.

use clap::Clap;

/// I am a program and I do things.
///
/// Sometimes they even work.
#[derive(Clap, Debug)]
#[clap(after_help = "Beware `-d`, dragons be here")]
struct Opt {
/// Release the dragon.
#[clap(short)]
dragon: bool,
}

fn main() {
let opt = Opt::parse();
println!("{:?}", opt);
}
6 changes: 3 additions & 3 deletions examples/at_least_two.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#[macro_use]
extern crate clap;
//! How to require presence of at least N values,
//! like `val1 val2 ... valN ... valM`.

use clap::Clap;

#[derive(Clap, Debug)]
struct Opt {
#[clap(raw(required = "true", min_values = "2"))]
#[clap(required = true, min_values = 2)]
foos: Vec<String>,
}

38 changes: 13 additions & 25 deletions examples/basic.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
// Copyright 2018 Guillaume Pinot (@TeXitoi) <texitoi@texitoi.eu>,
// Kevin Knapp (@kbknapp) <kbknapp@gmail.com>, and
// Andrew Hobden (@hoverbear) <andrew@hoverbear.org>
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
//
// This work was derived from Structopt (https://github.com/TeXitoi/structopt)
// commit#ea76fa1b1b273e65e3b0b1046643715b49bec51f which is licensed under the
// MIT/Apache 2.0 license.

#[macro_use]
extern crate clap;
//! A somewhat comprehensive example of a typical `StructOpt` usage.use

use clap::Clap;
use std::path::PathBuf;
@@ -23,30 +8,33 @@ use std::path::PathBuf;
#[clap(name = "basic")]
struct Opt {
// A flag, true if used in the command line. Note doc comment will
// be used for the help message of the flag.
// be used for the help message of the flag. The name of the
// argument will be, by default, based on the name of the field.
/// Activate debug mode
#[clap(short = "d", long = "debug")]
#[clap(short, long)]
debug: bool,

// The number of occurences of the `v/verbose` flag
// The number of occurrences of the `v/verbose` flag
/// Verbose mode (-v, -vv, -vvv, etc.)
#[clap(short = "v", long = "verbose", parse(from_occurrences))]
#[clap(short, long, parse(from_occurrences))]
verbose: u8,

/// Set speed
#[clap(short = "s", long = "speed", default_value = "42")]
#[clap(short, long, default_value = "42")]
speed: f64,

/// Output file
#[clap(short = "o", long = "output", parse(from_os_str))]
#[clap(short, long, parse(from_os_str))]
output: PathBuf,

// the long option will be translated by default to kebab case,
// i.e. `--nb-cars`.
/// Number of cars
#[clap(short = "c", long = "nb-cars")]
#[clap(short = "c", long)]
nb_cars: Option<i32>,

/// admin_level to consider
#[clap(short = "l", long = "level")]
#[clap(short, long)]
level: Vec<String>,

/// Files to process
@@ -56,5 +44,5 @@ struct Opt {

fn main() {
let opt = Opt::parse();
println!("{:?}", opt);
println!("{:#?}", opt);
}
9 changes: 3 additions & 6 deletions examples/deny_missing_docs.rs
Original file line number Diff line number Diff line change
@@ -16,15 +16,12 @@

#![deny(missing_docs)]

#[macro_use]
extern crate clap;

use clap::Clap;

/// The options
#[derive(Clap, Debug, PartialEq)]
pub struct Opt {
#[clap(short = "v")]
#[clap(short)]
verbose: bool,
#[clap(subcommand)]
cmd: Option<Cmd>,
@@ -38,7 +35,7 @@ pub enum Cmd {
/// command B
B {
/// Alice?
#[clap(short = "a")]
#[clap(short)]
alice: bool,
},
/// command C
@@ -48,7 +45,7 @@ pub enum Cmd {
/// The options for C
#[derive(Clap, Debug, PartialEq)]
pub struct COpt {
#[clap(short = "b")]
#[clap(short)]
bob: bool,
}

Loading