Rust equivalent of Brigadier (command parsing and autocomplete library)?

So uh there's this really easy to use library for dealing with commands and autocomplete in Java, called Brigadier. Is there anything similar for Rust? We tried to look but came up empty.

clap and structopt can do it.

Those are designed for argv parsing, which is much easier as you get already-split words. Our use-case is more similar to that of brigadier: we have an interface where users can input commands. We get a plain string, and need to do our own handling of it.

In other words, our input looks like this:

let input = "/foo bar baz";

but clap and structopt expect this:

let input = ["foo", "bar", "baz"];

Have you considered using nom?

You could split the input either simply by whitespace, or using more complex shell rules and then give that to clap/structopt.

To add a bit more detail to @erelde's reply:

clap has a get_matches_from function that you can pass an anything that implements IntoIterator<Item = T> where T implements Into<OsString> + Clone, and get matches back from it.

The iterator returned from split fits this criteria, so the following slight adjustment to the example for get_matches_from works:

let matches = App::new("myprog")
    // Args and options go here...
        "/foo bar baz".split(" ")

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.