Skip to content

How to create a nested command structure using derive? #161

Answered by pacak
f16n asked this question in Q&A
Discussion options

You must be logged in to vote

each level should be mutually exclusive (if new is given, no other commands are possible)
I think I need a toplevel enum (game/login/server) followed by a second level enum

This is a great start. You analyze how bits of the result relate to each other and come up with a structure - top level enum with some enums and structs inside.

This is how enum for server might look like

#[derive(Debug, Clone)]
enum Server {
    Status,
    Restart,
}

You want it to be command "server" on the outside so any bit of the parser can succeed and "status" / "restart" on the inside so you can pass prog server status / prog server restart:

#[derive(Debug, Clone, Bpaf)]
#[bpaf(command)]
enum Server {
    #[bpaf

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
1 reply
@f16n
Comment options

Answer selected by f16n
Comment options

You must be logged in to vote
3 replies
@f16n
Comment options

@pacak
Comment options

@f16n
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
parsing Running the parser to get results
2 participants