@@ -10,6 +10,7 @@ use pixi_manifest::{
1010use thiserror:: Error ;
1111
1212use crate :: workspace:: Workspace ;
13+ use crate :: workspace:: WorkspaceRegistry ;
1314
1415/// Defines where the search for the workspace should start.
1516#[ derive( Debug , Clone , Default ) ]
@@ -30,6 +31,11 @@ pub enum DiscoveryStart {
3031 ///
3132 /// If no manifest is found at the given path the search will abort.
3233 ExplicitManifest ( PathBuf ) ,
34+
35+ /// Search by name in the workspace registry.
36+ ///
37+ /// If the name is not found in the registry, abort.
38+ WorkspaceRegistry ( String ) ,
3339}
3440
3541impl DiscoveryStart {
@@ -39,6 +45,14 @@ impl DiscoveryStart {
3945 DiscoveryStart :: CurrentDir => std:: env:: current_dir ( ) ,
4046 DiscoveryStart :: SearchRoot ( path) => Ok ( path. clone ( ) ) ,
4147 DiscoveryStart :: ExplicitManifest ( path) => Ok ( path. clone ( ) ) ,
48+ DiscoveryStart :: WorkspaceRegistry ( name) => {
49+ let registry = WorkspaceRegistry :: load ( )
50+ . map_err ( |_| WorkspaceLocatorError :: MissingRegistry ( ) ) ?;
51+ let path = registry
52+ . named_workspace ( name)
53+ . map_err ( |_| WorkspaceLocatorError :: MissingWorkspace ( name. clone ( ) ) ) ?;
54+ Ok ( path)
55+ }
4256 }
4357 }
4458}
@@ -97,6 +111,19 @@ pub enum WorkspaceLocatorError {
97111 #[ error( transparent) ]
98112 #[ diagnostic( transparent) ]
99113 ExplicitManifestError ( #[ from] ExplicitManifestError ) ,
114+
115+ #[ error( "unable to load the workspace registry" ) ]
116+ MissingRegistry ( ) ,
117+
118+ #[ error( "could not find workspace '{}'" , . 0 ) ]
119+ MissingWorkspace ( String ) ,
120+ }
121+
122+ impl From < WorkspaceLocatorError > for std:: io:: Error {
123+ fn from ( err : WorkspaceLocatorError ) -> Self {
124+ // Create a new std::io::Error, using Other kind and the source error
125+ std:: io:: Error :: other ( err)
126+ }
100127}
101128
102129impl WorkspaceLocator {
@@ -160,6 +187,14 @@ impl WorkspaceLocator {
160187 std:: env:: current_dir ( ) . map_err ( WorkspaceLocatorError :: CurrentDir ) ?,
161188 ) ,
162189 DiscoveryStart :: SearchRoot ( path) => pixi_manifest:: DiscoveryStart :: SearchRoot ( path) ,
190+ DiscoveryStart :: WorkspaceRegistry ( name) => {
191+ let registry = WorkspaceRegistry :: load ( )
192+ . map_err ( |_| WorkspaceLocatorError :: MissingRegistry ( ) ) ?;
193+ let path = registry
194+ . named_workspace ( & name)
195+ . map_err ( |_| WorkspaceLocatorError :: MissingWorkspace ( name. clone ( ) ) ) ?;
196+ pixi_manifest:: DiscoveryStart :: ExplicitManifest ( path)
197+ }
163198 } ;
164199
165200 let discovery_source = discovery_start. root ( ) . to_path_buf ( ) ;
0 commit comments