Skip to content
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

Add update project functionality #78

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion skootrs-bin/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use skootrs_model::skootrs::{
GithubRepoParams, GithubUser, GoParams, InitializedProject, MavenParams, ProjectArchiveParams,
ProjectCreateParams, ProjectGetParams, ProjectOutput, ProjectOutputGetParams,
ProjectOutputReference, ProjectOutputType, ProjectOutputsListParams, ProjectReleaseParam,
RepoCreateParams, SkootError, SourceInitializeParams, SupportedEcosystems,
ProjectUpdateParams, RepoCreateParams, SkootError, SourceInitializeParams, SupportedEcosystems,
};
use std::{
collections::{HashMap, HashSet},
Expand Down Expand Up @@ -169,6 +169,36 @@ impl Project {
})
}

/// Updates an existing initialized project to include any updated facets.
///
/// # Errors
///
/// Returns an error if the project can't be updated for some reason.
pub async fn update<'a, T: ProjectService + ?Sized>(
config: &Config,
project_service: &'a T,
project_update_params: Option<ProjectUpdateParams>,
) -> Result<InitializedProject, SkootError> {
let mut cache = InMemoryProjectReferenceCache::load_or_create("./skootcache")?;
let project_update_params = match project_update_params {
Some(p) => p,
None => Project::prompt_update(config, project_service).await?,
};
let updated_project = project_service.update(project_update_params).await?;
cache.set(updated_project.repo.full_url()).await?;
Ok(updated_project)
}

async fn prompt_update<'a, T: ProjectService + ?Sized>(
config: &Config,
project_service: &'a T,
) -> Result<ProjectUpdateParams, SkootError> {
let initialized_project = Project::get(config, project_service, None).await?;
Ok(ProjectUpdateParams {
initialized_project,
})
}

/// Returns the list of projects that are stored in the cache.
///
/// # Errors
Expand Down
19 changes: 19 additions & 0 deletions skootrs-bin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ enum ProjectCommands {
input: Option<Input>,
},

/// Update a project.
#[command(name = "update")]
Update {
/// This is an optional input parameter that can be used to pass in a file, pipe, url, or stdin.
/// This is expected to be YAML or JSON. If it is not provided, the CLI will prompt the user for the input.
#[clap(value_parser)]
input: Option<Input>,
},

/// Archive a project.
#[command(name = "archive")]
Archive {
Expand Down Expand Up @@ -270,6 +279,16 @@ async fn main() -> std::result::Result<(), SkootError> {
error!(error = error.as_ref(), "Failed to get project info");
}
}
ProjectCommands::Update { input } => {
let project_update_params = parse_optional_input(input)?;
if let Err(ref error) =
helpers::Project::update(&config, &project_service, project_update_params)
.await
.handle_response_output(stdout())
{
error!(error = error.as_ref(), "Failed to update project");
}
}
ProjectCommands::List => {
if let Err(ref error) = helpers::Project::list(&config)
.await
Expand Down
Loading