Skip to content

Commit

Permalink
Merge pull request #868 from nextstrain/feat/cli-better-errors-on-rem…
Browse files Browse the repository at this point in the history
…oved-args
  • Loading branch information
ivan-aksamentov authored Jun 17, 2022
2 parents 36f0df7 + 21c8568 commit b4f0559
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 6 deletions.
60 changes: 58 additions & 2 deletions packages_rs/nextclade-cli/src/cli/nextalign_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,15 @@ pub enum NextalignOutputSelection {
pub struct NextalignRunArgs {
/// Path to a FASTA file with input sequences
#[clap(value_hint = ValueHint::FilePath)]
pub input_fasta: Vec<PathBuf>,
pub input_fastas: Vec<PathBuf>,

/// REMOVED. Use positional arguments instead.
///
/// Example: nextalign run -D dataset/ -O out/ seq1.fasta seq2.fasta
#[clap(long, short = 'i', visible_alias("sequences"))]
#[clap(value_hint = ValueHint::FilePath)]
#[clap(hide_long_help = true, hide_short_help = true)]
pub input_fasta: Option<PathBuf>,

/// Path to a FASTA file containing reference sequence.
///
Expand Down Expand Up @@ -124,6 +132,12 @@ pub struct NextalignRunArgs {
#[clap(value_hint = ValueHint::FilePath)]
pub genes: Option<Vec<String>>,

/// REMOVED. Use `--output-all` instead
#[clap(long)]
#[clap(value_hint = ValueHint::DirPath)]
#[clap(hide_long_help = true, hide_short_help = true)]
pub output_dir: Option<PathBuf>,

/// Produce all of the output files into this directory, using default basename and predefined suffixes and extensions. This is equivalent to specifying each of the individual `--output-*` flags. Convenient when you want to receive all or most of output files into the same directory and don't care about their filenames.
///
/// Output files can be optionally included or excluded using `--output-selection` flag.
Expand Down Expand Up @@ -252,7 +266,7 @@ 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_fasta,
input_fastas: input_fasta,
output_all,
ref mut output_basename,
ref mut output_errors,
Expand Down Expand Up @@ -349,6 +363,47 @@ At least one of the following flags is required:
Ok(())
}

const ERROR_MSG_INPUT_FASTA_REMOVED: &str = r#"The argument `--input-fasta` (alias: `--sequences`, `-i`) is removed in favor of positional arguments.
Try:
nextalign run -r ref.fasta -m genemap.gff -O out/ seq1.fasta seq2.fasta
^ ^
one or multiple positional arguments
with paths to input fasta files
When positional arguments are not provided, nextalign will read input fasta from standard input.
For more information, type
nextalign run --help"#;

const ERROR_MSG_OUTPUT_DIR_REMOVED: &str = r#"The argument `--output-dir` is removed in favor of `--output-all`.
When provided, `--output-all` allows to write all possible outputs into a directory.
The defaut base name of the files can be overriden with `--output-basename` argument.
The set of output files can be restricted with `--output-selection` argument.
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() {
return make_error!("{ERROR_MSG_INPUT_FASTA_REMOVED}");
}

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

Ok(())
}

pub fn nextalign_parse_cli_args() -> Result<NextalignArgs, Report> {
let mut args = NextalignArgs::parse();

Expand All @@ -369,6 +424,7 @@ pub fn nextalign_parse_cli_args() -> Result<NextalignArgs, Report> {
generate_completions(shell).wrap_err_with(|| format!("When generating completions for shell '{shell}'"))?;
}
NextalignCommands::Run(ref mut run_args) => {
nextalign_check_removed_args(run_args)?;
nextalign_get_output_filenames(run_args).wrap_err("When deducing output filenames")?;
}
}
Expand Down
3 changes: 2 additions & 1 deletion packages_rs/nextclade-cli/src/cli/nextalign_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub fn nextalign_run(args: NextalignRunArgs) -> Result<(), Report> {
info!("Command-line arguments:\n{args:#?}");

let NextalignRunArgs {
input_fasta,
input_fastas: input_fasta,
input_ref,
genes,
input_gene_map,
Expand All @@ -38,6 +38,7 @@ pub fn nextalign_run(args: NextalignRunArgs) -> Result<(), Report> {
jobs,
in_order,
alignment_params: alignment_params_from_cli,
..
} = args;

let mut alignment_params = AlignPairwiseParams::default();
Expand Down
59 changes: 57 additions & 2 deletions packages_rs/nextclade-cli/src/cli/nextclade_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,15 @@ pub enum NextcladeOutputSelection {
pub struct NextcladeRunArgs {
/// Path to a FASTA file with input sequences
#[clap(value_hint = ValueHint::FilePath)]
pub input_fasta: Vec<PathBuf>,
pub input_fastas: Vec<PathBuf>,

/// REMOVED. Use positional arguments instead.
///
/// Example: nextclade run -D dataset/ -O out/ seq1.fasta seq2.fasta
#[clap(long, short = 'i', visible_alias("sequences"))]
#[clap(value_hint = ValueHint::FilePath)]
#[clap(hide_long_help = true, hide_short_help = true)]
pub input_fasta: Option<PathBuf>,

/// Path to a directory or a zip file containing a dataset.
///
Expand Down Expand Up @@ -318,6 +326,12 @@ pub struct NextcladeRunArgs {
#[clap(value_hint = ValueHint::FilePath)]
pub genes: Option<Vec<String>>,

/// REMOVED. Use `--output-all` instead
#[clap(long)]
#[clap(value_hint = ValueHint::DirPath)]
#[clap(hide_long_help = true, hide_short_help = true)]
pub output_dir: Option<PathBuf>,

/// Produce all of the output files into this directory, using default basename and predefined suffixes and extensions. This is equivalent to specifying each of the individual `--output-*` flags. Convenient when you want to receive all or most of output files into the same directory and don't care about their filenames.
///
/// Output files can be optionally included or excluded using `--output-selection` flag.
Expand Down Expand Up @@ -508,7 +522,7 @@ 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_fasta,
input_fastas: input_fasta,
output_all,
output_basename,
output_ndjson,
Expand Down Expand Up @@ -642,6 +656,46 @@ At least one of the following flags is required:
Ok(())
}

const ERROR_MSG_INPUT_FASTA_REMOVED: &str = r#"The argument `--input-fasta` (alias: `--sequences`, `-i`) is removed in favor of positional arguments.
Try:
nextclade run -D dataset/ -O out/ seq1.fasta seq2.fasta
^ ^
one or multiple positional arguments
with paths to input fasta files
When positional arguments are not provided, nextclade will read input fasta from standard input.
For more information, type:
nextclade run --help"#;

const ERROR_MSG_OUTPUT_DIR_REMOVED: &str = r#"The argument `--output-dir` is removed in favor of `--output-all`.
When provided, `--output-all` allows to write all possible outputs into a directory.
The defaut base name of the files can be overriden with `--output-basename` argument.
The set of output files can be restricted with `--output-selection` argument.
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() {
return make_error!("{ERROR_MSG_INPUT_FASTA_REMOVED}");
}

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

Ok(())
}

pub fn nextclade_parse_cli_args() -> Result<NextcladeArgs, Report> {
let mut args = NextcladeArgs::parse();

Expand All @@ -662,6 +716,7 @@ pub fn nextclade_parse_cli_args() -> Result<NextcladeArgs, Report> {
generate_completions(shell).wrap_err_with(|| format!("When generating completions for shell '{shell}'"))?;
}
NextcladeCommands::Run(ref mut run_args) => {
nextclade_check_removed_args(run_args)?;
nextclade_get_output_filenames(run_args).wrap_err("When deducing output filenames")?;
}
_ => {}
Expand Down
2 changes: 1 addition & 1 deletion packages_rs/nextclade-cli/src/cli/nextclade_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub fn nextclade_run(args: NextcladeRunArgs) -> Result<(), Report> {
info!("Command-line arguments:\n{args:#?}");

let NextcladeRunArgs {
input_fasta,
input_fastas: input_fasta,
output_all,
output_basename,
output_selection,
Expand Down

1 comment on commit b4f0559

@vercel
Copy link

@vercel vercel bot commented on b4f0559 Jun 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nextclade – ./

nextclade.vercel.app
nextclade-git-master-nextstrain.vercel.app
nextclade-nextstrain.vercel.app

Please sign in to comment.