config_arg.hpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #pragma once
  2. #include <filesystem>
  3. #include <string>
  4. namespace smartbotic::common {
  5. struct ConfigArg {
  6. std::filesystem::path path;
  7. /**
  8. * True when the caller named a config file on the command line, false when
  9. * the built-in default path is being used.
  10. *
  11. * The distinction decides what a missing file means. Falling back to
  12. * defaults is reasonable when nobody asked for a particular file; it is
  13. * never reasonable when someone did, because the settings they meant to
  14. * apply - database address, project namespace, ports - would be silently
  15. * replaced by other values.
  16. */
  17. bool explicitly_given = false;
  18. };
  19. /**
  20. * Read the config file location from a service's command line.
  21. *
  22. * Accepts, in order of preference:
  23. * --config <path> --config=<path>
  24. * -c <path> -c=<path>
  25. * <path> (bare first argument, the original form)
  26. *
  27. * The flag forms exist because the packaged systemd units have always passed
  28. * "--config /etc/.../webserver.json", while the services only ever read
  29. * argv[1] as a path. That mismatch made every .deb install run on built-in
  30. * defaults with nothing but a warning to say so.
  31. *
  32. * Unknown arguments are ignored rather than rejected, so this stays additive
  33. * for anything else a deployment may already be passing.
  34. */
  35. ConfigArg parseConfigArg(int argc, char* argv[], const std::filesystem::path& default_path);
  36. } // namespace smartbotic::common