From 377cec303eea81fb18b294eb47a54587643dbd01 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 10 Sep 2020 19:05:23 +0300 Subject: Add support for arguments in default options files helpers --- libbutl/default-options.mxx | 50 ++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 17 deletions(-) (limited to 'libbutl/default-options.mxx') diff --git a/libbutl/default-options.mxx b/libbutl/default-options.mxx index e9f92d3..aeb246d 100644 --- a/libbutl/default-options.mxx +++ b/libbutl/default-options.mxx @@ -6,6 +6,7 @@ #endif #ifndef __cpp_lib_modules_ts +#include #include #include // move(), forward(), make_pair() @@ -50,17 +51,21 @@ LIBBUTL_MODEXPORT namespace butl template struct default_options_entry { - path file; - O options; - bool remote; + path file; + O options; + small_vector arguments; + bool remote; }; template using default_options = small_vector, 4>; - // Search for and load (using scanner S and parsing in the U::fail mode for - // both options and arguments) the specified list of options files in the - // specified directories returning a vector of option class instances (O). + // Search for and load the specified list of options files in the specified + // directories returning a vector of option class instances (O). If args is + // false, only options are allowed and are parsed using scanner S in the + // U::fail mode. If args is true, then both options and arguments are + // allowed in any order with options parsed in the U::stop mode. + // // Pass each default options file path to the specified function prior to // load (can be used for tracing, etc). The function signature is: // @@ -106,33 +111,44 @@ LIBBUTL_MODEXPORT namespace butl const optional& home_dir, const optional& extra_dir, const default_options_files&, - F&&); + F&&, + bool args = false); - // Merge the default options and the command line options. + // Merge the default options/arguments and the command line + // options/arguments. // - // Note that this is the default implementation and in some cases you may + // Note that these are the default implementations and in some cases you may // want to provide an options class-specific version that verifies/sanitizes - // the default options (e.g., you may not want to allow certain options to - // be specified in the default options files) or warns/prompts about - // potentially dangerous options if they came from the remote options files. + // the default options/arguments (e.g., you may not want to allow certain + // options to be specified in the default options files) or warns/prompts + // about potentially dangerous options if they came from the remote options + // files. // template O merge_default_options (const default_options&, const O& cmd_ops); - // As above but pass each default option to the specified function prior to - // merging. The function signature is: + template + AS + merge_default_arguments (const default_options&, const AS& cmd_args); + + // As above but pass each default option/argument entry to the specified + // function prior to merging. The function signature is: // // void (const default_options_entry&, const O& cmd_ops) // - // This version can be used to verify the default options. For example, you - // may want to disallow certain options from being specified in the default - // options files. + // This version can be used to verify the default options/arguments. For + // example, you may want to disallow certain options/arguments from being + // specified in the default options files. // template O merge_default_options (const default_options&, const O&, F&&); + template + AS + merge_default_arguments (const default_options&, const AS&, F&&); + // Find a common start (parent) directory stopping at home or root // (excluding). // -- cgit v1.1