Skip to content

Commit

Permalink
+ flake root check
Browse files Browse the repository at this point in the history
  • Loading branch information
oluceps committed Sep 15, 2024
1 parent 2c28a79 commit 779e32a
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/cmd/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::{fs, path::PathBuf};
use std::{array::TryFromSliceError, fs, path::PathBuf};

use eyre::{eyre, Context};
use spdlog::prelude::*;
use {argh::FromArgs, std::fmt::Debug};

Expand Down Expand Up @@ -70,7 +71,7 @@ impl Args {
use super::profile::Profile;

let profile: Profile = {
let file = fs::read_to_string(&self.profile)?;
let file = fs::read_to_string(&self.profile).wrap_err("arg `profile` not found")?;
toml::from_str(file.as_str())?
};

Expand All @@ -81,6 +82,20 @@ impl Args {
std::env::current_dir()?
};

// check flake root
if !fs::read_dir(&flake_root)?.into_iter().any(|e| {
e.is_ok_and(|ie| {
ie.file_name()
.into_string()
.is_ok_and(|iie| iie.as_str() == "flake.nix")
})
}) {
error!("please run app in flake root");
return Err(eyre!(
"`flake.nix` not found here, make sure run in flake toplevel."
));
};

trace!("{:#?}", profile);

match self.app {
Expand Down

0 comments on commit 779e32a

Please sign in to comment.