forked from adl-lang/adl
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
512ec6b
commit db5f48a
Showing
2 changed files
with
50 additions
and
1 deletion.
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
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,35 @@ | ||
use std::fs; | ||
use std::path::{Path, PathBuf}; | ||
use std::env; | ||
|
||
pub(crate) fn workspace(opts: &super::GenOpts) -> Result<(), anyhow::Error> { | ||
let pkg_defs = collect_work_and_pkg(&opts.dir); | ||
println!("{:?}", pkg_defs); | ||
Ok(()) | ||
} | ||
|
||
const ADL_PKG_FILES: &[(&str, PkgDef)] = &[("adl.pkg.json", PkgDef::Pkg), ("adl.work.json", PkgDef::Work)]; | ||
|
||
#[derive(Debug, Copy, Clone, PartialEq)] | ||
enum PkgDef { | ||
Pkg, | ||
Work, | ||
} | ||
|
||
fn collect_work_and_pkg(start_dir: &String) -> Vec<(PkgDef,PathBuf)> { | ||
let mut res = vec![]; | ||
let mut current_dir = PathBuf::from(start_dir); | ||
|
||
loop { | ||
for f in ADL_PKG_FILES { | ||
let file_path = current_dir.join(f.0); | ||
if file_path.exists() { | ||
res.push((f.1, current_dir.clone())); | ||
} | ||
} | ||
if !current_dir.pop() { | ||
break; | ||
} | ||
} | ||
res | ||
} |