Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add options to handle windows style command line options #187

Merged
merged 3 commits into from
Jan 10, 2019
Merged
Changes from 1 commit
Commits
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
Prev Previous commit
remove some extra brackets
  • Loading branch information
phlptp committed Jan 7, 2019
commit 775e413ec08c994459afb12c6c2fdea0b8cf9ae3
16 changes: 7 additions & 9 deletions include/CLI/App.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1189,27 +1189,25 @@ class App {
name_ = nstr.first;
}
commandline = std::move(nstr.second);
} else {
} else
detail::trim(commandline);
}
// the first section of code is to deal with quoted arguments after an '='
// the next section of code is to deal with quoted arguments after an '=' or ':' for windows like operations
if(!commandline.empty()) {
auto escape_detect = [](std::string &str, size_t offset) {
auto next = str[offset + 1];
if((next == '\"') || (next == '\'') || (next == '`')) {
auto astart = str.find_last_of("-/ \"\'`", offset - 1);
if(astart != std::string::npos) {
if(str[astart] == (str[offset] == '=') ? '-' : '/') {
str[offset] = ' '; // interpret this a space so the split_up works properly
}
if(str[astart] == (str[offset] == '=') ? '-' : '/')
str[offset] = ' '; // interpret this as a space so the split_up works properly
}
}
return offset + 1;
return (offset + 1);
};

commandline = detail::find_and_modify(commandline, "=", escape_detect);
if(allow_windows_style_options_) {
if(allow_windows_style_options_)
commandline = detail::find_and_modify(commandline, ":", escape_detect);
}
}

auto args = detail::split_up(std::move(commandline));
Expand Down