Skip to content

Commit 576d0e0

Browse files
committed
docs: updating docs for 2x release
1 parent 177fe5c commit 576d0e0

19 files changed

+1339
-1087
lines changed

src/app/meta.rs

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,10 @@
1+
#[doc(hidden)]
12
pub struct AppMeta<'b> {
2-
// The name displayed to the user when showing version and help/usage information
33
pub name: String,
44
pub bin_name: Option<String>,
5-
// A string of author(s) if desired. Displayed when showing help/usage information
65
pub author: Option<&'b str>,
7-
// The version displayed to the user
86
pub version: Option<&'b str>,
9-
// A brief explanation of the program that gets displayed to the user when shown
10-
// help/usage
11-
// information
127
pub about: Option<&'b str>,
13-
// Additional help information
148
pub more_help: Option<&'b str>,
159
pub usage_str: Option<&'b str>,
1610
pub usage: Option<String>,

src/app/mod.rs

+167-193
Large diffs are not rendered by default.

src/app/parser.rs

+21-36
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use args::{AnyArg, ArgMatcher};
1515
use args::settings::{ArgSettings, ArgFlags};
1616
use errors::{ErrorKind, Error};
1717
use errors::Result as ClapResult;
18-
use utf8::INVALID_UTF8;
18+
use INVALID_UTF8;
1919
use suggestions;
2020
use INTERNAL_ERROR_MSG;
2121
use SubCommand;
@@ -24,6 +24,7 @@ use osstringext::OsStrExt2;
2424
use app::meta::AppMeta;
2525
use args::MatchedArg;
2626

27+
#[doc(hidden)]
2728
pub struct Parser<'a, 'b> where 'a: 'b {
2829
required: Vec<&'b str>,
2930
short_list: Vec<char>,
@@ -114,30 +115,23 @@ impl<'a, 'b> Parser<'a, 'b> where 'a: 'b {
114115

115116
// actually adds the arguments
116117
pub fn add_arg(&mut self, a: &Arg<'a, 'b>) {
117-
if self.flags.iter().any(|f| &f.name == &a.name) ||
118-
self.opts.iter().any(|o| o.name == a.name) ||
119-
self.positionals.values().any(|p| p.name == a.name) {
120-
panic!("Non-unique argument name: {} is already in use", a.name);
121-
}
118+
assert!(!(self.flags.iter().any(|f| &f.name == &a.name)
119+
|| self.opts.iter().any(|o| o.name == a.name)
120+
|| self.positionals.values().any(|p| p.name == a.name)),
121+
format!("Non-unique argument name: {} is already in use", a.name));
122122
if let Some(grp) = a.group {
123123
let ag = self.groups.entry(grp).or_insert_with(|| ArgGroup::with_name(grp));
124124
ag.args.push(a.name);
125125
}
126126
if let Some(s) = a.short {
127-
if self.short_list.contains(&s) {
128-
panic!("Argument short must be unique\n\n\t-{} is already in use",
129-
s);
130-
} else {
131-
self.short_list.push(s);
132-
}
127+
assert!(!self.short_list.contains(&s),
128+
format!("Argument short must be unique\n\n\t-{} is already in use", s));
129+
self.short_list.push(s);
133130
}
134131
if let Some(l) = a.long {
135-
if self.long_list.contains(&l) {
136-
panic!("Argument long must be unique\n\n\t--{} is already in use",
137-
l);
138-
} else {
139-
self.long_list.push(l);
140-
}
132+
assert!(!self.long_list.contains(&l),
133+
format!("Argument long must be unique\n\n\t--{} is already in use", l));
134+
self.long_list.push(l);
141135
if l == "help" {
142136
self.set(AppSettings::NeedsLongHelp);
143137
} else if l == "version" {
@@ -153,12 +147,10 @@ impl<'a, 'b> Parser<'a, 'b> where 'a: 'b {
153147
} else {
154148
a.index.unwrap() as usize
155149
};
156-
if self.positionals.contains_key(&i) {
157-
panic!("Argument \"{}\" has the same index as another positional \
150+
assert!(!self.positionals.contains_key(&i),
151+
format!("Argument \"{}\" has the same index as another positional \
158152
argument\n\n\tPerhaps try .multiple(true) to allow one positional argument \
159-
to take multiple values",
160-
a.name);
161-
}
153+
to take multiple values", a.name));
162154
let pb = PosBuilder::from_arg(&a, i as u8, &mut self.required);
163155
self.positionals.insert(i, pb);
164156
} else if a.is_set(ArgSettings::TakesValue) {
@@ -169,11 +161,9 @@ impl<'a, 'b> Parser<'a, 'b> where 'a: 'b {
169161
self.flags.push(fb);
170162
}
171163
if a.is_set(ArgSettings::Global) {
172-
if a.is_set(ArgSettings::Required) {
173-
panic!("Global arguments cannot be required.\n\n\t'{}' is marked as global and \
174-
required",
175-
a.name);
176-
}
164+
assert!(!a.is_set(ArgSettings::Required),
165+
format!("Global arguments cannot be required.\n\n\t'{}' is marked as global and \
166+
required", a.name));
177167
self.global_args.push(a.into());
178168
}
179169
}
@@ -383,7 +373,6 @@ impl<'a, 'b> Parser<'a, 'b> where 'a: 'b {
383373
self.settings.set(s)
384374
}
385375

386-
387376
pub fn verify_positionals(&mut self) {
388377
// Because you must wait until all arguments have been supplied, this is the first chance
389378
// to make assertions on positional argument indexes
@@ -392,13 +381,9 @@ impl<'a, 'b> Parser<'a, 'b> where 'a: 'b {
392381
// positional arguments to verify there are no gaps (i.e. supplying an index of 1 and 3
393382
// but no 2)
394383
if let Some((idx, ref p)) = self.positionals.iter().rev().next() {
395-
if idx != self.positionals.len() {
396-
panic!("Found positional argument \"{}\" who's index is {} but there are only {} \
397-
positional arguments defined",
398-
p.name,
399-
idx,
400-
self.positionals.len());
401-
}
384+
assert!(!(idx != self.positionals.len()),
385+
format!("Found positional argument \"{}\" who's index is {} but there are only {} \
386+
positional arguments defined", p.name, idx, self.positionals.len()));
402387
}
403388

404389
// Next we verify that only the highest index has a .multiple(true) (if any)

0 commit comments

Comments
 (0)