载入中...
搜索中...
未找到
Doc.cpp
浏览该文件的文档.
1#include "cmdline.h"
2#include "common/config.h"
3
4#include <CLI11.hpp>
5#include <filesystem>
6#include <rang.hpp>
7
8#if defined(EVENGINE_IOS)
9#include "ios/ios.h"
10#endif
11
12using namespace std::filesystem;
13using namespace std;
14
15namespace eve::cmd {
16
17struct DocArgs : Handler {
18 bool no_open = false;
19
20 void setup(CLI::App& app, std::shared_ptr<CLI::Formatter> formatter) override {
21 auto doc = app.add_subcommand("doc", "Query the online documentation for a class/function");
22 doc->allow_extras();
23 doc->add_flag("--no-open", no_open,
24 "Print the documentation URL without opening a browser (headless/CI)");
25 }
26
27 int parse(CLI::App& app, Cmdline& cmd) override {
28 auto doc = app.get_subcommand("doc");
29 if (doc->parsed()) {
30 string name = cmd.get_remaining(doc, "");
31 int res = cmd.Doc(name, no_open);
32 return res;
33 }
34 return -1; // not handle
35 }
36};
37
39
40
41// using system command to open a web page
42
43#ifdef _WIN32
44#define OPEN_WEB_PAGE_CMD "start "
45#elif defined(__APPLE__) && !defined(EVENGINE_IOS)
46#define OPEN_WEB_PAGE_CMD "open "
47#elif defined(__unix__) && !defined(EVENGINE_ANDROID)
48#define OPEN_WEB_PAGE_CMD "xdg-open "
49#endif
50
51static inline int openWebPage(string url) {
52#if defined(EVENGINE_IOS)
53 return eve::ios::openURL(url) ? 0 : -1;
54#elif defined(OPEN_WEB_PAGE_CMD)
55 string cmd = OPEN_WEB_PAGE_CMD + url;
56 return system(cmd.c_str());
57#else
58 (void)url;
59 return -1;
60#endif
61}
62
63int Cmdline::Doc(std::string symbol, bool noOpen) {
64 // The user/API manual lives on the organization GitHub Pages site.
65 // Doxygen has no stable per-symbol URL, so open the manual root and echo
66 // the requested symbol (useful for headless/agent invocations).
67 string url = "https://evengine.github.io/EVEngine/";
68 if (!symbol.empty())
69 cout << "EVEngine docs for '" << symbol << "': " << url << "\n";
70 else
71 cout << "EVEngine docs: " << url << "\n";
72 if (noOpen) return 0;
73 return openWebPage(url);
74}
75
76} // namespace eve::cmd
std::string name
命令行模块(eve.cmd):run / build / package / test / zip / dev-server 等子命令入口。
Definition cmdline.h:33
int Doc(std::string name, bool noOpen=false)
显示模块/函数/类型的文档。
Definition Doc.cpp:63
static std::string get_remaining(CLI::App *sub, std::string default_path=".")
子命令剩余位置参数。
Definition cmdline.cpp:80
#define CMD_REG(name)
Definition cmdline.h:101
int parse(CLI::App &app, Cmdline &cmd) override
Parses arguments and runs the command; returns the exit code.
Definition Doc.cpp:27
void setup(CLI::App &app, std::shared_ptr< CLI::Formatter > formatter) override
Registers options on the CLI11 sub-app.
Definition Doc.cpp:20
One eve <subcommand> handler: CLI setup + argument parsing.
Definition cmdline.h:23