diff --git a/.gitignore b/.gitignore index 088ba6b..b83d222 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1 @@ -# Generated by Cargo -# will have compiled files and executables /target/ - -# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries -# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html -Cargo.lock - -# These are backup files generated by rustfmt -**/*.rs.bk diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..1889b11 --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,24 @@ +[package] +name = "daily-compprog" +version = "0.1.0" +edition = "2021" +description = "My program! (TODO: Edit this description)" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +# General +miette = "5" + +# Logging +env_logger = "0.9" +log = "0.4" + +# Tokio +tokio = { version = "1", features = ["full"] } + +# Shutdown +tokio-graceful-shutdown = "0.11.1" + +# Command line arguments +clap = { version = "4.0", features = ["derive"] } diff --git a/LICENSE b/LICENSE deleted file mode 100644 index a849873..0000000 --- a/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2022 Veladus - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/README.md b/README.md deleted file mode 100644 index 03e4523..0000000 --- a/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# daily-codeforces -Telegram Bot for Daily Competeive Programming Tasks diff --git a/src/command_line.rs b/src/command_line.rs new file mode 100644 index 0000000..408d23b --- /dev/null +++ b/src/command_line.rs @@ -0,0 +1,23 @@ +use clap::Parser; +use env_logger::Env; + +#[derive(Parser)] +#[clap(version, about, long_about = None)] +pub struct Options { + /// Increase verbosity, and can be used multiple times + #[arg(short, long, action = clap::ArgAction::Count)] + pub verbose: u8, +} + +pub fn parse() -> Options { + let opts = Options::parse(); + + let debug_level = match opts.verbose { + 0 => "info", + 1 => "debug", + _ => "trace", + }; + env_logger::Builder::from_env(Env::default().default_filter_or(debug_level)).init(); + + opts +} diff --git a/src/dummy_task.rs b/src/dummy_task.rs new file mode 100644 index 0000000..f0f38e3 --- /dev/null +++ b/src/dummy_task.rs @@ -0,0 +1,10 @@ +use miette::Result; +use tokio_graceful_shutdown::SubsystemHandle; + +pub async fn dummy_task(subsys: SubsystemHandle) -> Result<()> { + log::info!("dummy_task started."); + subsys.on_shutdown_requested().await; + log::info!("dummy_task stopped"); + + Ok(()) +} diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..7c3bf52 --- /dev/null +++ b/src/main.rs @@ -0,0 +1,20 @@ +mod command_line; +mod dummy_task; + +use miette::Result; +use tokio::time::Duration; +use tokio_graceful_shutdown::Toplevel; + +#[tokio::main] +async fn main() -> Result<()> { + // Query command line options and initialize logging + let _opts = command_line::parse(); + + // Initialize and run subsystems + Toplevel::new() + .start("dummy_task", dummy_task::dummy_task) + .catch_signals() + .handle_shutdown_requests(Duration::from_millis(1000)) + .await + .map_err(Into::into) +}