-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: bootstrapping mehari CLI (#4)
- Loading branch information
Showing
8 changed files
with
165 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
//! Database construction and introspection tools. | ||
pub mod create; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(()) | ||
} |