-
Notifications
You must be signed in to change notification settings - Fork 283
feat(cargo-shuttle): maintain project id when deleting/creating project #2098
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 3 commits
bf2d2e8
666af3d
2723b17
1ca0a06
b42e609
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -300,7 +300,7 @@ impl Shuttle { | |
| } => self.delete_certificate(domain, yes).await, | ||
| }, | ||
| Command::Project(cmd) => match cmd { | ||
| ProjectCommand::Create => self.project_create(args.project_args.name).await, | ||
| ProjectCommand::Create => self.project_create(&args.project_args).await, | ||
| ProjectCommand::Update(cmd) => match cmd { | ||
| ProjectUpdateCommand::Name { new_name } => self.project_rename(new_name).await, | ||
| }, | ||
|
|
@@ -1929,24 +1929,31 @@ impl Shuttle { | |
| Ok(()) | ||
| } | ||
|
|
||
| async fn project_create(&self, name: Option<String>) -> Result<()> { | ||
| let Some(ref name) = name else { | ||
| async fn project_create(&mut self, project_args: &ProjectArgs) -> Result<()> { | ||
| let Some(ref name) = project_args.name else { | ||
| bail!("Provide a project name with '--name <name>'"); | ||
| }; | ||
|
|
||
| self.ctx.load_local_internal_config(project_args)?; | ||
|
|
||
| let client = self.client.as_ref().unwrap(); | ||
| let r = client.create_project(name).await?; | ||
| let (proj, raw_json) = client.create_project(name).await?.into_parts(); | ||
|
|
||
| match self.output_mode { | ||
| OutputMode::Normal => { | ||
| let project = r.into_inner(); | ||
| println!("Created project '{}' with id {}", project.name, project.id); | ||
| println!("Created project '{}' with id {}", proj.name, proj.id); | ||
| } | ||
| OutputMode::Json => { | ||
| println!("{}", r.raw_json); | ||
| println!("{}", raw_json); | ||
| } | ||
| } | ||
|
|
||
| // Update the local internal config file if we are in a Rust project | ||
| if project_args.workspace_path().is_ok() { | ||
| self.ctx.set_project_id(proj.id); | ||
| self.ctx.save_local_internal()?; | ||
| } | ||
|
|
||
| Ok(()) | ||
| } | ||
|
|
||
|
|
@@ -2028,7 +2035,7 @@ impl Shuttle { | |
| Ok(()) | ||
| } | ||
|
|
||
| async fn project_delete(&self, no_confirm: bool) -> Result<()> { | ||
| async fn project_delete(&mut self, no_confirm: bool) -> Result<()> { | ||
| let client = self.client.as_ref().unwrap(); | ||
| let pid = self.ctx.project_id(); | ||
|
|
||
|
|
@@ -2064,6 +2071,12 @@ impl Shuttle { | |
|
|
||
| let res = client.delete_project(pid).await?.into_inner(); | ||
|
|
||
| // todo | ||
| // if --id is provided, then we don't want to clear the id in the config file | ||
| // also should only happen if the file exists | ||
| self.ctx.remove_project_id(); | ||
| self.ctx.save_local_internal()?; | ||
|
||
|
|
||
| println!("{res}"); | ||
|
|
||
| Ok(()) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it's better to modify the
idfield in place instead of replacing the config (in case more fields are added). Same is true forset_project_id