settle 0.39.0

CLI tool for managing a digital Zettelkasten
use clap::{Arg, Command};

/// Generate the clap App by using a builer pattern
pub fn build() -> Command<'static>
{
    Command::new(env!("CARGO_PKG_NAME"))
    .version(env!("CARGO_PKG_VERSION"))
    .author("xylous <xylous.e@gmail.com>")
    .about("CLI tool to manage a digital Zettelkasten")

    .subcommand_required(true)
    .arg_required_else_help(true)

    .subcommand(Command::new("compl")
        .display_order(4)
        .arg(Arg::new("SHELL").required(true))
        .about("generate completion file for a given shell")
    )

    .subcommand(Command::new("sync")
        .display_order(1)
        .short_flag('S')
        .about("sync the database")
        .arg(Arg::new("PROJECT")
            .display_order(1)
            .conflicts_with_all(&["UPDATE", "RENAME", "GENERATE"])
            .short('p')
            .long("project")
            .takes_value(true)
            .help("helper option to --create and --move; specify working project")
        )
        .arg(Arg::new("CREATE")
            .display_order(2)
            .conflicts_with_all(&["UPDATE", "MOVE", "RENAME", "GENERATE"])
            .short('c')
            .long("create")
            .takes_value(true)
            .help("create a new Zettel")
        )
        .arg(Arg::new("UPDATE")
            .display_order(3)
            .conflicts_with_all(&["MOVE", "RENAME", "GENERATE"])
            .short('u')
            .long("--update")
            .takes_value(true)
            .help("update a note's metadata, given its path")
        )
        .arg(Arg::new("GENERATE")
            .display_order(4)
            .short('g')
            .long("--generate")
            .takes_value(false)
            .help("(re)generate the database")
        )
        .arg(Arg::new("MOVE")
            .display_order(5)
            .conflicts_with_all(&["RENAME", "GENERATE"])
            .short('m')
            .long("move")
            .takes_value(true)
            .requires("PROJECT")
            .help("move the matching Zettel to a project; requires --project")
        )
        .arg(Arg::new("RENAME")
            .display_order(6)
            .conflicts_with("GENERATE")
            .short('n')
            .long("rename")
            .min_values(2)
            .help("rename first argument to last argument, preserving project")
        )
    )

    .subcommand(Command::new("query")
        .display_order(2)
        .short_flag('Q')
        .about("query the database")
        .arg(Arg::new("TITLE")
            .display_order(1)
            .short('t')
            .long("title")
            .takes_value(true)
            .help("keep Zettel with a matching title")
        )
        .arg(Arg::new("PROJECT")
            .display_order(2)
            .short('p')
            .long("project")
            .takes_value(true)
            .help("keep Zettel that are in the matching projects")
        )
        .arg(Arg::new("TAG")
            .display_order(3)
            .short('g')
            .long("tag")
            .takes_value(true)
            .help("keep Zettel that have a matching tag name")
        )
        .arg(Arg::new("TEXT_REGEX")
            .display_order(4)
            .short('x')
            .long("text")
            .takes_value(true)
            .help("keep Zettel that contain some text")
        )
        .arg(Arg::new("LINKS")
            .display_order(5)
            .short('l')
            .long("links")
            .takes_value(true)
            .help("keep Zettel that have links to the matching Zettel")
        )
        .arg(Arg::new("BACKLINKS")
            .display_order(6)
            .short('b')
            .long("backlinks")
            .takes_value(true)
            .help("keep Zettel that have links from the matching Zettel")
        )
        .arg(Arg::new("LONERS")
            .display_order(7)
            .short('o')
            .long("loners")
            .takes_value(false)
            .help("keep Zettel that don't have any links to and fro")
        )
    )

    .subcommand(Command::new("ls")
        .display_order(3)
        .about("list things not related to notes")
        .arg(Arg::new("OBJECT")
            .required(true)
            .help("object to list (tags, projects, ghosts, path)"
        )
    ))
}