mod commands; use anyhow::{Context, Result}; use clap::Parser; use notion::ids::DatabaseId; use notion::NotionApi; use serde::{Deserialize, Serialize}; // From #[derive(Parser, Debug)] #[clap(version = "1.0", author = "Jake Swenson")] struct Opts { #[clap(subcommand)] command: SubCommand, } #[derive(Parser, Debug)] 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, task_database_id: Option, } #[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(()) } ion value='create-constructors-when-needed'>create-constructors-when-needed Unnamed repository; edit this file 'description' to name the repository.
aboutsummaryrefslogtreecommitdiff
AgeCommit message (Collapse)AuthorFilesLines
2023-10-17Add JSC.WeakGravatar Jarred Sumner 2-0/+293
2023-10-15more microtasksGravatar Jarred Sumner 1-11/+5
2023-10-15It's starting to workGravatar Jarred Sumner 6-49/+89
2023-10-15Things can happenGravatar Jarred Sumner 9-53/+150
2023-10-15FurtherGravatar Jarred Sumner 1-20/+30
2023-10-15The startup message sends successfullyGravatar Jarred Sumner 4-96/+130
2023-10-15it compiledGravatar Jarred Sumner 2-158/+238
2023-10-15okay we are starting to try itGravatar Jarred Sumner 4-9/+43
2023-10-15Okay most of the code is writtenGravatar Jarred Sumner 3-29/+398
2023-10-14MoreGravatar Jarred Sumner 7-66/+504
2023-10-14wipGravatar Jarred Sumner 8-16/+1194
2023-10-14More progressGravatar Jarred Sumner 4-36/+405
2023-10-13wipGravatar Jarred Sumner 8-48/+308