Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cli): add headings for help sections #884

Merged
merged 1 commit into from
Jun 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 49 additions & 16 deletions packages_rs/nextclade-cli/src/cli/nextalign_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub struct NextalignArgs {
pub command: NextalignCommands,

/// Make output more quiet or more verbose
#[clap(flatten)]
#[clap(flatten, next_help_heading = " Verbosity")]
pub verbosity: Verbosity<WarnLevel>,
}

Expand Down Expand Up @@ -71,7 +71,7 @@ pub enum NextalignOutputSelection {
}

#[derive(Parser, Debug)]
pub struct NextalignRunArgs {
pub struct NextalignRunInputArgs {
/// Path to one or multiple FASTA files with input sequences
///
/// Accepts plain or compressed FASTA files. If a compressed fasta file is provided, it will be transparently
Expand All @@ -82,6 +82,7 @@ pub struct NextalignRunArgs {
///
/// See: https://en.wikipedia.org/wiki/FASTA_format
#[clap(value_hint = ValueHint::FilePath)]
#[clap(display_order = 1)]
pub input_fastas: Vec<PathBuf>,

/// REMOVED. Use positional arguments instead.
Expand Down Expand Up @@ -129,7 +130,10 @@ pub struct NextalignRunArgs {
)]
#[clap(value_hint = ValueHint::FilePath)]
pub genes: Option<Vec<String>>,
}

#[derive(Parser, Debug)]
pub struct NextalignRunOutputArgs {
/// REMOVED. Use `--output-all` instead
#[clap(long)]
#[clap(value_hint = ValueHint::DirPath)]
Expand Down Expand Up @@ -245,13 +249,28 @@ pub struct NextalignRunArgs {
/// Note: the sequences which trigger errors during processing will be omitted from outputs, regardless of this flag.
#[clap(long)]
pub in_order: bool,
}

#[derive(Parser, Debug)]
pub struct NextalignRunOtherArgs {
/// Number of processing jobs. If not specified, all available CPU threads will be used.
#[clap(global = false, long, short = 'j', default_value_t = num_cpus::get() )]
#[clap(global = false, long, short = 'j', default_value_t = num_cpus::get())]
pub jobs: usize,
}

#[clap(flatten)]
#[derive(Parser, Debug)]
pub struct NextalignRunArgs {
#[clap(flatten, next_help_heading = " Inputs")]
pub inputs: NextalignRunInputArgs,

#[clap(flatten, next_help_heading = " Outputs")]
pub outputs: NextalignRunOutputArgs,

#[clap(flatten, next_help_heading = " Alignment parameters")]
pub alignment_params: AlignPairwiseParamsOptional,

#[clap(flatten, next_help_heading = " Other")]
pub other: NextalignRunOtherArgs,
}

fn generate_completions(shell: &str) -> Result<(), Report> {
Expand All @@ -275,15 +294,29 @@ fn generate_completions(shell: &str) -> Result<(), Report> {
/// Get output filenames provided by user or, if not provided, create filenames based on input fasta
pub fn nextalign_get_output_filenames(run_args: &mut NextalignRunArgs) -> Result<(), Report> {
let NextalignRunArgs {
input_fastas: input_fasta,
output_all,
ref mut output_basename,
ref mut output_errors,
ref mut output_fasta,
ref mut output_insertions,
ref mut output_translations,
ref mut output_selection,
..
inputs:
NextalignRunInputArgs {
input_fastas,
input_ref,
input_gene_map,
genes,
..
},
outputs:
NextalignRunOutputArgs {
output_all,
output_basename,
output_selection,
output_fasta,
output_translations,
output_insertions,
output_errors,
include_reference,
in_order,
..
},
other: NextalignRunOtherArgs { jobs },
alignment_params,
} = run_args;

// If `--output-all` is provided, then we need to deduce default output filenames,
Expand All @@ -292,7 +325,7 @@ pub fn nextalign_get_output_filenames(run_args: &mut NextalignRunArgs) -> Result
if let Some(output_all) = output_all {
let output_basename = output_basename
.clone()
.unwrap_or_else(|| get_fasta_basename(input_fasta).unwrap_or_else(|| "nextalign".to_owned()));
.unwrap_or_else(|| get_fasta_basename(input_fastas).unwrap_or_else(|| "nextalign".to_owned()));

let default_output_file_path = output_all.join(&output_basename);

Expand Down Expand Up @@ -402,11 +435,11 @@ For more information, type:
nextalign run --help"#;

pub fn nextalign_check_removed_args(run_args: &mut NextalignRunArgs) -> Result<(), Report> {
if run_args.input_fasta.is_some() {
if run_args.inputs.input_fasta.is_some() {
return make_error!("{ERROR_MSG_INPUT_FASTA_REMOVED}");
}

if run_args.output_dir.is_some() {
if run_args.outputs.output_dir.is_some() {
return make_error!("{ERROR_MSG_OUTPUT_DIR_REMOVED}");
}

Expand Down
49 changes: 29 additions & 20 deletions packages_rs/nextclade-cli/src/cli/nextalign_loop.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::cli::nextalign_cli::NextalignRunArgs;
use crate::cli::nextalign_cli::{
NextalignRunArgs, NextalignRunInputArgs, NextalignRunOtherArgs, NextalignRunOutputArgs,
};
use crate::cli::nextalign_ordered_writer::NextalignOrderedWriter;
use crossbeam::thread;
use eyre::{Report, WrapErr};
Expand All @@ -19,27 +21,34 @@ pub struct NextalignRecord {
pub outputs_or_err: Result<NextalignOutputs, Report>,
}

pub fn nextalign_run(args: NextalignRunArgs) -> Result<(), Report> {
info!("Command-line arguments:\n{args:#?}");
pub fn nextalign_run(run_args: NextalignRunArgs) -> Result<(), Report> {
info!("Command-line arguments:\n{run_args:#?}");

let NextalignRunArgs {
input_fastas: input_fasta,
input_ref,
genes,
input_gene_map,
output_all,
output_basename,
output_selection,
include_reference,
output_fasta,
output_translations,
output_insertions,
output_errors,
jobs,
in_order,
inputs:
NextalignRunInputArgs {
input_fastas,
input_ref,
input_gene_map,
genes,
..
},
outputs:
NextalignRunOutputArgs {
output_all,
output_basename,
output_selection,
output_fasta,
output_translations,
output_insertions,
output_errors,
include_reference,
in_order,
..
},
other: NextalignRunOtherArgs { jobs },
alignment_params: alignment_params_from_cli,
..
} = args;
} = run_args;

let mut alignment_params = AlignPairwiseParams::default();

Expand Down Expand Up @@ -68,7 +77,7 @@ pub fn nextalign_run(args: NextalignRunArgs) -> Result<(), Report> {
let (result_sender, result_receiver) = crossbeam_channel::bounded::<NextalignRecord>(CHANNEL_SIZE);

s.spawn(|_| {
let mut reader = FastaReader::from_paths(&input_fasta).unwrap();
let mut reader = FastaReader::from_paths(&input_fastas).unwrap();
loop {
let mut record = FastaRecord::default();
reader.read(&mut record).unwrap();
Expand Down
80 changes: 59 additions & 21 deletions packages_rs/nextclade-cli/src/cli/nextclade_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ pub struct NextcladeArgs {
pub command: NextcladeCommands,

/// Make output more quiet or more verbose
#[clap(flatten)]
#[clap(flatten, next_help_heading = " Verbosity")]
pub verbosity: Verbosity<WarnLevel>,
}

Expand Down Expand Up @@ -216,7 +216,7 @@ pub enum NextcladeOutputSelection {
}

#[derive(Parser, Debug, Clone)]
pub struct NextcladeRunArgs {
pub struct NextcladeRunInputArgs {
/// Path to one or multiple FASTA files with input sequences
///
/// Accepts plain or compressed FASTA files. If a compressed fasta file is provided, it will be transparently
Expand All @@ -227,6 +227,7 @@ pub struct NextcladeRunArgs {
///
/// See: https://en.wikipedia.org/wiki/FASTA_format
#[clap(value_hint = ValueHint::FilePath)]
#[clap(display_order = 1)]
pub input_fastas: Vec<PathBuf>,

/// REMOVED. Use positional arguments instead.
Expand Down Expand Up @@ -322,7 +323,10 @@ pub struct NextcladeRunArgs {
)]
#[clap(value_hint = ValueHint::FilePath)]
pub genes: Option<Vec<String>>,
}

#[derive(Parser, Debug, Clone)]
pub struct NextcladeRunOutputArgs {
/// REMOVED. Use `--output-all` instead
#[clap(long)]
#[clap(value_hint = ValueHint::DirPath)]
Expand Down Expand Up @@ -515,13 +519,28 @@ pub struct NextcladeRunArgs {
/// Note: the sequences which trigger errors during processing will be omitted from outputs, regardless of this flag.
#[clap(long)]
pub in_order: bool,
}

#[derive(Parser, Debug, Clone)]
pub struct NextcladeRunOtherArgs {
/// Number of processing jobs. If not specified, all available CPU threads will be used.
#[clap(global = false, long, short = 'j', default_value_t = num_cpus::get() )]
#[clap(global = false, long, short = 'j', default_value_t = num_cpus::get())]
pub jobs: usize,
}

#[clap(flatten)]
#[derive(Parser, Debug, Clone)]
pub struct NextcladeRunArgs {
#[clap(flatten, next_help_heading = " Inputs")]
pub inputs: NextcladeRunInputArgs,

#[clap(flatten, next_help_heading = " Outputs")]
pub outputs: NextcladeRunOutputArgs,

#[clap(flatten, next_help_heading = " Alignment parameters")]
pub alignment_params: AlignPairwiseParamsOptional,

#[clap(flatten, next_help_heading = " Other")]
pub other: NextcladeRunOtherArgs,
}

fn generate_completions(shell: &str) -> Result<(), Report> {
Expand All @@ -545,20 +564,39 @@ fn generate_completions(shell: &str) -> Result<(), Report> {
/// Get output filenames provided by user or, if not provided, create filenames based on input fasta
pub fn nextclade_get_output_filenames(run_args: &mut NextcladeRunArgs) -> Result<(), Report> {
let NextcladeRunArgs {
input_fastas: input_fasta,
output_all,
output_basename,
output_ndjson,
output_json,
output_csv,
output_tsv,
output_tree,
output_errors,
output_fasta,
output_insertions,
output_translations,
output_selection,
..
inputs:
NextcladeRunInputArgs {
input_fastas,
input_dataset,
input_ref,
input_tree,
input_qc_config,
input_virus_properties,
input_pcr_primers,
input_gene_map,
genes,
..
},
outputs:
NextcladeRunOutputArgs {
output_all,
output_basename,
output_selection,
output_fasta,
output_translations,
output_ndjson,
output_json,
output_csv,
output_tsv,
output_tree,
output_insertions,
output_errors,
include_reference,
in_order,
..
},
other: NextcladeRunOtherArgs { jobs },
alignment_params,
} = run_args;

// If `--output-all` is provided, then we need to deduce default output filenames,
Expand All @@ -567,7 +605,7 @@ pub fn nextclade_get_output_filenames(run_args: &mut NextcladeRunArgs) -> Result
if let Some(output_all) = output_all {
let output_basename = output_basename
.clone()
.unwrap_or_else(|| get_fasta_basename(input_fasta).unwrap_or_else(|| "nextclade".to_owned()));
.unwrap_or_else(|| get_fasta_basename(input_fastas).unwrap_or_else(|| "nextclade".to_owned()));

let default_output_file_path = output_all.join(&output_basename);

Expand Down Expand Up @@ -708,11 +746,11 @@ For more information, type
nextclade run --help"#;

pub fn nextclade_check_removed_args(run_args: &mut NextcladeRunArgs) -> Result<(), Report> {
if run_args.input_fasta.is_some() {
if run_args.inputs.input_fasta.is_some() {
return make_error!("{ERROR_MSG_INPUT_FASTA_REMOVED}");
}

if run_args.output_dir.is_some() {
if run_args.outputs.output_dir.is_some() {
return make_error!("{ERROR_MSG_OUTPUT_DIR_REMOVED}");
}

Expand Down
Loading