# # # patch "NEWS" # from [3c4114362b6f31dd11fba190abd4feafadee9d84] # to [1bc7803754869f1a94e537297520dd573aed6914] # # patch "option.cc" # from [4ec223067e7788e1fcba8bf6fff383c7fceee3ce] # to [2de045274ac6fa6d23dcc078388e2c5fd3bbb5be] # # patch "tests/complete_option_names/__driver__.lua" # from [07f0ef46efdbd23bd3de46a6f0e4e84a4e62933a] # to [642455fef8c2e5d21b5976222e3e3ee0b08f5ca4] # ============================================================ --- NEWS 3c4114362b6f31dd11fba190abd4feafadee9d84 +++ NEWS 1bc7803754869f1a94e537297520dd573aed6914 @@ -177,6 +177,13 @@ Xxx Xxx 99 99:99:99 UTC 2010 be expanded; if the expansion leads to multiple possibilities, all matches and an accompanying short description of the particular expansion are displayed. + Two types of expansions are available: simple prefix matching + and word abbreviation matching. Single-word options like '--update' + are easier to expand from prefixes, as they're unique after a few + characters, in this example '--up' already matches. + Multi-word options like for example '--ignore-suspend-certs' might + collide however with single-worded ones and are best expanded from + abbreviations, in this case '--isc'. - New automate command 'checkout' ============================================================ --- option.cc 4ec223067e7788e1fcba8bf6fff383c7fceee3ce +++ option.cc 2de045274ac6fa6d23dcc078388e2c5fd3bbb5be @@ -273,6 +273,26 @@ void concrete_option_set::from_command_l from_command_line(arguments); } +// checks a multi-word option like 'no-builtin-rcfile' against a +// possible abbreviated given option 'nbr' which is only compiled +// of the first character of each word +static bool +abbrev_match(string const & option, string const & part) +{ + if (option.find('-') == 0) + return false; + + string::const_iterator it = option.begin(); + string opt_part(1, *it); + for (; it != option.end(); ++it) + { + if (*it == '-' && it != option.end()) + opt_part += *(it+1); + } + + return part == opt_part; +} + static concrete_option const & getopt(map const & by_name, string & name) { @@ -292,6 +312,8 @@ getopt(map cons { if (i->first.find(name) == 0) candidates.push_back(i->first); + if (abbrev_match(i->first, name)) + candidates.push_back(i->first); } if (candidates.size() == 0) ============================================================ --- tests/complete_option_names/__driver__.lua 07f0ef46efdbd23bd3de46a6f0e4e84a4e62933a +++ tests/complete_option_names/__driver__.lua 642455fef8c2e5d21b5976222e3e3ee0b08f5ca4 @@ -25,3 +25,12 @@ check(not qgrep("option 'key' has multip check(qgrep("missing argument to option 'key'", "stderr")) check(not qgrep("option 'key' has multiple ambiguous expansions", "stderr")) +-- check that abbreviated options work - use --hidden / --no-hidden / --nh as an example +check(mtn("help"), 0, true, false) +rename("stdout", "no-hidden-expected") +check(mtn("help", "--hidden"), 0, true, false) +rename("stdout", "hidden-expected") +check(not samefile("no-hidden-expected", "hidden-expected")) +-- this is the important part +check(mtn("help", "--hidden", "--nh"), 0, true, false) +check(samefile("stdout", "no-hidden-expected"))