diff options
Diffstat (limited to 'src/args.cc')
| -rw-r--r-- | src/args.cc | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/src/args.cc b/src/args.cc index 68f296b..078db1a 100644 --- a/src/args.cc +++ b/src/args.cc @@ -1,11 +1,18 @@ #include "args.hh" +#include <algorithm> #include <cassert> +#include <cstddef> +#include <cstdint> #include <format> #include <iostream> #include <map> +#include <memory> #include <optional> +#include <string> +#include <string_view> #include <utility> +#include <vector> namespace { @@ -13,7 +20,7 @@ std::string kEmpty; class OptionImpl : public Args::OptionArgument { public: - enum Type { + enum Type : uint8_t { NoArgument, RequiredArgument, OptionalArgument, @@ -30,11 +37,13 @@ class OptionImpl : public Args::OptionArgument { const std::string arg; const std::string help; - bool is_set() const override { return is_set_; } + [[nodiscard]] bool is_set() const override { return is_set_; } - bool has_argument() const override { return value_.has_value(); } + [[nodiscard]] bool has_argument() const override { + return value_.has_value(); + } - const std::string& argument() const override { + [[nodiscard]] const std::string& argument() const override { if (value_.has_value()) return value_.value(); assert(false); @@ -117,7 +126,7 @@ class ArgsImpl : public Args { // "--", no more options signal if (arguments) { for (++a; a < argc; ++a) - arguments->push_back(argv[a]); + arguments->emplace_back(argv[a]); } break; } @@ -193,7 +202,7 @@ class ArgsImpl : public Args { } } else { if (arguments) - arguments->push_back(argv[a]); + arguments->emplace_back(argv[a]); } } return true; @@ -202,7 +211,7 @@ class ArgsImpl : public Args { void print_error(std::ostream& out) const override { if (last_error_.empty()) return; - out << last_error_ << std::endl; + out << last_error_ << '\n'; } void print_help(std::ostream& out, uint32_t width = 79) const override { @@ -240,7 +249,7 @@ class ArgsImpl : public Args { } need += 2; // margin - option_need.push_back(need); + option_need.emplace_back(need); if (need <= max_need) { indent = std::max(indent, need); } @@ -309,7 +318,7 @@ class ArgsImpl : public Args { if (!opt->longname.empty()) long_.emplace(opt->longname, idx); } - options_.push_back(std::move(opt)); + options_.emplace_back(std::move(opt)); } static inline bool is_whitespace(char c) { |
