Skip to content

Commit

Permalink
refactor: check for capitalization for specs argument
Browse files Browse the repository at this point in the history
  • Loading branch information
orhun committed Feb 22, 2024
1 parent 2f0fe4e commit a7e2d73
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 17 deletions.
17 changes: 16 additions & 1 deletion src/cli/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ pub struct Args {
/// - `pixi add --pypi boto3`
/// - `pixi add --pypi "boto3==version"
///
#[arg(required = true)]
#[arg(required = true, value_parser = Args::parse_specs)]
pub specs: Vec<String>,

/// The path to 'pixi.toml'
Expand Down Expand Up @@ -88,6 +88,21 @@ pub struct Args {
pub platform: Vec<Platform>,
}

impl Args {
/// Custom string parser for the dependencies.
///
/// Disallows strings with non-lowercase characters.
fn parse_specs(specs: &str) -> Result<String, String> {
if specs.chars().any(|v| !v.is_lowercase()) {
Err(String::from(
"please avoid using capitalized dependency names",
))
} else {
Ok(specs.to_string())
}
}
}

impl DependencyType {
pub fn from_args(args: &Args) -> Self {
if args.pypi {
Expand Down
16 changes: 0 additions & 16 deletions src/project/manifest/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,14 +355,6 @@ impl Manifest {
miette::bail!("pixi does not support wildcard dependencies")
};

// Check for duplicates.
if dependency_table.contains_key(name.as_source()) {
return Err(miette::miette!(
"{} is already added.",
console::style(name.as_normalized()).bold(),
));
}

// Store (or replace) in the document
dependency_table.insert(name.as_source(), Item::Value(spec.to_string().into()));

Expand Down Expand Up @@ -392,14 +384,6 @@ impl Manifest {
consts::PYPI_DEPENDENCIES,
)?;

// Check for duplicates.
if dependency_table.contains_key(name.as_str()) {
return Err(miette::miette!(
"{} is already added.",
console::style(name.as_source_str()).bold(),
));
}

// Add the pypi dependency to the table
dependency_table.insert(name.as_str(), (*requirement).clone().into());

Expand Down

0 comments on commit a7e2d73

Please sign in to comment.