Skip to content

Commit

Permalink
feat: add explicit flag to CLI list command (#1403)
Browse files Browse the repository at this point in the history
fixes: #1372 

feature: add cli flag for `pixi list` so users can filter only for
explicit packages using `--explicit` , additionally with `-x`.

---------

Co-authored-by: Tim de Jager <tdejager89@gmail.com>
  • Loading branch information
jjjermiah and tdejager authored May 19, 2024
1 parent 6e00256 commit 2a11546
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
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

0 comments on commit 2a11546

Please sign in to comment.