Jelajahi Sumber

Rename all things positional -> argument.

Sam Jaffe 4 tahun lalu
induk
melakukan
477c358ef7
2 mengubah file dengan 12 tambahan dan 12 penghapusan
  1. 3 3
      include/program_args/arguments.h
  2. 9 9
      include/program_args/arguments_impl.hpp

+ 3 - 3
include/program_args/arguments.h

@@ -9,7 +9,7 @@ namespace program {
 template <typename Impl> class Arguments {
 protected:
   struct Option;
-  struct Positional;
+  struct Argument;
   template <typename, typename> struct WithDefault;
 
 public:
@@ -29,7 +29,7 @@ private:
   // Metadata variables
   bool primed_{false};
   std::map<std::string, std::string> option_descriptions;
-  std::map<std::string, std::string> positional_descriptions;
+  std::map<std::string, std::string> argument_descriptions;
   std::map<std::string, std::string> option_name_mapping;
   std::map<size_t, std::string> argument_names;
 
@@ -60,7 +60,7 @@ template <typename Impl> struct Arguments<Impl>::Option {
   explicit operator bool() const;
 };
 
-template <typename Impl> struct Arguments<Impl>::Positional {
+template <typename Impl> struct Arguments<Impl>::Argument {
   Arguments<Impl> * self;
   size_t index;
   bool is_optional;

+ 9 - 9
include/program_args/arguments_impl.hpp

@@ -43,11 +43,11 @@ namespace program {
 
 template <typename Impl>
 template <typename T>
-Arguments<Impl>::Positional::operator T() const {
+Arguments<Impl>::Argument::operator T() const {
   return (*this) ? convert<T>(self->arguments.at(index)) : T();
 }
 
-template <typename Impl> Arguments<Impl>::Positional::operator bool() const {
+template <typename Impl> Arguments<Impl>::Argument::operator bool() const {
   bool const good = primed();
   if (good && self->arguments.size() <= index) {
     throw IllegalPositionError("No argument provided", index);
@@ -57,12 +57,12 @@ template <typename Impl> Arguments<Impl>::Positional::operator bool() const {
 
 template <typename Impl>
 template <typename T>
-auto Arguments<Impl>::Positional::operator=(T && value) {
+auto Arguments<Impl>::Argument::operator=(T && value) {
   is_optional = true;
-  return WithDefault<Positional, T>{*this, std::forward<T>(value)};
+  return WithDefault<Argument, T>{*this, std::forward<T>(value)};
 }
 
-template <typename Impl> bool Arguments<Impl>::Positional::primed() const {
+template <typename Impl> bool Arguments<Impl>::Argument::primed() const {
   if (self->primed_) { return true; }
   if (is_optional) {
     self->optional_from = std::min(self->optional_from, index);
@@ -72,7 +72,7 @@ template <typename Impl> bool Arguments<Impl>::Positional::primed() const {
   if (!self->argument_names.emplace(index, name).second) {
     throw IllegalPositionError("Duplicate positional", index);
   }
-  self->positional_descriptions.emplace(name, description);
+  self->argument_descriptions.emplace(name, description);
   return false;
 }
 
@@ -116,8 +116,8 @@ template <typename Impl> void Arguments<Impl>::usage() const {
     std::cout << " " << (index == optional_from ? "[" : "") << name;
   }
   if (optional_from != std::numeric_limits<size_t>::max()) { std::cout << "]"; }
-  std::cout << "\nPositional Arguments:\n";
-  for (auto & [name, desc] : positional_descriptions) {
+  std::cout << "\nArgument Arguments:\n";
+  for (auto & [name, desc] : argument_descriptions) {
     std::cout << "  " << name << ": " << desc << "\n";
   }
   std::cout << "Options:\n";
@@ -141,7 +141,7 @@ auto Arguments<Impl>::option(std::string const & name, char abbrev,
 template <typename Impl>
 auto Arguments<Impl>::argument(size_t index, std::string const & name,
                                std::string const & description) {
-  return Positional{this, index, false, name, description};
+  return Argument{this, index, false, name, description};
 }
 
 }