Skip to content

Compile time parse plan refactor #1

Description

@aaronaranda

What problem are you trying to solve?

The current implementation takes a more iterative approach with multiple template for call sites to where it is then determined how to parse cli options. A cleaner approach would be to build a parse plan at compile time, using all available information provided through annotations and with reflection. This design would also make it easier to do validation at compile time for things like overlapping options, duplicate annotations, and other potential issues. Compile times would probably also be reduced.

Suggested API or behaviour

struct option_descriptor {
  consteval option_descriptor(std::meta::info info) 
    : is_required{get_annotation<required_tag>(info)},
      long_name{get_annotation<long_name>(info)} // ...
      {}

  bool is_required;
  // ... other tag annotations
  std::string_view long_name;
  char short_name;
};

struct command_descriptor {
  consteval command_descriptor(std::meta::info) { /* ... */ }
  std::vector<optional_descriptor> options;
  std::unordered_map<command_descriptor> subcommands;
};

consteval auto build_parse_plan(std::meta::info info) -> command_descriptor {}

Alternatives you've considered

No response

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions