refactor: allow specifying different index when publishing

This commit is contained in:
daimond113 2024-11-04 14:53:59 +01:00
parent e53de00120
commit 9bc80a43db
No known key found for this signature in database
GPG key ID: 3A8ECE51328B513C
2 changed files with 13 additions and 6 deletions

View file

@ -108,6 +108,7 @@ Publishes the current project to the pesde registry.
tarball containing the package that would be published, but will not actually tarball containing the package that would be published, but will not actually
publish it. publish it.
- `-y, --yes`: Whether to skip the confirmation prompt. - `-y, --yes`: Whether to skip the confirmation prompt.
- `-i, --index`: Name of the index to publish to. Defaults to `default`.
## `pesde self-install` ## `pesde self-install`

View file

@ -26,7 +26,7 @@ use pesde::{
Project, DEFAULT_INDEX_NAME, MANIFEST_FILE_NAME, Project, DEFAULT_INDEX_NAME, MANIFEST_FILE_NAME,
}; };
#[derive(Debug, Args, Copy, Clone)] #[derive(Debug, Args, Clone)]
pub struct PublishCommand { pub struct PublishCommand {
/// Whether to output a tarball instead of publishing /// Whether to output a tarball instead of publishing
#[arg(short, long)] #[arg(short, long)]
@ -35,6 +35,10 @@ pub struct PublishCommand {
/// Agree to all prompts /// Agree to all prompts
#[arg(short, long)] #[arg(short, long)]
yes: bool, yes: bool,
/// The index to publish to
#[arg(short, long, default_value_t = DEFAULT_INDEX_NAME.to_string())]
index: String,
} }
impl PublishCommand { impl PublishCommand {
@ -460,8 +464,8 @@ impl PublishCommand {
let index_url = manifest let index_url = manifest
.indices .indices
.get(DEFAULT_INDEX_NAME) .get(&self.index)
.context("missing default index")?; .context(format!("missing index {}", self.index))?;
let source = PesdePackageSource::new(index_url.clone()); let source = PesdePackageSource::new(index_url.clone());
source source
.refresh(project) .refresh(project)
@ -541,14 +545,16 @@ impl PublishCommand {
} }
pub fn run(self, project: Project, reqwest: reqwest::blocking::Client) -> anyhow::Result<()> { pub fn run(self, project: Project, reqwest: reqwest::blocking::Client) -> anyhow::Result<()> {
let result = self.run_impl(&project, reqwest.clone()); let result = self.clone().run_impl(&project, reqwest.clone());
if project.workspace_dir().is_some() { if project.workspace_dir().is_some() {
return result; return result;
} else if let Err(result) = result { } else if let Err(result) = result {
println!("an error occurred publishing workspace root: {result}"); println!("an error occurred publishing workspace root: {result}");
} }
run_on_workspace_members(&project, |project| self.run_impl(&project, reqwest.clone())) run_on_workspace_members(&project, |project| {
.map(|_| ()) self.clone().run_impl(&project, reqwest.clone())
})
.map(|_| ())
} }
} }