Skip to content

Commit

Permalink
Add update project functionality
Browse files Browse the repository at this point in the history
This will rerun facets against the project and push out any
changes.
  • Loading branch information
mlieberman85 committed Apr 12, 2024
1 parent 039a47d commit 984ffec
Show file tree
Hide file tree
Showing 5 changed files with 231 additions and 74 deletions.
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

0 comments on commit 984ffec

Please sign in to comment.