Skip to content

Commit

Permalink
use rust template
Browse files Browse the repository at this point in the history
  • Loading branch information
Veladus committed Nov 27, 2022
1 parent 1a05b61 commit da3ffc2
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 32 deletions.
9 changes: 0 additions & 9 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"] }
21 changes: 0 additions & 21 deletions LICENSE

This file was deleted.

2 changes: 0 additions & 2 deletions README.md

This file was deleted.

23 changes: 23 additions & 0 deletions src/command_line.rs
Original file line number Diff line number Diff line change
@@ -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
}
10 changes: 10 additions & 0 deletions src/dummy_task.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
20 changes: 20 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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)
}

0 comments on commit da3ffc2

Please sign in to comment.