Skip to content

Commit

Permalink
Make checks harder to ignore
Browse files Browse the repository at this point in the history
  • Loading branch information
lpil committed Nov 25, 2024
1 parent 0c3343e commit 3ae052f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
`src/` and `test/`.
([PgBiel](https://github.com/PgBiel))

- `gleam publish` now requires more verbose confirmation for publishing Gleam
team packages and v0 packages.
([Louis Pilfold](https://github.com/lpil))

### Language Server

- The language server now provides type information when hovering over argument
Expand Down
5 changes: 5 additions & 0 deletions compiler-cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ pub fn confirm(question: &str) -> Result<bool, Error> {
}
}

pub fn confirm_with_text(response: &str) -> Result<bool, Error> {
let answer = ask(&format!("Type '{response}' to continue"))?;
Ok(response == answer)
}

pub fn ask_password(question: &str) -> Result<String, Error> {
let prompt = format!("{question} (will not be printed as you type): ");
rpassword::prompt_password(prompt)
Expand Down
21 changes: 12 additions & 9 deletions compiler-cli/src/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ impl PublishCommand {
let paths = crate::find_project_paths()?;
let mut config = crate::config::root_config()?;

let should_publish = check_for_gleam_prefix(&config, i_am_sure)?
&& check_for_version_zero(&config, i_am_sure)?
let should_publish = check_for_gleam_prefix(&config)?
&& check_for_version_zero(&config)?
&& check_repo_url(&config, i_am_sure)?;

if !should_publish {
Expand Down Expand Up @@ -147,7 +147,7 @@ valid, {} returned status {}",
}

/// Ask for confirmation if the package name if a v0.x.x version
fn check_for_version_zero(config: &PackageConfig, i_am_sure: bool) -> Result<bool, Error> {
fn check_for_version_zero(config: &PackageConfig) -> Result<bool, Error> {
if config.version.major != 0 {
return Ok(true);
}
Expand All @@ -158,26 +158,29 @@ fn check_for_version_zero(config: &PackageConfig, i_am_sure: bool) -> Result<boo
Semantic versioning doesn't apply to version 0.x.x releases, so your
users will not be protected from breaking changes. This can result
in a poor user experience where packages can break unexpectedly with
updates that would normally be safe."
updates that would normally be safe.
If your package is not ready to be used in production it should not
be published.
\n"
);
let should_publish = i_am_sure || cli::confirm("\nDo you wish to continue?")?;
let should_publish = cli::confirm_with_text("I am not using semantic versioning")?;
println!();
Ok(should_publish)
}

/// Ask for confirmation if the package name if `gleam_*`
fn check_for_gleam_prefix(config: &PackageConfig, i_am_sure: bool) -> Result<bool, Error> {
fn check_for_gleam_prefix(config: &PackageConfig) -> Result<bool, Error> {
if !config.name.starts_with("gleam_") || config.name.starts_with("gleam_community_") {
return Ok(true);
}

println!(
"You are about to publish a package with a name that starts with
the prefix `gleam_`, which is for packages maintained by the Gleam
core team.",
core team.\n",
);
let should_publish =
i_am_sure || cli::confirm("\nAre you sure you want to use this package name?")?;
let should_publish = cli::confirm_with_text("I am part of the Gleam core team")?;
println!();
Ok(should_publish)
}
Expand Down

0 comments on commit 3ae052f

Please sign in to comment.