Skip to content

Commit 8a14a2e

Browse files
committed
some small renames; merged joinable function implementations
1 parent 8e731b6 commit 8a14a2e

File tree

1 file changed

+40
-45
lines changed

1 file changed

+40
-45
lines changed

Diff for: include/clipp.h

+40-45
Original file line numberDiff line numberDiff line change
@@ -3579,14 +3579,9 @@ operator & (group a, group b)
35793579
* where all single char flag params ("-a", "b", ...) are joinable
35803580
*
35813581
*****************************************************************************/
3582-
inline group&
3583-
joinable(group& param) {
3584-
return param.joinable(true);
3585-
}
3586-
3587-
inline group&&
3588-
joinable(group&& param) {
3589-
return std::move(param.joinable(true));
3582+
inline group
3583+
joinable(group g) {
3584+
return g.joinable(true);
35903585
}
35913586

35923587
//-------------------------------------------------------------------
@@ -3676,16 +3671,16 @@ with_prefix(const arg_string& prefix, parameter&& p) {
36763671

36773672
//-------------------------------------------------------------------
36783673
inline group&
3679-
with_prefix(const arg_string& prefix, group& params)
3674+
with_prefix(const arg_string& prefix, group& g)
36803675
{
3681-
for(auto& p : params) {
3676+
for(auto& p : g) {
36823677
if(p.is_group()) {
36833678
with_prefix(prefix, p.as_group());
36843679
} else {
36853680
with_prefix(prefix, p.as_param());
36863681
}
36873682
}
3688-
return params;
3683+
return g;
36893684
}
36903685

36913686

@@ -3726,16 +3721,16 @@ with_prefixes_short_long(const arg_string& shortpfx, const arg_string& longpfx,
37263721
inline group&
37273722
with_prefixes_short_long(const arg_string& shortFlagPrefix,
37283723
const arg_string& longFlagPrefix,
3729-
group& params)
3724+
group& g)
37303725
{
3731-
for(auto& p : params) {
3726+
for(auto& p : g) {
37323727
if(p.is_group()) {
37333728
with_prefixes_short_long(shortFlagPrefix, longFlagPrefix, p.as_group());
37343729
} else {
37353730
with_prefixes_short_long(shortFlagPrefix, longFlagPrefix, p.as_param());
37363731
}
37373732
}
3738-
return params;
3733+
return g;
37393734
}
37403735

37413736

@@ -5356,17 +5351,17 @@ class usage_lines
53565351
public:
53575352
using string = doc_string;
53585353

5359-
usage_lines(const group& params, string prefix = "",
5354+
usage_lines(const group& cli, string prefix = "",
53605355
const doc_formatting& fmt = doc_formatting{})
53615356
:
5362-
params_(params), fmt_(fmt), prefix_(std::move(prefix))
5357+
cli_(cli), fmt_(fmt), prefix_(std::move(prefix))
53635358
{
53645359
if(!prefix_.empty()) prefix_ += ' ';
53655360
if(fmt_.start_column() > 0) prefix_.insert(0, fmt.start_column(), ' ');
53665361
}
53675362

5368-
usage_lines(const group& params, const doc_formatting& fmt):
5369-
usage_lines(params, "", fmt)
5363+
usage_lines(const group& cli, const doc_formatting& fmt):
5364+
usage_lines(cli, "", fmt)
53705365
{}
53715366

53725367
usage_lines& ommit_outermost_group_surrounders(bool yes) {
@@ -5389,7 +5384,7 @@ class usage_lines
53895384

53905385

53915386
private:
5392-
const group& params_;
5387+
const group& cli_;
53935388
doc_formatting fmt_;
53945389
string prefix_;
53955390
bool ommitOutermostSurrounders_ = false;
@@ -5424,10 +5419,10 @@ class usage_lines
54245419
void print_usage(OStream& os) const
54255420
{
54265421
context cur;
5427-
cur.pos = params_.begin_dfs();
5422+
cur.pos = cli_.begin_dfs();
54285423
cur.linestart = true;
54295424
cur.level = cur.pos.level();
5430-
cur.outermost = &params_;
5425+
cur.outermost = &cli_;
54315426

54325427
print_usage(os, cur, prefix_);
54335428
}
@@ -5651,33 +5646,33 @@ class usage_lines
56515646
* @brief prints flags in one group in a merged fashion
56525647
*
56535648
*******************************************************************/
5654-
string joined_label(const group& params, const context& cur) const
5649+
string joined_label(const group& g, const context& cur) const
56555650
{
56565651
if(!fmt_.merge_alternative_flags_with_common_prefix() &&
56575652
!fmt_.merge_joinable_with_common_prefix()) return "";
56585653

5659-
const bool flagsonly = std::all_of(params.begin(), params.end(),
5654+
const bool flagsonly = std::all_of(g.begin(), g.end(),
56605655
[](const pattern& p){
56615656
return p.is_param() && !p.as_param().flags().empty();
56625657
});
56635658

56645659
if(!flagsonly) return "";
56655660

5666-
const bool showOpt = params.all_optional() &&
5667-
!(ommitOutermostSurrounders_ && cur.outermost == &params);
5661+
const bool showOpt = g.all_optional() &&
5662+
!(ommitOutermostSurrounders_ && cur.outermost == &g);
56685663

5669-
auto pfx = params.common_flag_prefix();
5664+
auto pfx = g.common_flag_prefix();
56705665
if(pfx.empty()) return "";
56715666

56725667
const auto n = pfx.size();
5673-
if(params.exclusive() &&
5668+
if(g.exclusive() &&
56745669
fmt_.merge_alternative_flags_with_common_prefix())
56755670
{
56765671
string lbl;
56775672
if(showOpt) lbl += fmt_.optional_prefix();
56785673
lbl += pfx + fmt_.alternatives_prefix();
56795674
bool first = true;
5680-
for(const auto& p : params) {
5675+
for(const auto& p : g) {
56815676
if(p.is_param()) {
56825677
if(first)
56835678
first = false;
@@ -5691,10 +5686,10 @@ class usage_lines
56915686
return lbl;
56925687
}
56935688
//no alternatives, but joinable flags
5694-
else if(params.joinable() &&
5689+
else if(g.joinable() &&
56955690
fmt_.merge_joinable_with_common_prefix())
56965691
{
5697-
const bool allSingleChar = std::all_of(params.begin(), params.end(),
5692+
const bool allSingleChar = std::all_of(g.begin(), g.end(),
56985693
[&](const pattern& p){
56995694
return p.is_param() &&
57005695
p.as_param().flags().front().substr(n).size() == 1;
@@ -5704,7 +5699,7 @@ class usage_lines
57045699
string lbl;
57055700
if(showOpt) lbl += fmt_.optional_prefix();
57065701
lbl += pfx;
5707-
for(const auto& p : params) {
5702+
for(const auto& p : g) {
57085703
if(p.is_param())
57095704
lbl += p.as_param().flags().front().substr(n);
57105705
}
@@ -5833,11 +5828,11 @@ class documentation
58335828
usgFmt_.max_flags_per_param_in_doc());
58345829
}
58355830

5836-
documentation(const group& params,
5831+
documentation(const group& cli,
58375832
const param_filter& filter,
58385833
const doc_formatting& fmt = doc_formatting{})
58395834
:
5840-
documentation(params, fmt, filter)
5835+
documentation(cli, fmt, filter)
58415836
{}
58425837

58435838
template<class OStream>
@@ -5868,20 +5863,20 @@ class documentation
58685863
*
58695864
*******************************************************************/
58705865
template<class OStream>
5871-
void print_doc(OStream& os, const group& params,
5866+
void print_doc(OStream& os, const group& cli,
58725867
printed& sofar,
58735868
int indentLvl = 0) const
58745869
{
5875-
if(params.empty()) return;
5870+
if(cli.empty()) return;
58765871

58775872
//if group itself doesn't have docstring
5878-
if(params.doc().empty()) {
5879-
for(const auto& p : params) {
5873+
if(cli.doc().empty()) {
5874+
for(const auto& p : cli) {
58805875
print_doc(os, p, sofar, indentLvl);
58815876
}
58825877
}
58835878
else { //group itself does have docstring
5884-
bool anyDocInside = std::any_of(params.begin(), params.end(),
5879+
bool anyDocInside = std::any_of(cli.begin(), cli.end(),
58855880
[](const pattern& p){ return !p.doc().empty(); });
58865881

58875882
if(anyDocInside) { //group docstring as title, then child entries
@@ -5890,19 +5885,19 @@ class documentation
58905885
}
58915886
auto indent = string(fmt_.start_column(), ' ');
58925887
if(indentLvl > 0) indent += string(fmt_.indent_size() * indentLvl, ' ');
5893-
os << indent << params.doc() << '\n';
5888+
os << indent << cli.doc() << '\n';
58945889
sofar = printed::nothing;
5895-
for(const auto& p : params) {
5890+
for(const auto& p : cli) {
58965891
print_doc(os, p, sofar, indentLvl + 1);
58975892
}
58985893
sofar = printed::paragraph;
58995894
}
59005895
else { //group label first then group docstring
5901-
auto lbl = usage_lines(params, usgFmt_)
5896+
auto lbl = usage_lines(cli, usgFmt_)
59025897
.ommit_outermost_group_surrounders(true).str();
59035898

59045899
str::trim(lbl);
5905-
print_entry(os, lbl, params.doc(), fmt_, sofar, indentLvl);
5900+
print_entry(os, lbl, cli.doc(), fmt_, sofar, indentLvl);
59065901
}
59075902
}
59085903
}
@@ -6122,13 +6117,13 @@ class man_page
61226117
*
61236118
*****************************************************************************/
61246119
inline man_page
6125-
make_man_page(const group& params,
6120+
make_man_page(const group& cli,
61266121
doc_string progname = "",
61276122
const doc_formatting& fmt = doc_formatting{})
61286123
{
61296124
man_page man;
6130-
man.append_section("SYNOPSIS", usage_lines(params,progname,fmt).str());
6131-
man.append_section("OPTIONS", documentation(params,fmt).str());
6125+
man.append_section("SYNOPSIS", usage_lines(cli,progname,fmt).str());
6126+
man.append_section("OPTIONS", documentation(cli,fmt).str());
61326127
return man;
61336128
}
61346129

0 commit comments

Comments
 (0)