From 9bc80a43db0038db671aee12730a57bddf3ace03 Mon Sep 17 00:00:00 2001 From: daimond113 <72147841+daimond113@users.noreply.github.com> Date: Mon, 4 Nov 2024 14:53:59 +0100 Subject: [PATCH] refactor: allow specifying different index when publishing --- docs/src/content/docs/reference/cli.mdx | 1 + src/cli/commands/publish.rs | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/docs/src/content/docs/reference/cli.mdx b/docs/src/content/docs/reference/cli.mdx index 48fdea3..7748cc8 100644 --- a/docs/src/content/docs/reference/cli.mdx +++ b/docs/src/content/docs/reference/cli.mdx @@ -108,6 +108,7 @@ Publishes the current project to the pesde registry. tarball containing the package that would be published, but will not actually publish it. - `-y, --yes`: Whether to skip the confirmation prompt. +- `-i, --index`: Name of the index to publish to. Defaults to `default`. ## `pesde self-install` diff --git a/src/cli/commands/publish.rs b/src/cli/commands/publish.rs index 840ffc1..49d5fbc 100644 --- a/src/cli/commands/publish.rs +++ b/src/cli/commands/publish.rs @@ -26,7 +26,7 @@ use pesde::{ Project, DEFAULT_INDEX_NAME, MANIFEST_FILE_NAME, }; -#[derive(Debug, Args, Copy, Clone)] +#[derive(Debug, Args, Clone)] pub struct PublishCommand { /// Whether to output a tarball instead of publishing #[arg(short, long)] @@ -35,6 +35,10 @@ pub struct PublishCommand { /// Agree to all prompts #[arg(short, long)] yes: bool, + + /// The index to publish to + #[arg(short, long, default_value_t = DEFAULT_INDEX_NAME.to_string())] + index: String, } impl PublishCommand { @@ -460,8 +464,8 @@ impl PublishCommand { let index_url = manifest .indices - .get(DEFAULT_INDEX_NAME) - .context("missing default index")?; + .get(&self.index) + .context(format!("missing index {}", self.index))?; let source = PesdePackageSource::new(index_url.clone()); source .refresh(project) @@ -541,14 +545,16 @@ impl PublishCommand { } 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() { return result; } else if let Err(result) = result { println!("an error occurred publishing workspace root: {result}"); } - run_on_workspace_members(&project, |project| self.run_impl(&project, reqwest.clone())) - .map(|_| ()) + run_on_workspace_members(&project, |project| { + self.clone().run_impl(&project, reqwest.clone()) + }) + .map(|_| ()) } }