derive_rudo/
derive_rudo.rs

1/// parser inspired by https://github.com/hood/rudo/blob/e448942b752c56dd2be2e2bb5026ced45e215ed6/src/main.rs
2///
3use bpaf::*;
4
5#[derive(Debug, Clone, Bpaf)]
6#[allow(dead_code)]
7#[bpaf(options)]
8struct Options {
9    /// help
10    #[bpaf(external, fallback(Action::List))]
11    action: Action,
12}
13
14#[derive(Debug, Clone, Bpaf)]
15enum Action {
16    /// Add a new TODO item
17    #[bpaf(command)]
18    Add(String),
19
20    /// Mark nth item as done
21    #[bpaf(command)]
22    Mark(usize),
23
24    /// Read nth item
25    #[bpaf(command)]
26    Read(usize),
27
28    /// Lists everything
29    // name argument for command is optional
30    #[bpaf(command("list"))]
31    List,
32}
33
34fn main() {
35    println!("{:?}", options().run());
36}