Skip to content

Commit

Permalink
feat(cli): deprecate unused args for dataset coomands
Browse files Browse the repository at this point in the history
Emit messages when the following args are used:

 For `dataset get`:

```
--reference
--attributes
```

 For `dataset list`:

```
--reference
--attributes
--include-old
```

Reminder, Nextclade v3 datasets are uniquely identified by their name (path) and tag only, so all other attributes lost their meaning.

All version tags are listed so `--include-old` is no longer relevant.
  • Loading branch information
ivan-aksamentov committed Oct 12, 2023
1 parent 847eaa1 commit 94c6ee7
Show file tree
Hide file tree
Showing 3 changed files with 115 additions and 59 deletions.
155 changes: 113 additions & 42 deletions packages_rs/nextclade-cli/src/cli/nextclade_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,34 +131,17 @@ pub struct NextcladeDatasetListArgs {
#[clap(value_hint = ValueHint::Other)]
pub name: Option<String>,

/// REMOVED
#[clap(long, short = 'r')]
#[clap(value_hint = ValueHint::Other)]
#[clap(hide_long_help = true, hide_short_help = true)]
pub reference: Option<String>,

/// Restrict list to datasets with this exact version tag.
#[clap(long, short = 't')]
#[clap(value_hint = ValueHint::Other)]
pub tag: Option<String>,

/// REMOVED
#[clap(long, short = 'a')]
#[clap(value_hint = ValueHint::Other)]
#[clap(hide_long_help = true, hide_short_help = true)]
pub attribute: Vec<String>,

/// Include dataset versions that are incompatible with this version of Nextclade CLI.
///
/// By default the incompatible versions are omitted.
#[clap(long)]
pub include_incompatible: bool,

/// REMOVED
#[clap(long)]
#[clap(hide_long_help = true, hide_short_help = true)]
pub include_old: Option<bool>,

/// Include deprecated datasets.
///
/// By default the deprecated datasets are omitted.
Expand Down Expand Up @@ -201,6 +184,22 @@ pub struct NextcladeDatasetListArgs {

#[clap(flatten)]
pub proxy_config: ProxyConfig,

// Deprecated args
/// REMOVED
#[clap(long, short = 'r')]
#[clap(hide_long_help = true, hide_short_help = true)]
pub reference: Option<String>,

/// REMOVED
#[clap(long, short = 'a')]
#[clap(hide_long_help = true, hide_short_help = true)]
pub attribute: Vec<String>,

/// REMOVED
#[clap(long)]
#[clap(hide_long_help = true, hide_short_help = true)]
pub include_old: bool,
}

#[derive(Parser, Debug)]
Expand All @@ -212,25 +211,13 @@ pub struct NextcladeDatasetGetArgs {
#[clap(value_hint = ValueHint::Other)]
pub name: String,

/// REMOVED
#[clap(long, short = 'r')]
#[clap(value_hint = ValueHint::Other)]
#[clap(hide_long_help = true, hide_short_help = true)]
pub reference: Option<String>,

/// Version tag of the dataset to download.
///
/// If this flag is not provided the latest version is downloaded.
#[clap(long, short = 't')]
#[clap(value_hint = ValueHint::Other)]
pub tag: Option<String>,

/// REMOVED
#[clap(long, short = 'a')]
#[clap(value_hint = ValueHint::Other)]
#[clap(hide_long_help = true, hide_short_help = true)]
pub attribute: Vec<String>,

/// Use custom dataset server.
///
/// You can host your own dataset server, with one or more datasets, grouped into dataset collections, and use this server to provide datasets to users of Nextclade CLI and Nextclade Web. Refer to Nextclade dataset documentation for more details.
Expand Down Expand Up @@ -263,6 +250,17 @@ pub struct NextcladeDatasetGetArgs {

#[clap(flatten)]
pub proxy_config: ProxyConfig,

// Deprecated arguments
/// REMOVED
#[clap(long, short = 'r')]
#[clap(hide_long_help = true, hide_short_help = true)]
pub reference: Option<String>,

/// REMOVED
#[clap(long, short = 'a')]
#[clap(hide_long_help = true, hide_short_help = true)]
pub attribute: Vec<String>,
}

#[derive(Copy, Debug, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum, EnumIter)]
Expand Down Expand Up @@ -922,7 +920,8 @@ When positional arguments are not provided, nextclade will read input fasta from
const ERROR_MSG_INPUT_ROOT_SEQ_REMOVED: &str =
r#"The argument `--input-root-seq` (alias `--reference`) is removed in favor of `--input-ref`."#;

const ERROR_MSG_INPUT_GENE_MAP_RENAMED: &str = r#"The argument `--input-gene-map` (alias `--genemap`) is renamed to `--input-annotation`."#;
const ERROR_MSG_INPUT_GENE_MAP_RENAMED: &str =
r#"The argument `--input-gene-map` (alias `--genemap`) is renamed to `--input-annotation`."#;

const ERROR_MSG_OUTPUT_DIR_REMOVED: &str = r#"The argument `--output-dir` is removed in favor of `--output-all`.
Expand Down Expand Up @@ -952,7 +951,7 @@ const ERROR_MSG_OUTPUT_ERRORS_REMOVED: &str = r#"The argument `--output-errors`
In Nextclade v3 the separate arguments `--output-insertions` and `--output-errors` are removed. Please use `--output-csv` (for semicolon-separated table) and `--output-tsv` (for tab-separated table) arguments instead. These tables contain, among others, all the columns from the output insertions table (`--output-insertions`) as well as from the output errors table (`--output-errors`)."#;

const MSG_READ_DOCS: &str = r#"
const MSG_READ_RUN_DOCS: &str = r#"
For more information, type
Expand All @@ -964,39 +963,105 @@ Read Nextclade documentation at:

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

if run_args.inputs.input_root_seq.is_some() || run_args.inputs.reference.is_some() {
return make_error!("{ERROR_MSG_INPUT_ROOT_SEQ_REMOVED}{MSG_READ_DOCS}");
return make_error!("{ERROR_MSG_INPUT_ROOT_SEQ_REMOVED}{MSG_READ_RUN_DOCS}");
}

if run_args.inputs.input_gene_map.is_some() || run_args.inputs.genemap.is_some() {
return make_error!("{ERROR_MSG_INPUT_GENE_MAP_RENAMED}{MSG_READ_DOCS}");
return make_error!("{ERROR_MSG_INPUT_GENE_MAP_RENAMED}{MSG_READ_RUN_DOCS}");
}

if run_args.inputs.input_virus_properties.is_some() {
return make_error!("{ERROR_MSG_INPUT_VIRUS_PROPERTIES_REMOVED}{MSG_READ_DOCS}");
return make_error!("{ERROR_MSG_INPUT_VIRUS_PROPERTIES_REMOVED}{MSG_READ_RUN_DOCS}");
}

if run_args.inputs.input_qc_config.is_some() {
return make_error!("{ERROR_MSG_INPUT_QC_CONFIG_REMOVED}{MSG_READ_DOCS}");
return make_error!("{ERROR_MSG_INPUT_QC_CONFIG_REMOVED}{MSG_READ_RUN_DOCS}");
}

if run_args.inputs.input_pcr_primers.is_some() {
return make_error!("{ERROR_MSG_INPUT_PCR_PRIMERS_REMOVED}{MSG_READ_DOCS}");
return make_error!("{ERROR_MSG_INPUT_PCR_PRIMERS_REMOVED}{MSG_READ_RUN_DOCS}");
}

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

if run_args.outputs.output_insertions.is_some() {
return make_error!("{ERROR_MSG_OUTPUT_INSERTIONS_REMOVED}{MSG_READ_DOCS}");
return make_error!("{ERROR_MSG_OUTPUT_INSERTIONS_REMOVED}{MSG_READ_RUN_DOCS}");
}

if run_args.outputs.output_errors.is_some() {
return make_error!("{ERROR_MSG_OUTPUT_ERRORS_REMOVED}{MSG_READ_DOCS}");
return make_error!("{ERROR_MSG_OUTPUT_ERRORS_REMOVED}{MSG_READ_RUN_DOCS}");
}

Ok(())
}

const MSG_DATASET_NAMING_CHANGE: &str = r#"
Nextclade datasets are now identified only by their name (`--name`) and, optionally, a version tag (`--tag`). All other attributes are now included into the name.
In order to list all dataset names, type:
nextclade dataset list --names-only"#;

const MSG_READ_DATASET_LIST_DOCS: &str = r#"
For more information, type
nextclade dataset list --help
Read Nextclade documentation at:
https://docs.nextstrain.org/projects/nextclade/en/stable"#;

fn nextclade_check_removed_dataset_list_args(args: &NextcladeDatasetListArgs) -> Result<(), Report> {
if args.reference.is_some() {
return make_error!(
"The argument `--reference` (alias `-r`) is removed.{MSG_DATASET_NAMING_CHANGE}{MSG_READ_DATASET_LIST_DOCS}"
);
}

if !args.attribute.is_empty() {
return make_error!(
"The argument `--attribute` (alias `-a`) is removed.{MSG_DATASET_NAMING_CHANGE}{MSG_READ_DATASET_LIST_DOCS}"
);
}

if args.include_old {
return make_error!(
"The argument `--include-old` is removed. All versions are always shown now. {MSG_READ_DATASET_LIST_DOCS}"
);
}

Ok(())
}

const MSG_READ_DATASET_GET_DOCS: &str = r#"
For more information, type
nextclade dataset get --help
Read Nextclade documentation at:
https://docs.nextstrain.org/projects/nextclade/en/stable"#;

fn nextclade_check_removed_dataset_get_args(args: &NextcladeDatasetGetArgs) -> Result<(), Report> {
if args.reference.is_some() {
return make_error!(
"The argument `--reference` (alias `-r`) is removed.{MSG_DATASET_NAMING_CHANGE}{MSG_READ_DATASET_GET_DOCS}"
);
}

if !args.attribute.is_empty() {
return make_error!(
"The argument `--attribute` (alias `-a`) is removed.{MSG_DATASET_NAMING_CHANGE}{MSG_READ_DATASET_GET_DOCS}"
);
}

Ok(())
Expand Down Expand Up @@ -1034,8 +1099,14 @@ pub fn nextclade_parse_cli_args() -> Result<(), Report> {
nextclade_run(*run_args)
}
NextcladeCommands::Dataset(dataset_command) => match dataset_command.command {
NextcladeDatasetCommands::List(dataset_list_args) => nextclade_dataset_list(dataset_list_args),
NextcladeDatasetCommands::Get(dataset_get_args) => nextclade_dataset_get(&dataset_get_args),
NextcladeDatasetCommands::List(dataset_list_args) => {
nextclade_check_removed_dataset_list_args(&dataset_list_args)?;
nextclade_dataset_list(dataset_list_args)
}
NextcladeDatasetCommands::Get(dataset_get_args) => {
nextclade_check_removed_dataset_get_args(&dataset_get_args)?;
nextclade_dataset_get(&dataset_get_args)
}
},
NextcladeCommands::Sort(seq_sort_args) => nextclade_seq_sort(&seq_sort_args),
NextcladeCommands::ReadAnnotation(read_annotation_args) => nextclade_read_annotation(&read_annotation_args),
Expand Down
7 changes: 1 addition & 6 deletions packages_rs/nextclade-cli/src/cli/nextclade_dataset_get.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,14 @@ pub struct DatasetHttpGetParams<'s> {
pub fn nextclade_dataset_get(
NextcladeDatasetGetArgs {
name,
reference,
tag,
attribute,
server,
output_dir,
output_zip,
proxy_config,
..
}: &NextcladeDatasetGetArgs,
) -> Result<(), Report> {
if reference.is_some() || !attribute.is_empty() {
return make_error!("The arguments `--reference` and `--attribute` are removed. Datasets are now queried by `--name` and `--tag` only.\n\nIn order to list all dataset names, type:\n\n nextclade dataset list --names-only\n\n. Please refer to `--help` and to Nextclade documentation for more details.");
}

let verbose = log::max_level() > LevelFilter::Info;

let mut http = HttpClient::new(server, proxy_config, verbose)?;
Expand Down
12 changes: 1 addition & 11 deletions packages_rs/nextclade-cli/src/cli/nextclade_dataset_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,18 @@ use nextclade::utils::info::this_package_version;
pub fn nextclade_dataset_list(
NextcladeDatasetListArgs {
name,
reference,
tag,
attribute,
include_incompatible,
include_old,
include_deprecated,
include_experimental,
include_community,
json,
only_names,
server,
proxy_config,
..
}: NextcladeDatasetListArgs,
) -> Result<(), Report> {
if include_old.is_some() {
return make_error!("The argument `--include-old` is removed.\n\nAll version tags are always listed now\n\n. Please refer to `--help` and to Nextclade documentation for more details.");
}

if reference.is_some() || !attribute.is_empty() {
return make_error!("The arguments `--reference` and `--attribute` are removed. Datasets are now queried by `--name` and `--tag` only.\n\nIn order to list all dataset names, type:\n\n nextclade dataset list --names-only\n\n. Please refer to `--help` and to Nextclade documentation for more details.");
}

let verbose = log::max_level() > LevelFilter::Info;

let mut http = HttpClient::new(&server, &proxy_config, verbose)?;
Expand Down

0 comments on commit 94c6ee7

Please sign in to comment.