last_getopt_easy_setup.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #include "last_getopt_easy_setup.h"
  2. namespace NLastGetopt {
  3. TEasySetup::TEasySetup(const TStringBuf& optstring)
  4. : TOpts(optstring)
  5. {
  6. AddHelpOption();
  7. }
  8. TOpt& TEasySetup::AdjustParam(const char* longName, const char* help, const char* argName, bool required) {
  9. Y_ASSERT(longName);
  10. TOpt& o = AddLongOption(longName);
  11. if (help) {
  12. o.Help(help);
  13. }
  14. if (argName) {
  15. o.RequiredArgument(argName);
  16. } else {
  17. o.HasArg(NO_ARGUMENT);
  18. }
  19. if (required) {
  20. o.Required();
  21. }
  22. return o;
  23. }
  24. TEasySetup& TEasySetup::operator()(char shortName, const char* longName, const char* help, bool required) {
  25. AdjustParam(longName, help, nullptr, required).AddShortName(shortName);
  26. return *this;
  27. }
  28. TEasySetup& TEasySetup::operator()(char shortName, const char* longName, const char* argName, const char* help, bool required) {
  29. AdjustParam(longName, help, argName, required).AddShortName(shortName);
  30. return *this;
  31. }
  32. TEasySetup& TEasySetup::operator()(const char* longName, const char* help, bool required) {
  33. AdjustParam(longName, help, nullptr, required);
  34. return *this;
  35. }
  36. TEasySetup& TEasySetup::operator()(const char* longName, const char* argName, const char* help, bool required) {
  37. AdjustParam(longName, help, argName, required);
  38. return *this;
  39. }
  40. }