*--config-path* _PATH_::
- Let the subsequent command line options operate on configuration file
- _PATH_ instead of the default. Using this option has the same effect as
- setting the environment variable `CCACHE_CONFIGPATH` temporarily.
+ Let the command line options operate on configuration file _PATH_ instead of
+ the default. Using this option has the same effect as setting the
+ environment variable `CCACHE_CONFIGPATH` temporarily.
*-d*, *--directory* _PATH_::
- Let the subsequent command line options operate on cache directory _PATH_
- instead of the default. For example, to show statistics for a cache
- directory at `/shared/ccache` you can run `ccache -d /shared/ccache -s`.
- Using this option has the same effect as setting the environment variable
- `CCACHE_DIR` temporarily.
+ Let the command line options operate on cache directory _PATH_ instead of
+ the default. For example, to show statistics for a cache directory at
+ `/shared/ccache` you can run `ccache -d /shared/ccache -s`. Using this
+ option has the same effect as setting the environment variable `CCACHE_DIR`
+ temporarily.
*--evict-older-than* _AGE_::
process_main_options(int argc, const char* const* argv)
{
int c;
+
+ // First pass: Handle non-command options that affect command options.
+ while ((c = getopt_long(argc,
+ const_cast<char* const*>(argv),
+ options_string,
+ long_options,
+ nullptr))
+ != -1) {
+ switch (c) {
+ case 'd': // --directory
+ Util::setenv("CCACHE_DIR", optarg);
+ break;
+
+ case CONFIG_PATH:
+ Util::setenv("CCACHE_CONFIGPATH", optarg);
+ break;
+ }
+ }
+
+ // Second pass: Handle command options in order.
+ optind = 1;
while ((c = getopt_long(argc,
const_cast<char* const*>(argv),
options_string,
std::string arg = optarg ? optarg : std::string();
switch (c) {
+ case CONFIG_PATH:
+ break; // Already handled in the first pass.
+
+ case 'd': // --directory
+ break; // Already handled in the first pass.
+
case CHECKSUM_FILE: {
Checksum checksum;
Fd fd(arg == "-" ? STDIN_FILENO : open(arg.c_str(), O_RDONLY));
break;
}
- case CONFIG_PATH:
- Util::setenv("CCACHE_CONFIGPATH", arg);
- break;
-
case DUMP_MANIFEST:
return Manifest::dump(arg, stdout) ? 0 : 1;
break;
}
- case 'd': // --directory
- Util::setenv("CCACHE_DIR", arg);
- break;
-
case 'h': // --help
PRINT(stdout, USAGE_TEXT, CCACHE_NAME, CCACHE_NAME);
exit(EXIT_SUCCESS);