Skip to content

Commit

Permalink
Add project args to phylum project status (#1302)
Browse files Browse the repository at this point in the history
Closes #1300.
  • Loading branch information
cd-work authored Nov 27, 2023
1 parent 75c4619 commit 69f3df9
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Show project ID after project creation
- `skip-sandbox` option for `parse`/`analyze` to generate lockfiles without sandbox protection
- `no-generation` option for `parse`/`analyze` to disable lockfile generation
- Optional `--project` and `--group` arguments for `phylum project status`

### Fixed

Expand Down
11 changes: 11 additions & 0 deletions cli/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@ pub fn add_subcommands(command: Command) -> Command {
.short('j')
.long("json")
.help("Produce output in json format (default: false)"),
Arg::new("project")
.short('p')
.long("project")
.value_name("PROJECT_NAME")
.help("Specify a project to use for analysis"),
Arg::new("group")
.short('g')
.long("group")
.value_name("GROUP_NAME")
.help("Specify a group to use for analysis")
.requires("project"),
]),
)
.subcommand(
Expand Down
40 changes: 25 additions & 15 deletions cli/src/commands/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,25 +101,35 @@ pub async fn handle_project(
Ok(ExitCode::Ok)
}

/// Print current project information.
/// Print project information.
pub async fn status(api: &PhylumApi, matches: &ArgMatches) -> StdResult<(), PhylumApiError> {
let pretty_print = !matches.get_flag("json");

let project_config = match phylum_project::get_current_project() {
Some(project_config) => project_config,
None => {
if pretty_print {
print_user_success!("No project set");
} else {
println!("{{}}");
}

return Ok(());
let project = matches.get_one::<String>("project");
let group = matches.get_one::<String>("group");

let (project_id, group_name) = match project {
// If project is passed on CLI, lookup its ID.
Some(project) => {
let group = group.cloned();
let project_id = lookup_project(api, project, group.as_deref()).await?;
(project_id, group)
},
// If no project is passed, use `.phylum_project`.
None => match phylum_project::get_current_project() {
Some(project_config) => (project_config.id, project_config.group_name),
None => {
if pretty_print {
print_user_success!("No project set");
} else {
println!("{{}}");
}

return Ok(());
},
},
};
let project = api
.get_project(&project_config.id.to_string(), project_config.group_name.as_deref())
.await?;

let project = api.get_project(&project_id.to_string(), group_name.as_deref()).await?;

project.write_stdout(pretty_print);

Expand Down
6 changes: 6 additions & 0 deletions docs/commands/phylum_project_status.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ Usage: phylum project status [OPTIONS]
`-j`, `--json`
&emsp; Produce output in json format (default: false)

`-p`, `--project` `<PROJECT_NAME>`
&emsp; Specify a project to use for analysis

`-g`, `--group` `<GROUP_NAME>`
&emsp; Specify a group to use for analysis

`-v`, `--verbose`...
&emsp; Increase the level of verbosity (the maximum is -vvv)

Expand Down

0 comments on commit 69f3df9

Please sign in to comment.