1
0

feat: finish clap manual namespace

This commit is contained in:
2025-10-02 18:19:11 +08:00
parent 5859264eca
commit 3dd0c85995
3 changed files with 12 additions and 14 deletions

View File

@ -3,6 +3,7 @@
#include "../../patch/stream.hpp" #include "../../patch/stream.hpp"
#include "../../patch/format.hpp" #include "../../patch/format.hpp"
#include "../../string/op.hpp" #include "../../string/op.hpp"
#include "../../rust/env.hpp"
#include <ranges> #include <ranges>
#define CLAP ::yycc::carton::clap #define CLAP ::yycc::carton::clap
@ -10,6 +11,7 @@
#define TERMCOLOR ::yycc::carton::termcolor #define TERMCOLOR ::yycc::carton::termcolor
#define OP ::yycc::string::op #define OP ::yycc::string::op
#define FORMAT ::yycc::patch::format #define FORMAT ::yycc::patch::format
#define ENV ::yycc::rust::env
using namespace ::yycc::patch::stream; using namespace ::yycc::patch::stream;
@ -107,8 +109,12 @@ namespace yycc::carton::clap::manual {
void Manual::print_help(std::ostream &dst) const { void Manual::print_help(std::ostream &dst) const {
this->print_version(); this->print_version();
TERMCOLOR::cprintln(trctx.usage_title, TERMCOLOR::Color::Yellow, TERMCOLOR::Color::Default, TERMCOLOR::Attribute::Default, dst); // only print usage if we can fetch the name of executable
dst << INDENT << FORMAT::format(trctx.usage_body, app.get_summary().get_bin_name()) << std::endl; auto executable = ENV::current_exe();
if (executable.has_value()) {
TERMCOLOR::cprintln(trctx.usage_title, TERMCOLOR::Color::Yellow, TERMCOLOR::Color::Default, TERMCOLOR::Attribute::Default, dst);
dst << INDENT << FORMAT::format(trctx.usage_body, executable.value()) << std::endl;
}
const auto &variables = app.get_variables(); const auto &variables = app.get_variables();
if (!variables.empty()) { if (!variables.empty()) {

View File

@ -3,11 +3,9 @@
namespace yycc::carton::clap::summary { namespace yycc::carton::clap::summary {
Summary::Summary(const std::u8string_view &name, Summary::Summary(const std::u8string_view &name,
const std::u8string_view &bin_name,
const std::u8string_view &author, const std::u8string_view &author,
const std::u8string_view &version, const std::u8string_view &version,
const std::u8string_view &description) : const std::u8string_view &description) : name(name), author(author), version(version), description(description) {}
name(name), bin_name(bin_name), author(author), version(version), description(description) {}
Summary::~Summary() {} Summary::~Summary() {}
@ -15,10 +13,6 @@ namespace yycc::carton::clap::summary {
return this->name; return this->name;
} }
std::u8string_view Summary::get_bin_name() const {
return this->bin_name;
}
std::u8string_view Summary::get_author() const { std::u8string_view Summary::get_author() const {
return this->author; return this->author;
} }

View File

@ -4,11 +4,10 @@
#include <string_view> #include <string_view>
namespace yycc::carton::clap::summary { namespace yycc::carton::clap::summary {
class Summary { class Summary {
public: public:
Summary(const std::u8string_view& name, Summary(const std::u8string_view& name,
const std::u8string_view& bin_name,
const std::u8string_view& author, const std::u8string_view& author,
const std::u8string_view& version, const std::u8string_view& version,
const std::u8string_view& description); const std::u8string_view& description);
@ -17,13 +16,12 @@ namespace yycc::carton::clap::summary {
public: public:
std::u8string_view get_name() const; std::u8string_view get_name() const;
std::u8string_view get_bin_name() const;
std::u8string_view get_author() const; std::u8string_view get_author() const;
std::u8string_view get_version() const; std::u8string_view get_version() const;
std::u8string_view get_description() const; std::u8string_view get_description() const;
private: private:
std::u8string name, bin_name, author, version, description; std::u8string name, author, version, description;
}; };
} } // namespace yycc::carton::clap::summary