Example #1
0
	/**@brief Print flags but looking at validOptions_ so needs to be called at
	 * the end of set up so that options can be placed into validOptions_
	 * @param out The std::ostream out object to print to
	 */
	void printFlags(std::ostream &out) {

		std::map<std::string, std::map<std::string, std::string>> infoOutRequried;
		std::map<std::string, std::map<std::string, std::string>> infoOutNotRequried;
		for (const auto & f : flags_.flags_) {
			if (f.second.required_) {
				infoOutRequried[f.second.flagGrouping_][f.second.getFlagsStrAutoDash()] = f.second.helpInfo();
			} else {
				infoOutNotRequried[f.second.flagGrouping_][f.second.getFlagsStrAutoDash()] = f.second.helpInfo();
			}
		}
		std::map<std::string, std::string> infoOutHelp;
		infoOutHelp["--getFlags"] = "Print flags";
		infoOutHelp["-h,--help"] = "Print a more detail help message if available";
		std::pair<uint32_t, uint32_t> paddings { 0, 0 };
		auto keyFunc = [](const auto & kv) {return kv.first;};
		auto valFunc =
				[](const auto & kv) {return bashCT::trimForNonTerminalOut(kv.second);};
		if (!infoOutRequried.empty()) {
			for(const auto & requiredFlagGroup : infoOutRequried){
				compareColPaddings(requiredFlagGroup.second, paddings, keyFunc, valFunc);
			}
		}
		if (!infoOutNotRequried.empty()) {
			for(const auto & optionalFlagGroup : infoOutNotRequried){
				compareColPaddings(optionalFlagGroup.second, paddings, keyFunc, valFunc);
			}
		}
		if (!infoOutHelp.empty()) {
			compareColPaddings(infoOutHelp, paddings, keyFunc, valFunc);
		}
		const std::string middleSep = "\t";
		out << commands_.masterProgram_ << " " << commands_.subProgramRaw_ << std::endl;
		if("" != description_){
			out << description_ << std::endl;
		}
		//assuming tab is len of 4
		std::string requiredOptsTitle = bashCT::bold + bashCT::green + "Required Options"
				+ bashCT::reset;
		std::string optionalOptsTitle = bashCT::bold + bashCT::blue + "Optional Options"
				+ bashCT::reset;
		std::string helpOptsTitle = bashCT::bold + "Help Options" + bashCT::reset;
		if (!infoOutRequried.empty()) {
			out
					<< std::string(
							paddings.first + 2
									- round(bashCT::getPrintLen(requiredOptsTitle) / 2.0), ' ')
					<< requiredOptsTitle << std::endl;
			for (const auto & requiredFlagGroup : infoOutRequried) {
				if ("Misc" == requiredFlagGroup.first) {
					continue;
				}
				std::string currentTitle = bashCT::bold + bashCT::purple
						+ requiredFlagGroup.first + bashCT::reset;
				;
				out
						<< std::string(
								paddings.first + 2
										- round(bashCT::getPrintLen(currentTitle) / 2.0), ' ')
						<< currentTitle << std::endl;
				mapOutColAdjust(requiredFlagGroup.second, out, middleSep,
						paddings.first, paddings.second);
			}
			if(in(std::string("Misc"), infoOutRequried)){
				std::string miscTitle = bashCT::bold + bashCT::purple  + "Miscellaneous" + bashCT::reset;;
				out
						<< std::string(
								paddings.first + 2
										- round(bashCT::getPrintLen(miscTitle) / 2.0), ' ')
						<< miscTitle << std::endl;
				mapOutColAdjust(infoOutRequried.at("Misc"), out, middleSep, paddings.first,
						paddings.second);
			}
		}
		if (!infoOutNotRequried.empty()) {
			out
					<< std::string(
							paddings.first + 2
									- round(bashCT::getPrintLen(optionalOptsTitle) / 2.0), ' ')
					<< optionalOptsTitle << std::endl;
			for(const auto & optionalFlagGroup : infoOutNotRequried){
				if("Misc" == optionalFlagGroup.first){
					continue;
				}
				std::string currentTitle = bashCT::bold + bashCT::purple  + optionalFlagGroup.first + bashCT::reset;;
				out
						<< std::string(
								paddings.first + 2
										- round(bashCT::getPrintLen(currentTitle) / 2.0), ' ')
						<< currentTitle << std::endl;
				mapOutColAdjust(optionalFlagGroup.second, out, middleSep, paddings.first,
						paddings.second);
			}
			if(in(std::string("Misc"), infoOutNotRequried)){
				std::string miscTitle = bashCT::bold + bashCT::purple  + "Miscellaneous" + bashCT::reset;;
				out
						<< std::string(
								paddings.first + 2
										- round(bashCT::getPrintLen(miscTitle) / 2.0), ' ')
						<< miscTitle << std::endl;
				mapOutColAdjust(infoOutNotRequried.at("Misc"), out, middleSep, paddings.first,
						paddings.second);
			}
		}
		if (!infoOutHelp.empty()) {
			out
					<< std::string(
							paddings.first + 2
									- round(bashCT::getPrintLen(helpOptsTitle) / 2.0), ' ')
					<< helpOptsTitle << std::endl;
			mapOutColAdjust(infoOutHelp, out, middleSep, paddings.first,
					paddings.second);
		}
		if (!examples_.empty()) {
			out << std::string(
					paddings.first + 2
							- round(bashCT::getPrintLen(helpOptsTitle) / 2.0), ' ')
			<< bashCT::boldGreen("Examples") << std::endl;
			for (const auto & example : examples_) {
				out
						<< njh::replaceString(
								njh::replaceString(example, "MASTERPROGRAM",
										commands_.masterProgram_), "SUBPROGRAM",
								commands_.subProgramRaw_) << std::endl;
			}
		}
	}
Example #2
0
	/**@brief Print flags but looking at validOptions_ so needs to be called at
	 * the end of set up so that options can be placed into validOptions_
	 * @param out The std::ostream out object to print to
	 */
	void printFlags(std::ostream &out) {
		std::map<std::string, std::string> infoOutRequried;
		std::map<std::string, std::string> infoOutNotRequried;
		for (const auto & f : flags_.flags_) {
			if (f.second.required_) {
				infoOutRequried[f.first] = f.second.helpInfo();
			} else {
				infoOutNotRequried[f.first] = f.second.helpInfo();
			}
		}
		std::map<std::string, std::string> infoOutHelp;
		infoOutHelp["-flags,-getFlags"] = "Print flags";
		infoOutHelp["-h,-help"] = "Print a more detail help message if available";
		std::pair<uint32_t, uint32_t> paddings { 0, 0 };
		auto keyFunc = [](const std::pair<std::string, std::string> & kv) {return kv.first;};
		auto valFunc =
				[](const std::pair<std::string, std::string> & kv) {return bashCT::trimForNonTerminalOut(kv.second);};
		if (!infoOutRequried.empty()) {
			compareColPaddings(infoOutRequried, paddings, keyFunc, valFunc);
		}
		if (!infoOutNotRequried.empty()) {
			compareColPaddings(infoOutNotRequried, paddings, keyFunc, valFunc);
		}
		if (!infoOutHelp.empty()) {
			compareColPaddings(infoOutHelp, paddings, keyFunc, valFunc);
		}
		const std::string middleSep = "\t";
		//assuming tab is len of 4
		std::string requiredOptsTitle = bashCT::bold + "Required Options"
				+ bashCT::reset;
		std::string optionalOptsTitle = bashCT::bold + "Optional Options"
				+ bashCT::reset;
		std::string helpOptsTitle = bashCT::bold + "Help Options" + bashCT::reset;
		if (!infoOutRequried.empty()) {
			out
					<< std::string(
							paddings.first + 2
									- round(bashCT::getPrintLen(requiredOptsTitle) / 2.0), ' ')
					<< requiredOptsTitle << std::endl;
			mapOutColAdjust(infoOutRequried, out, middleSep, paddings.first,
					paddings.second);
		}
		if (!infoOutNotRequried.empty()) {
			out
					<< std::string(
							paddings.first + 2
									- round(bashCT::getPrintLen(optionalOptsTitle) / 2.0), ' ')
					<< optionalOptsTitle << std::endl;
			mapOutColAdjust(infoOutNotRequried, out, middleSep, paddings.first,
					paddings.second);
		}
		if (!infoOutHelp.empty()) {
			out
					<< std::string(
							paddings.first + 2
									- round(bashCT::getPrintLen(helpOptsTitle) / 2.0), ' ')
					<< helpOptsTitle << std::endl;
			mapOutColAdjust(infoOutHelp, out, middleSep, paddings.first,
					paddings.second);
		}
	}