-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR adds an environment registry and `flox envs` command. Flox commands has so far been mostly stateless, i.e. the fact that an environment exists at a given path is "forgotten" as soon as the command completes. `flox envs` is supposed to list both active and _available/inactive_ environments (that are represented by .flox directories). To avoid _scanning_ for `.flox` directories, we use the env registry introduced in #1312. In addition, the `flox envs` supports filtering the output to only active environments as well as formatting its output as JSON.
- Loading branch information
Showing
17 changed files
with
361 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use std::path::{Path, PathBuf}; | ||
|
||
use serde::Serialize; | ||
use thiserror::Error; | ||
|
||
/// A path that is guaranteed to be canonicalized | ||
/// | ||
/// [`ManagedEnvironment`] uses this to refer to the path of its `.flox` directory. | ||
/// [`ManagedEnvironment::encode`] is used to uniquely identify the environment | ||
/// by encoding the canonicalized path. | ||
/// This encoding is used to create a unique branch name in the floxmeta repository. | ||
/// Thus, rather than canonicalizing the path every time we need to encode it, | ||
/// we store the path as a [`CanonicalPath`]. | ||
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, derive_more::Deref, derive_more::AsRef)] | ||
#[deref(forward)] | ||
#[as_ref(forward)] | ||
pub struct CanonicalPath(PathBuf); | ||
|
||
#[derive(Debug, Error)] | ||
#[error("couldn't canonicalize path {path:?}: {err}")] | ||
pub struct CanonicalizeError { | ||
pub path: PathBuf, | ||
#[source] | ||
pub err: std::io::Error, | ||
} | ||
|
||
impl CanonicalPath { | ||
pub fn new(path: impl AsRef<Path>) -> Result<Self, CanonicalizeError> { | ||
let canonicalized = std::fs::canonicalize(&path).map_err(|e| CanonicalizeError { | ||
path: path.as_ref().to_path_buf(), | ||
err: e, | ||
})?; | ||
Ok(Self(canonicalized)) | ||
} | ||
|
||
pub fn into_path_buf(self) -> PathBuf { | ||
self.0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
mod canonical_path; | ||
mod version; | ||
|
||
pub use canonical_path::{CanonicalPath, CanonicalizeError}; | ||
pub use version::Version; | ||
pub type System = String; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
--- | ||
title: FLOX-ENVS | ||
section: 1 | ||
header: "Flox User Manuals" | ||
... | ||
|
||
# NAME | ||
|
||
flox-envs - show active and available environments | ||
|
||
# SYNOPSIS | ||
|
||
``` | ||
flox [<general options>] envs | ||
[--active] | ||
[--json] | ||
``` | ||
|
||
# DESCRIPTION | ||
|
||
This command can be used to list available environments on the local machine. | ||
When one or more environments are active, | ||
the last activated environment will be listed first and printed in **bold**. | ||
|
||
Whenever an environment is used with any `flox` command | ||
it is registered to a user specific global registry. | ||
`flox envs` will list all environments known to it through the registry. | ||
Environments that are present on the local system may not show up | ||
until they are used the first time. | ||
Similarly, if an environment is changed | ||
(e.g. deleted and replaced by an environment with different metadata), | ||
the change may not show until the new environment is used. | ||
|
||
# OPTIONS | ||
|
||
## Edit Options | ||
|
||
`--active` | ||
: Show only active environments | ||
|
||
`--json` | ||
: Format the output as JSON | ||
|
||
```{.include} | ||
./include/general-options.md | ||
``` | ||
|
||
# SEE ALSO | ||
[`flox-init(1)`](./flox-init.md), | ||
[`flox-pull(1)`](./flox-pull.md), | ||
[`flox-activate(1)`](./flox-activate.md) |
Oops, something went wrong.