bdd_todo/
lib.rs

1use std::{env, process};
2
3/// Provides a connection to the postgres database.
4mod db;
5
6/// Provides functionality for the command `todo help`.
7pub mod help;
8
9/// Provides functionality for the command `todo list`.
10pub mod list;
11
12/// Provides implementation of a Task.
13pub mod task;
14
15/// Provides helper functions for other modules.
16mod util;
17
18/// Based on the arguments provided by the user (`args`), execute the proper
19/// function.
20pub fn run(args: Vec<String>) {
21    // There is no command.
22    if args.len() < 2 {
23        print_intro();
24        process::exit(0);
25    }
26    // There is a command.
27    let command = args[1].as_str();
28    match command {
29        "help" | "--help" => help::print_help(),
30        "list" => list::execute(args),
31        _ => print_intro(),
32    }
33}
34
35/// Print the name of the app and version.
36fn print_version() {
37    let (name, version): (String, String) = (
38        env::var("CARGO_PKG_NAME").unwrap_or(String::from("todo")),
39        env::var("CARGO_PKG_VERSION").unwrap_or(String::from("?")),
40    );
41    println!("{name} v{version}");
42}
43
44/// Print the name of the app and version, as well as how to get help.
45fn print_intro() {
46    print_version();
47    println!("For help, use --help.");
48}