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

feat: add explicit flag to CLI list command #1403

Merged
merged 4 commits into from
May 19, 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
2 changes: 2 additions & 0 deletions docs/reference/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ List project's packages. Highlighted packages are explicit dependencies.
- `--json`: Whether to output in json format.
- `--json-pretty`: Whether to output in pretty json format
- `--sort-by <SORT_BY>`: Sorting strategy [default: name] [possible values: size, name, type]
- `--explicit (-x)`: Only list the packages that are explicitly added to the [manifest file](configuration.md).
- `--manifest-path <MANIFEST_PATH>`: The path to [manifest file](configuration.md), by default it searches for one in the parent directories.
- `--environment (-e)`: The environment's packages to list, if non is provided the default environment's packages will be listed.
- `--frozen`: install the environment as defined in the lock file, doesn't update `pixi.lock` if it isn't up-to-date with [manifest file](configuration.md). It can also be controlled by the `PIXI_FROZEN` environment variable (example: `PIXI_FROZEN=true`).
Expand All @@ -360,6 +361,7 @@ List project's packages. Highlighted packages are explicit dependencies.
```shell
pixi list
pixi list --json-pretty
pixi list --explicit
pixi list --sort-by size
pixi list --platform win-64
pixi list --environment cuda
Expand Down
12 changes: 12 additions & 0 deletions src/cli/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ pub struct Args {
/// Don't install the environment for pypi solving, only update the lock-file if it can solve without installing.
#[arg(long)]
pub no_install: bool,

/// Only list packages that are explicitly defined in the project.
#[arg(short = 'x', long)]
pub explicit: bool,
}

fn serde_skip_is_editable(editable: &bool) -> bool {
Expand Down Expand Up @@ -181,6 +185,14 @@ pub async fn execute(args: Args) -> miette::Result<()> {
.collect::<Vec<_>>();
}

// Filter packages by explicit if needed
if args.explicit {
packages_to_output = packages_to_output
.into_iter()
.filter(|p| p.is_explicit)
.collect::<Vec<_>>();
}

// Sort according to the sorting strategy
match args.sort_by {
SortBy::Size => {
Expand Down
Loading