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 project args to phylum project status #1302

Merged
merged 1 commit into from
Nov 27, 2023
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
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