2025-09-25 15:29:55 +08:00
|
|
|
#pragma once
|
|
|
|
|
#include "application.hpp"
|
|
|
|
|
#include "../../macro/class_copy_move.hpp"
|
|
|
|
|
#include "../tabulate.hpp"
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
#define NS_YYCC_CLAP ::yycc::carton::clap
|
|
|
|
|
#define NS_YYCC_TABULATE ::yycc::carton::tabulate
|
|
|
|
|
|
2025-09-25 15:52:28 +08:00
|
|
|
namespace yycc::carton::clap::manual {
|
2025-09-25 15:29:55 +08:00
|
|
|
|
2025-12-23 13:59:14 +08:00
|
|
|
/// @brief Structure containing translation context for manual generation.
|
2025-09-25 15:29:55 +08:00
|
|
|
struct ManualTr {
|
|
|
|
|
public:
|
2025-12-23 13:59:14 +08:00
|
|
|
/// @brief Constructs a new ManualTr object with default values.
|
2025-09-25 15:29:55 +08:00
|
|
|
ManualTr();
|
|
|
|
|
~ManualTr();
|
2025-12-06 21:29:51 +08:00
|
|
|
YYCC_DEFAULT_COPY_MOVE(ManualTr)
|
2025-09-25 15:29:55 +08:00
|
|
|
|
|
|
|
|
public:
|
2025-12-23 13:59:14 +08:00
|
|
|
std::u8string author_and_version; ///< Translated string for author and version
|
|
|
|
|
std::u8string usage_title, usage_body; ///< Translated strings for usage title and body
|
|
|
|
|
std::u8string avail_opt, avail_var; ///< Translated strings for available options and variables
|
2025-09-25 15:29:55 +08:00
|
|
|
};
|
2025-09-25 15:52:28 +08:00
|
|
|
|
2025-12-23 13:59:14 +08:00
|
|
|
/// @brief Class responsible for generating help and version information for command line applications.
|
2025-09-25 15:29:55 +08:00
|
|
|
class Manual {
|
|
|
|
|
public:
|
2025-12-23 13:59:14 +08:00
|
|
|
/**
|
|
|
|
|
* @brief Constructs a new Manual object for the given application.
|
|
|
|
|
* @param[in] app The application to generate manual for
|
|
|
|
|
* @param[in] trctx Translation context for manual generation (default if not provided)
|
|
|
|
|
*/
|
2025-09-25 15:29:55 +08:00
|
|
|
Manual(const NS_YYCC_CLAP::application::Application& app, ManualTr&& trctx = ManualTr());
|
|
|
|
|
~Manual();
|
2025-12-06 21:29:51 +08:00
|
|
|
YYCC_DEFAULT_COPY_MOVE(Manual)
|
2025-09-25 15:29:55 +08:00
|
|
|
|
|
|
|
|
private:
|
2025-12-23 13:59:14 +08:00
|
|
|
void setup_table(); ///< Sets up the tables for displaying options and variables
|
|
|
|
|
void fill_opt_table(); ///< Fills the options table with available options
|
|
|
|
|
void fill_var_table(); ///< Fills the variables table with available variables
|
2025-09-25 15:29:55 +08:00
|
|
|
|
|
|
|
|
public:
|
2025-12-23 13:59:14 +08:00
|
|
|
/**
|
|
|
|
|
* @brief Prints the version information of the application.
|
|
|
|
|
* @param[in] dst The output stream to print to (defaults to std::cout)
|
|
|
|
|
*/
|
2025-09-25 15:29:55 +08:00
|
|
|
void print_version(std::ostream& dst = std::cout) const;
|
2025-12-23 13:59:14 +08:00
|
|
|
/**
|
|
|
|
|
* @brief Prints the help information of the application.
|
|
|
|
|
* @param[in] dst The output stream to print to (defaults to std::cout)
|
|
|
|
|
*/
|
2025-09-25 15:29:55 +08:00
|
|
|
void print_help(std::ostream& dst = std::cout) const;
|
|
|
|
|
|
|
|
|
|
private:
|
2025-12-23 13:59:14 +08:00
|
|
|
ManualTr trctx; ///< Translation context for manual generation
|
|
|
|
|
NS_YYCC_CLAP::application::Application app; ///< The application to generate manual for
|
|
|
|
|
NS_YYCC_TABULATE::Tabulate opt_printer; ///< Tabulate object for printing options
|
|
|
|
|
NS_YYCC_TABULATE::Tabulate var_printer; ///< Tabulate object for printing variables
|
2025-09-25 15:29:55 +08:00
|
|
|
};
|
|
|
|
|
|
2025-09-25 15:52:28 +08:00
|
|
|
} // namespace yycc::carton::clap::manual
|
2025-09-25 15:29:55 +08:00
|
|
|
|
|
|
|
|
#undef NS_YYCC_TABULATE
|
2025-12-23 13:59:14 +08:00
|
|
|
#undef NS_YYCC_CLAP
|