git/
git.rs

1//! `git.rs` serves as a demonstration of how to use subcommands,
2//! as well as a demonstration of adding documentation to subcommands.
3//!
4//! Note, this "fetch" command uses fallback to inner description to get the help message, "add"
5//! uses explicit override with the same value.
6
7use std::path::PathBuf;
8
9use bpaf::*;
10
11#[allow(dead_code)]
12#[derive(Debug, Clone)]
13enum Opt {
14    Fetch {
15        dry_run: bool,
16        all: bool,
17        repository: String,
18    },
19    Add {
20        interactive: bool,
21        all: bool,
22        files: Vec<PathBuf>,
23    },
24}
25
26fn main() {
27    let dry_run = long("dry_run").switch();
28    let all = long("all").switch();
29    let repository = positional::<String>("SRC").fallback("origin".to_string());
30    let fetch = construct!(Opt::Fetch {
31        dry_run,
32        all,
33        repository
34    })
35    .to_options()
36    .descr("fetches branches from remote repository");
37
38    let fetch_cmd = fetch.command("fetch");
39
40    let interactive = short('i').switch();
41    let all = long("all").switch();
42    let files = positional::<PathBuf>("FILE").many();
43    let add = construct!(Opt::Add {
44        interactive,
45        all,
46        files
47    })
48    .to_options()
49    .descr("add files to the staging area");
50
51    let add_cmd = add.command("add").help("add files to the staging area");
52
53    let opt = construct!([fetch_cmd, add_cmd])
54        .to_options()
55        .descr("The stupid content tracker")
56        .run();
57
58    println!("{:?}", opt);
59}