Skip to content

Commit

Permalink
chore: bootstrapping mehari CLI (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
holtgrewe authored Mar 3, 2023
1 parent c20ba89 commit 6465c4d
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 2 deletions.
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@ readme = "README.md"
name = "mehari"

[dependencies]
anyhow = "1.0.69"
clap = { version = "4.1.8", features = ["derive"] }
clap-verbosity-flag = "2.0.0"
log = "0.4.17"
tracing = { version = "0.1.37", features = ["log"] }
tracing-subscriber = "0.3.16"
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[![CI](https://github.com/bihealth/mehari/actions/workflows/rust.yml/badge.svg)](https://github.com/bihealth/mehari/actions/workflows/rust.yml)
[![codecov](https://codecov.io/gh/bihealth/mehari/branch/main/graph/badge.svg?token=B1dfb7N2n8)](https://codecov.io/gh/bihealth/mehari)

# Mehari

Expand Down
12 changes: 12 additions & 0 deletions src/common.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//! Commonly used code.
use clap::Parser;
use clap_verbosity_flag::{InfoLevel, Verbosity};

/// Commonly used command line arguments.
#[derive(Parser, Debug)]
pub struct Args {
/// Verbosity of the program
#[clap(flatten)]
pub verbose: Verbosity<InfoLevel>,
}
4 changes: 4 additions & 0 deletions src/db/create/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
//! Creation of mehari internal databases.
pub mod seqvar_freqs;
pub mod txs;
20 changes: 20 additions & 0 deletions src/db/create/seqvar_freqs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//! Sequence variant frequency annotation.
use clap::Parser;

/// Command line arguments for `db create seqvar-freqs` sub command.
#[derive(Parser, Debug)]
#[command(about = "Construct mehari sequence variant frequencies database", long_about = None)]
pub struct Args {}

/// Main entry point for `db create seqvar_freqs` sub command.
pub(crate) fn run(common: &crate::common::Args, args: &Args) -> Result<(), anyhow::Error> {
tracing::info!(
"Building sequence variant frequencies table\ncommon args: {:#?}\nargs: {:#?}",
common,
args
);

tracing::info!("Done building sequence variant frequency table");
Ok(())
}
13 changes: 13 additions & 0 deletions src/db/create/txs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//! Transcript database.
use clap::Parser;

/// Command line arguments for `db create txs` sub command.
#[derive(Parser, Debug)]
#[command(about = "Construct mehari transcripts database", long_about = None)]
pub struct Args {}

/// Main entry point for `db create txs` sub command.
pub fn run(_common: &crate::common::Args, _args: &Args) -> Result<(), anyhow::Error> {
todo!()
}
3 changes: 3 additions & 0 deletions src/db/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//! Database construction and introspection tools.
pub mod create;
108 changes: 106 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,107 @@
fn main() {
println!("Hello, world!");
//! Main entry point for the Mehari CLI.
pub mod common;
pub mod db;

use clap::{command, Args, Parser, Subcommand};

#[derive(Debug, Parser)]
#[command(
author,
version,
about = "VCF variant effect prediction and annotation"
)]
struct Cli {
/// Commonly used arguments
#[command(flatten)]
common: common::Args,

/// The sub command to run
#[command(subcommand)]
command: Commands,
}

/// Enum supporting the parsing of top-level commands.
#[allow(clippy::large_enum_variant)]
#[derive(Debug, Subcommand)]
enum Commands {
/// Database-related commands.
Db(Db),
// /// SV related commands.
// Sv(Sv),
// /// Server related commands.
// Server(Server),
}

/// Parsing of "db *" sub commands.
#[derive(Debug, Args)]
#[command(args_conflicts_with_subcommands = true)]
struct Db {
/// The sub command to run
#[command(subcommand)]
command: DbCommands,
}

/// Enum supporting the parsing of "db *" sub commands.
#[derive(Debug, Subcommand)]
enum DbCommands {
Create(DbCreate),
}

/// Parsing of "db create *" sub commands.
#[derive(Debug, Args)]
#[command(args_conflicts_with_subcommands = true)]
struct DbCreate {
/// The sub command to run
#[command(subcommand)]
command: DbCreateCommands,
}

/// Enum supporting the parsing of "db create *" sub commands.
#[derive(Debug, Subcommand)]
enum DbCreateCommands {
Txs(db::create::txs::Args),
SeqvarFreqs(db::create::seqvar_freqs::Args),
}

fn main() -> Result<(), anyhow::Error> {
let cli = Cli::parse();

// Build a tracing subscriber according to the configuration in `cli.common`.
let collector = tracing_subscriber::fmt()
.with_target(false)
.with_max_level(match cli.common.verbose.log_level() {
Some(level) => match level {
log::Level::Error => tracing::Level::ERROR,
log::Level::Warn => tracing::Level::WARN,
log::Level::Info => tracing::Level::INFO,
log::Level::Debug => tracing::Level::DEBUG,
log::Level::Trace => tracing::Level::TRACE,
},
None => tracing::Level::INFO,
})
.compact()
.finish();

// Install collector and go into sub commands.
tracing::subscriber::with_default(collector, || {
tracing::info!("Mehari startup -- letting the camel from the leash...");

match &cli.command {
Commands::Db(db) => match &db.command {
DbCommands::Create(db_create) => match &db_create.command {
DbCreateCommands::Txs(args) => db::create::txs::run(&cli.common, args)?,
DbCreateCommands::SeqvarFreqs(args) => {
db::create::seqvar_freqs::run(&cli.common, args)?
}
},
},
}

tracing::info!("All done. Have a nice day!");

Ok::<(), anyhow::Error>(())
})?;

Ok(())
}

0 comments on commit 6465c4d

Please sign in to comment.