aboutsummaryrefslogtreecommitdiff
path: root/examples/todo/main.rs
blob: 3a01af33e7cc9eda91cb0be4af864bafcf26b244 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
mod commands;

use anyhow::{Context, Result};
use clap::Clap;
use notion::ids::DatabaseId;
use notion::NotionApi;
use serde::{Deserialize, Serialize};

// From <https://docs.rs/clap/3.0.0-beta.2/clap/>
#[derive(Clap)]
#[clap(version = "1.0", author = "Jake Swenson")]
struct Opts {
    #[clap(subcommand)]
    command: SubCommand,
}

#[derive(Clap)]
enum SubCommand {
    /// Configure what database this notion-todo example uses
    Config,
    /// List all todos
    List,
    /// Add a todo item to the notion database
    Add,
    /// Complete a todo item
    Check,
}

#[derive(Deserialize, Serialize)]
struct TodoConfig {
    api_token: Option<String>,
    task_database_id: Option<DatabaseId>,
}

#[tokio::main]
async fn main() -> Result<()> {
    let opts: Opts = Opts::parse();

    // https://docs.rs/config/0.11.0/config/
    let config = config::Config::default()
        .with_merged(config::File::with_name("todo_config"))
        .unwrap_or_default()
        .with_merged(config::Environment::with_prefix("NOTION"))?;

    let config: TodoConfig = config.try_into().context("Failed to read config")?;

    let notion_api = NotionApi::new(
        std::env::var("NOTION_API_TOKEN")
            .or(config
                .api_token
                .ok_or(anyhow::anyhow!("No api token from config")))
            .context(
                "No Notion API token found in either the environment variable \
                        `NOTION_API_TOKEN` or the config file!",
            )?,
    )?;

    match opts.command {
        SubCommand::Config => commands::configure::configure(notion_api).await,
        SubCommand::List => list_tasks(notion_api),
        SubCommand::Add => add_task(notion_api),
        SubCommand::Check => complete_task(notion_api),
    }
}

fn list_tasks(_notion_api: NotionApi) -> Result<()> {
    Ok(())
}

fn add_task(_notion_api: NotionApi) -> Result<()> {
    Ok(())
}

fn complete_task(_notion_api: NotionApi) -> Result<()> {
    Ok(())
}
ommitdiff
path: root/integration/snippets/code-simplification-neql-define.js (unfollow)
AgeCommit message (Expand)AuthorFilesLines
2022-03-27[bun.js] begin the webkit-ingGravatar Jarred Sumner 30-42/+3196
2022-03-27Bun.mmap() (#134)Gravatar evan 3-0/+170
2022-03-26Add a function for moving slices from a typeGravatar Jarred Sumner 1-0/+85
2022-03-26improve performance of accessing `Bun.Transpiler` and `Bun.unsafe`Gravatar Jarred Sumner 5-4/+69
2022-03-26fix `instanceof` checks for classesGravatar Jarred Sumner 1-8/+7
2022-03-26Update syscall.zigGravatar Jarred Sumner 1-2/+2
2022-03-26clarifyGravatar Jarred Sumner 1-22/+22
2022-03-26Update uwsGravatar Jarred Sumner 1-0/+0