diff --git a/crates/omnix-cli/src/command/develop.rs b/crates/omnix-cli/src/command/develop.rs index 9145356c..27bc7985 100644 --- a/crates/omnix-cli/src/command/develop.rs +++ b/crates/omnix-cli/src/command/develop.rs @@ -1,13 +1,12 @@ -use std::path::PathBuf; - use clap::Parser; +use nix_rs::flake::url::FlakeUrl; /// Prepare to develop on a flake project #[derive(Parser, Debug)] pub struct DevelopCommand { /// Directory of the project #[arg(name = "DIR", default_value = ".")] - dir: PathBuf, + flake_shell: FlakeUrl, /// The stage to run in. If not provided, runs all stages. #[arg(long, value_enum)] @@ -26,11 +25,9 @@ enum Stage { impl DevelopCommand { pub async fn run(&self) -> anyhow::Result<()> { - tracing::info!( - "⌨️ Preparing to develop project at {:}", - self.dir.display() - ); - let prj = omnix_develop::core::Project::new(&self.dir).await?; + let flake = self.flake_shell.without_attr(); + tracing::info!("⌨️ Preparing to develop project: {:}", &flake); + let prj = omnix_develop::core::Project::new(flake).await?; match self.stage { Some(Stage::PreShell) => omnix_develop::core::develop_on_pre_shell(&prj).await?, Some(Stage::PostShell) => omnix_develop::core::develop_on_post_shell(&prj).await?, diff --git a/crates/omnix-develop/src/core.rs b/crates/omnix-develop/src/core.rs index fc36df6c..56f0f104 100644 --- a/crates/omnix-develop/src/core.rs +++ b/crates/omnix-develop/src/core.rs @@ -1,5 +1,5 @@ use anyhow::Context; -use std::path::{Path, PathBuf}; +use std::{env::current_dir, path::PathBuf}; use nix_rs::{flake::url::FlakeUrl, info::NixInfo}; use omnix_common::markdown::print_markdown; @@ -10,7 +10,7 @@ use crate::config::DevelopConfig; /// A project that an be developed on locally. pub struct Project { /// The directory of the project. - pub dir: PathBuf, + pub dir: Option, /// [FlakeUrl] corresponding to the project. pub flake: FlakeUrl, /// The develop configuration @@ -18,9 +18,11 @@ pub struct Project { } impl Project { - pub async fn new(dir: &Path) -> anyhow::Result { - let dir = dir.canonicalize()?; - let flake: FlakeUrl = Into::::into(dir.as_ref()); + pub async fn new(flake: FlakeUrl) -> anyhow::Result { + let dir = match flake.as_local_path() { + Some(path) => Some(path.canonicalize()?), + None => None, + }; let cfg = DevelopConfig::from_flake(&flake).await?; Ok(Self { dir, flake, cfg }) } @@ -85,7 +87,9 @@ pub async fn develop_on_pre_shell(prj: &Project) -> anyhow::Result<()> { pub async fn develop_on_post_shell(prj: &Project) -> anyhow::Result<()> { eprintln!(); - print_markdown(&prj.dir, prj.cfg.readme.get_markdown()).await?; + let pwd = current_dir()?; + let dir = prj.dir.as_ref().unwrap_or(&pwd); + print_markdown(dir, prj.cfg.readme.get_markdown()).await?; Ok(()) }