From 426035e6fb01f7dd3ea533e32f0efb0f6c1e0db1 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Tue, 8 Dec 2020 11:46:40 +0300 Subject: Add --options-file option --- build2/b-options.cxx | 31 +++++++++++++++++++++++++++++++ build2/b-options.hxx | 8 ++++++++ build2/b-options.ixx | 12 ++++++++++++ build2/b.cli | 23 +++++++++++++++++++++++ build2/b.cxx | 3 ++- 5 files changed, 76 insertions(+), 1 deletion(-) (limited to 'build2') diff --git a/build2/b-options.cxx b/build2/b-options.cxx index 316d7ad..8e424f9 100644 --- a/build2/b-options.cxx +++ b/build2/b-options.cxx @@ -714,6 +714,8 @@ namespace build2 pager_specified_ (false), pager_option_ (), pager_option_specified_ (false), + options_file_ (), + options_file_specified_ (false), default_options_ (), default_options_specified_ (false), no_default_options_ (), @@ -970,6 +972,13 @@ namespace build2 this->pager_option_specified_ = true; } + if (a.options_file_specified_) + { + ::build2::cl::parser< string>::merge ( + this->options_file_, a.options_file_); + this->options_file_specified_ = true; + } + if (a.default_options_specified_) { ::build2::cl::parser< dir_path>::merge ( @@ -1197,6 +1206,25 @@ namespace build2 << " this option to specify multiple pager options." << ::std::endl; os << std::endl + << "\033[1m--options-file\033[0m \033[4mfile\033[0m Read additional options from \033[4mfile\033[0m. Each option should" << ::std::endl + << " appear on a separate line optionally followed by space or" << ::std::endl + << " equal sign (\033[1m=\033[0m) and an option value. Empty lines and lines" << ::std::endl + << " starting with \033[1m#\033[0m are ignored. Option values can be" << ::std::endl + << " enclosed in double (\033[1m\"\033[0m) or single (\033[1m'\033[0m) quotes to preserve" << ::std::endl + << " leading and trailing whitespaces as well as to specify" << ::std::endl + << " empty values. If the value itself contains trailing or" << ::std::endl + << " leading quotes, enclose it with an extra pair of quotes," << ::std::endl + << " for example \033[1m'\"x\"'\033[0m. Non-leading and non-trailing quotes" << ::std::endl + << " are interpreted as being part of the option value." << ::std::endl + << ::std::endl + << " The semantics of providing options in a file is" << ::std::endl + << " equivalent to providing the same set of options in the" << ::std::endl + << " same order on the command line at the point where the" << ::std::endl + << " \033[1m--options-file\033[0m option is specified except that the shell" << ::std::endl + << " escaping and quoting is not required. Repeat this option" << ::std::endl + << " to specify more than one options file." << ::std::endl; + + os << std::endl << "\033[1m--default-options\033[0m \033[4mdir\033[0m The directory to load additional default options files" << ::std::endl << " from." << ::std::endl; @@ -1307,6 +1335,9 @@ namespace build2 _cli_options_map_["--pager-option"] = &::build2::cl::thunk< options, strings, &options::pager_option_, &options::pager_option_specified_ >; + _cli_options_map_["--options-file"] = + &::build2::cl::thunk< options, string, &options::options_file_, + &options::options_file_specified_ >; _cli_options_map_["--default-options"] = &::build2::cl::thunk< options, dir_path, &options::default_options_, &options::default_options_specified_ >; diff --git a/build2/b-options.hxx b/build2/b-options.hxx index d55dd36..fd93aba 100644 --- a/build2/b-options.hxx +++ b/build2/b-options.hxx @@ -573,6 +573,12 @@ namespace build2 bool pager_option_specified () const; + const string& + options_file () const; + + bool + options_file_specified () const; + const dir_path& default_options () const; @@ -647,6 +653,8 @@ namespace build2 bool pager_specified_; strings pager_option_; bool pager_option_specified_; + string options_file_; + bool options_file_specified_; dir_path default_options_; bool default_options_specified_; bool no_default_options_; diff --git a/build2/b-options.ixx b/build2/b-options.ixx index 1d41af2..3d5781c 100644 --- a/build2/b-options.ixx +++ b/build2/b-options.ixx @@ -500,6 +500,18 @@ namespace build2 return this->pager_option_specified_; } + inline const string& options:: + options_file () const + { + return this->options_file_; + } + + inline bool options:: + options_file_specified () const + { + return this->options_file_specified_; + } + inline const dir_path& options:: default_options () const { diff --git a/build2/b.cli b/build2/b.cli index a03e9cc..b54e9a5 100644 --- a/build2/b.cli +++ b/build2/b.cli @@ -639,6 +639,29 @@ namespace build2 specify multiple pager options." } + // The following option is "fake" in that it is actually handled by + // argv_file_scanner. We have it here for documentation. + // + string --options-file + { + "", + "Read additional options from . Each option should appear on a + separate line optionally followed by space or equal sign (\cb{=}) and + an option value. Empty lines and lines starting with \cb{#} are + ignored. Option values can be enclosed in double (\cb{\"}) or single + (\cb{'}) quotes to preserve leading and trailing whitespaces as well as + to specify empty values. If the value itself contains trailing or + leading quotes, enclose it with an extra pair of quotes, for example + \cb{'\"x\"'}. Non-leading and non-trailing quotes are interpreted as + being part of the option value. + + The semantics of providing options in a file is equivalent to providing + the same set of options in the same order on the command line at the + point where the \cb{--options-file} option is specified except that + the shell escaping and quoting is not required. Repeat this option + to specify more than one options file." + } + dir_path --default-options { "", diff --git a/build2/b.cxx b/build2/b.cxx index 18326cc..9a924d6 100644 --- a/build2/b.cxx +++ b/build2/b.cxx @@ -255,7 +255,7 @@ main (int argc, char* argv[]) string args; try { - cl::argv_scanner scan (argc, argv); + cl::argv_file_scanner scan (argc, argv, "--options-file"); size_t argn (0); // Argument count. bool shortcut (false); // True if the shortcut syntax is used. @@ -502,6 +502,7 @@ main (int argc, char* argv[]) trace << "loading " << (r ? "remote " : "local ") << f; } }, + "--options-file", true /* args */)); // Merge the default and command line options. -- cgit v1.1