@@ -565,3 +565,73 @@ TEST_F(format_help_test, subcommand_parser)
565565 + basic_options_str + " \n " + version_str ();
566566 EXPECT_EQ (get_parse_cout_on_exit (parser), expected);
567567}
568+
569+ namespace sharg ::custom
570+ {
571+
572+ template <>
573+ struct parsing <std::errc>
574+ {
575+ static inline std::unordered_map<std::string_view, std::errc> const enumeration_names{};
576+ };
577+
578+ } // namespace sharg::custom
579+
580+ TEST_F (format_help_test, auto_synopsis)
581+ {
582+ auto parser = get_parser (" -h" );
583+ parser.info .synopsis .clear ();
584+ ASSERT_TRUE (parser.info .synopsis .empty ());
585+
586+ foo enum_option_value;
587+ std::errc enum_option_value2;
588+ bool flag{};
589+ uint16_t some_int{};
590+ std::filesystem::path value1{};
591+ std::string value2{};
592+ std::vector<std::filesystem::path> container_value1{};
593+ std::vector<std::string> container_value2{};
594+
595+ parser.add_option (some_int, sharg::config{.short_id = ' a' , .long_id = " some_int" });
596+ parser.add_option (value1, sharg::config{.short_id = ' b' , .long_id = " value1" });
597+ parser.add_option (value2, sharg::config{.short_id = ' c' , .long_id = " value2" , .required = true });
598+ parser.add_option (container_value1, sharg::config{.short_id = ' d' , .long_id = " container1" });
599+ parser.add_option (container_value2, sharg::config{.short_id = ' e' , .long_id = " container2" , .required = true });
600+ parser.add_flag (flag, sharg::config{.short_id = ' f' , .long_id = " flag" });
601+ parser.add_option (enum_option_value, sharg::config{.short_id = ' g' , .long_id = " enum" });
602+ parser.add_option (enum_option_value2, sharg::config{.short_id = ' i' , .long_id = " errc" });
603+ parser.add_positional_option (value2, sharg::config{});
604+ parser.add_positional_option (container_value1, sharg::config{});
605+
606+ expected = " test_parser\n "
607+ " ===========\n\n "
608+ " SYNOPSIS\n "
609+ " test_parser [-a|--some_int uint16_t] [-b|--value1 path] -c|--value2 string\n "
610+ " [-d|--container1 path]... -e|--container2 string [-e|--container2\n "
611+ " string]... -f|--flag [-g|--enum enum] [-i|--errc enum] [--] string path...\n\n "
612+ " POSITIONAL ARGUMENTS\n "
613+ " ARGUMENT-1 (std::string)\n "
614+ " ARGUMENT-2 (List of std::filesystem::path)\n "
615+ " Default: []\n\n "
616+ " OPTIONS\n "
617+ " -a, --some_int (unsigned 16 bit integer)\n "
618+ " Default: 0\n "
619+ " -b, --value1 (std::filesystem::path)\n "
620+ " Default: \"\"\n "
621+ " -c, --value2 (std::string)\n "
622+ " -d, --container1 (List of std::filesystem::path)\n "
623+ " Default: []\n "
624+ " -e, --container2 (List of std::string)\n "
625+ " -f, --flag\n "
626+ " -g, --enum (foo)\n "
627+ " Default: one\n "
628+ #ifdef _LIBCPP_VERSION
629+ " -i, --errc (std::__1::errc)\n "
630+ #else
631+ " -i, --errc (std::errc)\n "
632+ #endif
633+ " Default: <UNKNOWN_VALUE>\n "
634+ " \n "
635+ + basic_options_str + " \n " + version_str ();
636+ EXPECT_EQ (get_parse_cout_on_exit (parser), expected);
637+ }
0 commit comments