Prechádzať zdrojové kódy

Print out simple default values.

Sam Jaffe 4 rokov pred
rodič
commit
d613e83598

+ 12 - 0
include/program_args/arguments_impl.hpp

@@ -28,6 +28,10 @@ template <typename Impl>
 template <typename T>
 auto Arguments<Impl>::Argument::operator=(T && value) {
   is_optional = true;
+  if (description.size()) {
+    using ::program::to_string;
+    description += "Default Value: " + to_string(value);
+  }
   return WithDefault<Argument, T>{*this, std::forward<T>(value)};
 }
 
@@ -60,6 +64,10 @@ template <typename Impl> Arguments<Impl>::Flag::operator bool() const {
 }
 
 template <typename Impl> auto Arguments<Impl>::Flag::operator=(bool && value) {
+  if (description.size()) {
+    description += "Default Value: ";
+    description += (value ? "true" : "false");
+  }
   default_value = value;
   return *this;
 }
@@ -88,6 +96,10 @@ template <typename Impl> Arguments<Impl>::Option::operator bool() const {
 template <typename Impl>
 template <typename T>
 auto Arguments<Impl>::Option::operator=(T && value) {
+  if (description.size()) {
+    using ::program::to_string;
+    description += "Default Value: " + to_string(value);
+  }
   return WithDefault<Option, T>{*this, std::forward<T>(value)};
 }
 

+ 5 - 0
include/program_args/utilities.h

@@ -88,4 +88,9 @@ struct conversion_helper<std::vector<T>> : conversion_helper<T> {
     return rval;
   }
 };
+
+using std::to_string;
+template <typename T> std::string to_string(T const &) { return "?"; }
+inline std::string to_string(char const * str) { return str; }
+inline std::string const & to_string(std::string const & str) { return str; }
 }