yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
usage_schema.h
Go to the documentation of this file.
1#ifndef YAZE_CLI_SERVICE_USAGE_SCHEMA_H_
2#define YAZE_CLI_SERVICE_USAGE_SCHEMA_H_
3
4#include <string>
5#include <vector>
6
7#include "absl/strings/string_view.h"
8#include "nlohmann/json.hpp"
9
10namespace yaze::cli {
11
12// One argument recovered from a command usage string such as
13// "dungeon-list-sprites --room <hex> [--format <json|text>]".
15 std::string name; // Flag name without dashes, or a positional placeholder.
16 bool positional = false;
17 bool required = false;
18 bool takes_value = false;
19 std::string value_hint; // "hex" for "--room <hex>".
20 std::vector<std::string> choices; // {"json", "text"} for "<json|text>".
21
22 bool operator==(const UsageParameter&) const = default;
23};
24
25// Parses the conventional usage grammar: `[...]` marks optional groups,
26// `a | b` marks alternatives, `--flag <hint>` / `--flag=<hint>` / `--flag
27// literal` take values, and bare `--flag` is a boolean switch. The leading
28// command name is skipped. Unrecognized tokens are ignored, so free-form
29// usage text degrades to fewer parameters rather than an error.
30std::vector<UsageParameter> ParseUsageParameters(absl::string_view usage);
31
32// JSON Schema object compatible with function-calling `parameters`. Property
33// names are the literal flag names so a tool call maps back to `--name=value`.
34nlohmann::ordered_json UsageParametersToJsonSchema(
35 const std::vector<UsageParameter>& parameters);
36
37} // namespace yaze::cli
38
39#endif // YAZE_CLI_SERVICE_USAGE_SCHEMA_H_
nlohmann::ordered_json UsageParametersToJsonSchema(const std::vector< UsageParameter > &parameters)
std::vector< UsageParameter > ParseUsageParameters(absl::string_view usage)
bool operator==(const UsageParameter &) const =default
std::vector< std::string > choices