feat(ariadne): add CLI skeleton
This commit was merged in pull request #31.
This commit is contained in:
1 parent
01f47b419d
commit
3538297991
8 files changed
+270
-17
No files matched your search
@@ -0,0 +1,51 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use clap::Parser;
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
struct Args {
|
||||
#[arg(long, default_value = "output")]
|
||||
output_dir: PathBuf,
|
||||
|
||||
#[arg(long)]
|
||||
force: bool,
|
||||
|
||||
#[arg(default_value = "all", value_parser = parse_stage)]
|
||||
target_stage: ariadne::pipeline::Stage,
|
||||
}
|
||||
|
||||
impl From<Args> for ariadne::Config {
|
||||
fn from(args: Args) -> Self {
|
||||
ariadne::Config {
|
||||
output_dir: resolve_workspace_path(args.output_dir),
|
||||
force: args.force,
|
||||
target_stage: args.target_stage,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_stage(value: &str) -> Result<ariadne::pipeline::Stage, String> {
|
||||
ariadne::pipeline::Stage::ALL
|
||||
.iter()
|
||||
.copied()
|
||||
.find(|stage| stage.name() == value)
|
||||
.ok_or_else(|| format!("unknown stage: {value}"))
|
||||
}
|
||||
|
||||
// TODO: Move this into a shared Rust utility crate.
|
||||
fn resolve_workspace_path(path: PathBuf) -> PathBuf {
|
||||
if path.is_absolute() {
|
||||
return path;
|
||||
}
|
||||
|
||||
if let Some(workspace) = std::env::var_os("BUILD_WORKSPACE_DIRECTORY") {
|
||||
return PathBuf::from(workspace).join(path);
|
||||
}
|
||||
|
||||
path
|
||||
}
|
||||
|
||||
fn main() -> ariadne::Result<()> {
|
||||
let config: ariadne::Config = Args::parse().into();
|
||||
ariadne::run(&config)
|
||||
}
|
||||
Reference in new issue
Block a user