Commit graph

173 commits

Author SHA1 Message Date
Árpád Goretity
4cb8237e08 Clean up crate_authors macro 2017-10-05 00:09:18 +02:00
Kevin K
8699dfc37b
style: changes try-bang macro to questionmark 2017-07-29 14:29:22 -04:00
Corentin Henry
23e2f2b07b remove vec_remove!
it is used only once in the whole codebase and is only three lines long
2017-06-12 07:56:22 -07:00
Corentin Henry
80900a388c clippy: op_ref in vec_remove! 2017-06-12 07:56:22 -07:00
Corentin Henry
bc2103c643 clippy: op_ref for _find_by_long! 2017-06-12 07:56:22 -07:00
Corentin Henry
26f8ce01b9 clippy: op_ref in find_by_name! 2017-06-12 07:56:22 -07:00
Corentin Henry
adb253e63d clippy: op_ref 2017-06-12 07:56:22 -07:00
Corentin Henry
2f0e511ab6 clippy doc_markdown 2017-06-12 07:53:55 -07:00
Corentin Henry
548bf64e4a remove unused macros 2017-06-12 07:53:55 -07:00
Kevin K
826048cb3c docs(clap_app!): adds using the @group specifier to the macro docs
Closes #932
2017-05-16 07:23:22 -04:00
Kevin K
f7a8877978 feat(clap_app!): adds support for arg names with hyphens similar to longs with hyphens
One can now use `("config-file")` style arg names

Closes #869
2017-04-05 00:57:47 -04:00
Kevin K
bc08ef3e18 docs(clap_app!): documents the --("some-arg") method for using args with hyphens inside them
Closes #919
2017-04-05 00:47:19 -04:00
Kevin K
44ed8b663c
refactor: moves validation code into it's own module 2017-03-10 08:24:29 -05:00
Kevin K
150756b989
setting(InferSubcommands): adds a setting to allow one to infer shortened subcommands or aliases (i.e. for subcommmand "test", "t", "te", or "tes" would be allowed assuming no other ambiguities)
Closes #863
2017-03-10 08:22:31 -05:00
Kevin K
0efa411963
perf: refactor to remove unneeded vectors and allocations and checks for significant performance increases
Building an `App` struct with a fair number of args/flags/switches, etc. (used ripgrep as test case)
went from taking ~21,000 ns to ~13,000ns.
2017-02-28 08:30:13 -05:00
Eduard-Mihai Burtescu
f28b2353b2 Add missing fragment specifier to a clap_app! rule. 2017-02-18 12:03:41 +02:00
Peter Williams
e635658dad tests: fix clap_app! doctest 2017-02-16 10:48:34 -07:00
Kevin K
e3296e566b Docs (#854)
* docs(App::template) adds missing categories and fixes descriptions

* docs(clap_app): documents all the shorthand syntax

Closes #736

* chore: fixes crates.io category...hopefully
2017-02-16 09:44:44 -05:00
Kevin K
92919f5f67 Call this PR "Raid" cause it's squashin bugs! (#843)
* tests: adds tests for default values triggering conditional requirements

* fix: fixes a bug where default values should have triggered a conditional requirement but didnt

Closes #831

* tests: adds tests for missing conditional requirements in usage string of errors

* fix: fixes a bug where conditionally required args werent appearing in errors

* tests: adds tests for completion generators

* tests: adds tests for completions with binaries names that have underscores

* fix: fixes a bug where ZSH completions would panic if the binary name had an underscore in it

Closes #581

* fix: fixes bash completions for commands that have an underscore in the name

Closes #581

* chore: fix the category for crates.io

* docs(Macros): adds a warning about changing values in Cargo.toml not triggering a rebuild automatically

Closes #838

* fix(Completions): fixes a bug where global args weren't included in the generated completion scripts

Closes #841

* fix: fixes a println->debugln typo

* chore: increase version
2017-02-03 17:43:49 -05:00
Kevin K
69bd16c410
chore: clippy run 2017-01-29 21:19:00 -05:00
Trevor Spiteri
5b29be9b07 docs: fix link from app_from_crate! to crate_authors! (#822) 2017-01-29 18:13:34 -08:00
nabijaczleweli
4d9a82db8e
feat(simple-cargo-app): Implement crate_description!, crate_name! and app_from_crate! macros
Closes #778
2016-12-31 14:25:59 +01:00
Kevin K
988b9cbea4
style: standardizes debug calls and output
Closes #792
2016-12-29 23:34:46 -05:00
Kevin K
198449d643
feat(Conditional Requirements): adds the ability to conditionally require additional args
An arg can now conditionally require additional arguments if it's value matches a specific value.

For example, arg A can state that it only requires arg B if the value X was used with arg A. If any
other value is used with A, arg B isn't required.

Relates to #764
2016-12-28 23:28:21 -05:00
Jędrzej
6fdd2f9d69 feat(no_cargo): add no_cargo feature to disable Cargo-env-var-dependent macros (#786) 2016-12-27 21:07:59 -05:00
Kevin K
83bacb87bb Merge branch 'master' into fix/779/crate_authors!-newlines 2016-12-18 17:08:38 -05:00
nabijaczleweli
315dffc011
Add documentation for new crate_authors!() functionality 2016-12-18 22:43:43 +01:00
nabijaczleweli
15d1619fa2
Default crate_authors!() macro to colon version. Add arm to handle custom separators
This makes default crate_authors!() invocation same as before the
changes
2016-12-18 21:56:44 +01:00
nabijaczleweli
05f4953409
Inline lazy_static! even harder in crate_authors!()
Functionality remains the same
2016-12-18 13:39:43 +01:00
nabijaczleweli
1a84ce22bc
Replace colons with newlines in crate_authors!()
The implementation is basically manually expanded lazy_static! macro
(with some hand-crafted simplifications and inlining), since you can't
use extern crates (and therefore import macros therefrom) in macros.

This ensures that you get this:

    p:\Rust\http>target\debug\http -h
    http 0.1.0
    thecoshman <thecoshman@gmail.com>
    nabijaczleweli <nabijaczleweli@gmail.com>
    Host These Things Please - a basic HTTP server for hosting a folder fast and simply

Instead of this:

    p:\Rust\http>target\debug\http -h
    http 0.1.0
    thecoshman <thecoshman@gmail.com>:nabijaczleweli <nabijaczleweli@gmail.com>
    Host These Things Please - a basic HTTP server for hosting a folder fast and simply

Closes #779
2016-12-18 13:17:34 +01:00
Arnavion
f41ec962c2 feat(clap_app!): Support --("some-arg-name") syntax for defining long arg names
Used for arg names that aren't idents.

Ref #321
2016-12-12 22:42:11 -08:00
Arnavion
9895b671cf feat(clap_app!): Support ("some app name") syntax for defining app names
Used for setting names that aren't Rust idents.

Fixes #759
2016-12-12 22:42:11 -08:00
Kevin K
7cb44abc09
Revert "Auto merge of #737 - kbknapp:questionmark, r=kbknapp"
This reverts commit f24a3760e4, reversing
changes made to 087cee7404.
2016-11-12 12:12:05 -05:00
Kevin K
55e7385685
style: changes try! to ? and rustfmt run 2016-11-11 15:20:07 -05:00
Kevin K
3d37001d1d
imp(Error Output): conflicting errors are now symetrical, meaning more consistent and less confusing
Prior to this commit, conflicting error messages and the suggeseted usage would depend on whether
you defined the conflict on both arguments, or just one, and the order in which you specified the
conflicting arguments at runtime.

Now they are symetrical, meaning the suggestions from the error message are consistent, and it no
longer matters if you specify the conflict in one, or both arguments.

Closes #718
2016-10-31 00:35:23 -04:00
Kevin K
468baadb83
fix: fixes a bug that made determining when to auto-wrap long help messages inconsistent
Closes #688
2016-10-20 19:39:21 -04:00
tormol
cd516006e3 imp: Stabilize clap_app!
It was de-stabilized in 2.0.0 but hasn't been changed since.

This commit also updates docs to reflect that the "unstable" feature does nothing now.
2016-10-16 21:33:52 +02:00
tormol
8c0f55516f docs(yaml): make sure the doc-tests don't fail before "missing file"
Removing an unused import is the only visible change.
2016-10-16 11:31:12 +02:00
Kevin K
b7793a2f4d Issues rollup (#637)
* feat: adds App::with_defaults to automatically use crate_authors! and crate_version! macros

One can now use

```rust
let a = App::with_defaults("My Program");

// same as
let a2 = App::new("My Program")
	.version(crate_version!())
	.author(crate_authors!());
```

Closes #600

* imp(YAML Errors): vastly improves error messages when using YAML

When errors are made while developing, the panic error messages have
been improved instead of relying on the default panic message which is
extremely unhelpful.

Closes #574

* imp(Completions): uses standard conventions for bash completion files, namely '{bin}.bash-completion'

Closes #567

* imp(Help): automatically moves help text to the next line and wraps when term width is determined to be too small, or help text is too long

Now `clap` will check if it should automatically place long help
messages on the next line after the flag/option. This is determined by
checking to see if the space taken by flag/option plus spaces and values
doesn't leave enough room for the entirety of the help message, with the
single exception of of if the flag/option/spaces/values is less than 25%
of the width.

Closes #597

* tests: updates help tests to new forced new line rules

* fix(Groups): fixes some usage strings that contain both args in groups and ones that conflict with each other

Args that conflict *and* are in a group will now only display in the
group and not in the usage string itself.

Closes #616

* chore: updates dep graph

Closes #633

* chore: clippy run

* style: changes debug header to match other Rust projects

* chore: increase version
2016-08-27 23:42:31 -04:00
Roman A. Taycher
05edc4338e removed unstable gate from crate_authors 2016-07-23 15:56:42 -07:00
Kevin K
edf9b2331c imp(arg_enum!): allows using meta items like repr(C) with arg_enum!s
One can now use more than one meta item, and things like `#[repr(C)]`

Example:

```rust

arg_enum! {
	#[repr(C)]
	#[derive(Debug)]
	pub enum MyEnum {
		A=1,
		B=2
	}
}

```

Closes #543
2016-06-28 00:09:25 -04:00
Roger Andersen
43b3d40b8c docs: fix typos 2016-06-24 12:23:08 +02:00
Kevin K
65c2350aa3 feat: colors dont get sent to pipes by default
Color are now only used when outputting to a termainal/TTY. There are three new settings as well
which can be used to control color output, they are:

 * `AppSettings::ColorAuto`: The default, and will only output color when outputting to a terminal or TTY
 * `AppSettings::ColorAlways`: Outputs color no matter where the output is going
 * `AppSettings::ColorNever`: Never colors output

This now allows one to use things like command line options, or environmental variables to turn
colored output on/off.

Closes #512
2016-06-04 11:28:03 -04:00
Kevin K
3312893dda docs: inter-links all types and pages
All doc pages should now be inter-linked between other doc pages and
Rust documentation.

Closes #505
2016-05-15 14:23:37 -04:00
Kevin K
ffde90f2ba style: rustfmt run 2016-05-06 17:52:23 -04:00
Homu
fdbd12e830 Auto merge of #478 - hgrecco:template, r=kbknapp
A new Help Engine with templating capabilities

This set of commits brings a new Help System to CLAP.

Major changes are:
- The help format is (almost) completely defined in `help.rs` instead of being scattered across multiple files.
- The HELP object contains a writer and its methods accept AnyArgs, not the other way around.
- A template option allows the user to change completely the organization of the autogenerated help.
2016-04-18 08:12:39 +09:00
Hernan Grecco
9d757e8678 imp(macros.rs): Added write_nspaces macro (a new version of write_spaces)
`write_nspaces` has three differences with `write_spaces`

  1. Accepts arguments with attribute access (such as self.writer)
  2. The order of the arguments is swapped to make the writer the first
      argument as in other write related macros.
  3. Does not use the `write!` macro under the hood but rather calls
      directly `write`

I have chosen to put the function under a new name to avoid backwards
compatibility problem but it might be better to migrate everything to
`write_nspaces` (and maybe rename it `write_spaces`)
2016-04-13 07:06:22 -03:00
Roman A. Taycher
d0f1d204a0 minor comment fixes 2016-04-11 22:37:36 -07:00
Roman A. Taycher
38fb59abf4 feat(Authors Macro): adds a crate_authors macro
Adds a crate_authors! macro that fetches
crate authors from a (recently added)
cargo enviromental variable populated
from the Cargo file. Like the
crate_version macro.

Closes #447
2016-04-11 16:17:44 -07:00
Holger Rapp
4c676c06e8 Use ::std::result::Result to make macro hygienic. 2016-04-01 22:03:29 +02:00
Kevin K
7166f4f110 refactor(macros): removes ok() from Result.ok().expect() 2016-02-04 02:01:10 -05:00
Kevin K
de32078d75 refactor(macros): implements a better vec_remove and remove_overriden 2016-02-02 07:45:49 -05:00
Kevin K
ca7f197a12 refactor: minor code cleanup 2016-02-02 07:45:49 -05:00
Kevin K
cdee7a0eb2 feat(AppSettings): adds HidePossibleValuesInHelp to skip writing those values 2016-02-02 07:21:01 -05:00
Kevin K
ee96baffd3 fix(value_t_or_exit): fixes typo which causes value_t_or_exit to return a Result 2016-02-02 07:21:01 -05:00
Kevin K
ab41be700b imp(arg_enum): enum declared with arg_enum returns [&'static str; #] instead of Vec 2016-01-31 08:23:34 -05:00
Vincent Prouillet
0c8b84af61 fix: clap_app! should be gated by unstable, not nightly feature 2016-01-30 11:16:13 +00:00
Kevin K
90542747ac chore: fixes doc and style mistakes 2016-01-28 21:58:40 -05:00
Kevin K
f1876388a7 docs: updating docs for 2x release 2016-01-28 11:45:31 -05:00
Kevin K
86f3e33975 refactor(macros): uses macros to implement Settings enums 2016-01-28 11:45:31 -05:00
Kevin K
eb4de9215f imp(From Usage): vastly improves the usage parser
Closes #350
2016-01-28 11:45:31 -05:00
Kevin K
e874a0d5e0 feat(UTF-8): adds support for invalid utf8 in values
Closes #269
2016-01-28 11:45:31 -05:00
Kevin K
c3e96232c9 tests(v2): fixing more tests on the new v2 base 2016-01-28 11:45:31 -05:00
Kevin K
0031d78564 refactor(v2): improving macros for code dedup 2016-01-28 11:45:31 -05:00
Kevin K
7fc18e685f test(v2): fixing tests to pass under new v2 changes 2016-01-28 11:45:31 -05:00
Kevin K
20de5c6e76 feat(v2): implementing the base of 2.x
This commit implements the base changes for clap 2.x
2016-01-28 11:45:31 -05:00
Kevin K
8988853fb8 imp(ArgMatcher): huge refactor and deduplication of code
Tons of code has been moved into functions, deduplicated, made much
easier to read, maintain, and understand. Comments still need to be
added, but that will happen shortly. Modules have also been moved around
to follow Rust conventions and best practices.

All functionality remains exactly the same
2015-11-11 10:26:05 -05:00
Kevin K
bc4495b32e perf(App): more BTreeMap->Vec, Opts and SubCmds 2015-11-08 03:48:13 -05:00
Kevin K
d357640fab perf(App): changes flags BTreeMap->Vec 2015-11-08 01:50:12 -05:00
Kevin K
78971fd68d perf(App): removed unneeded BTreeMap 2015-11-08 01:08:06 -05:00
Kevin K
111745c937 chore: updates clippy 2015-11-07 00:08:15 -05:00
Ben S
00b61ae226 Fix a bunch of typos in comments 2015-11-01 14:02:37 +00:00
Kevin K
e639adad22 style: removes commented out code 2015-10-28 11:00:31 -04:00
Kevin K
d0c13d2960 style: rustfmt run 2015-10-28 10:56:10 -04:00
Kevin K
f161ffa470 chore: updates and implements lint findings 2015-10-28 10:55:26 -04:00
Kevin K
c9a9548a8f fix(Option Args): fixes bug with args and multiple values
Closes #323
2015-10-28 04:54:28 -04:00
Kevin K
2a223dad82 fix(Unified Help): sorts both flags and options as a unified category 2015-10-05 20:36:30 -04:00
Kevin K
b01667ebb3 refactor: changes some arg fields to flags internally 2015-09-30 23:59:40 -04:00
Kevin K
87ba54451d docs: properly names Examples section for rustdoc 2015-09-21 22:06:15 -04:00
Dabo Ross
ffe1458882 Replace crate_version!() macro with simpler call
As of https://github.com/rust-lang/cargo/pull/1094, cargo publishes the full crate version as `CARGO_PKG_VERSION`, rather than *just* the parts of it.

This replaces the more complicated call with simply `env!("CARGO_PKG_VERSION").to_owned()`.
2015-09-12 20:22:01 -07:00
James McGlashan
13712da1d3 fix: Macro benchmarks 2015-09-10 22:23:58 +10:00
Kevin K
07f6d63e17 chore: increase version 2015-09-09 00:00:17 -04:00
Kevin K.
c0c1613188 Merge branch 'master' into issue-231 2015-09-08 22:49:07 -04:00
Kevin K
56b95f3208 feat: allows printing help message by library consumers 2015-09-08 22:38:07 -04:00
James McGlashan
443841b012 feat: Builder macro to assist with App/Arg/Group/SubCommand building 2015-09-08 22:53:31 +10:00
Kevin K
86cf4c4562 feat(YAML): allows building a CLI from YAML files 2015-08-31 23:57:16 -04:00
Kevin K
d715646e69 feat(Args): allows defining POSIX compatible argument conflicts 2015-08-18 23:59:04 -04:00
Kevin K
d0c3b37970 perf(Args and Apps): changes HashSet->Vec in some instances for increased performance 2015-08-18 22:04:22 -04:00
Kevin K
8a2cd7f95f imp: code corrections thanks to rust-clippy 2015-08-14 00:21:16 -04:00
Kevin K
c9195c5f92 fix(Macros): fixes a typo in a macro generated error message 2015-07-19 22:03:59 -04:00
Kevin K
fe5d95c64f fix(Type Errors): fixes formatting of error output when failed type parsing 2015-07-19 21:52:34 -04:00
Kevin K
6d214b549a fix: fixes a bug when parsing multiple {n} newlines inside help strings 2015-07-16 22:16:50 -04:00
Kevin K
f9800a2969 imp(Help Strings): properly aligns and handles newlines in long help strings
Long help strings can now be broken up with newlines that will be
properly aligned in help messages. Simply place a `{n}` wherever you'd
like the newline to appear.

Closes #145
2015-07-16 01:27:58 -04:00
Kevin K
52bcd892ea feat: allows creating unified help messages, a la docopt or getopts
Allows creating help messages with a more unified look, similar to how
docopt and getopts are formatted. (i.e. flags and options are combined
into a single group)

Closes #158
2015-07-16 01:27:05 -04:00
Kevin K
cc76ab8c2b imp(Errors): writes errors to stderr
Closes #154
2015-07-11 11:23:48 -04:00
Kevin K
1528038fbb chore: silence macro definition warnings 2015-07-07 20:06:15 -04:00
Kevin K
d6c3ed54d2 imp(Colors): implements more structured colored output
Closes #129
2015-05-22 23:01:20 -04:00
Kevin K
30fa87ba4e feat(macros): arg_enum! and simple_enum! provide a Vec<&str> of variant names
You can now use  ArgName::variants() to get a Vec<&'static str> of
vairant names (Nice for Arg::possible_values()). It's not as good as
implementing Iterator for the enum, but that can't be done without being
able to concat AST tokens in order to make an "EnumIter" type which
implements iterator and keeps track of when to yield None. But the
overall intent of this issue was to be able to iterate variant names,
which is now possible.

Closes #119
2015-05-15 16:42:00 -04:00
Kevin K
d1219f0d13 feat(macros): arg_enum! and simple_enum! auto-implement Display
enums created with simple_enum! and arg_enum! now auto-implement
std::fmt::Display where the variant only is displayed.

Closes #120
2015-05-15 15:40:06 -04:00
Kevin K
0c264a8ca5 fix(macros): makes macro errors consistent with others
Mainly this is newline fixes

Closes #118
2015-05-15 15:40:06 -04:00