Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Commit

Permalink
put generated files in .generated
Browse files Browse the repository at this point in the history
  • Loading branch information
hugodutka committed Oct 28, 2020
1 parent 53612df commit 5b7521a
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 deletions.
5 changes: 2 additions & 3 deletions src/action/close.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
use super::Action;
use crate::cmd::close::CloseCmd;
use crate::core::dir::get_app_dir;
use crate::core::dir::get_project_dir;
use crate::core::shell::run_command;
use anyhow::Result;
use std::process::Command;

impl Action for CloseCmd {
fn run(&self) -> Result<()> {
let hocus_dir = get_app_dir()?;
let project_dir = hocus_dir.join(&self.name);
let project_dir = get_project_dir(&self.name)?;

println!("Shutting down the Docker environment...");
run_command(
Expand Down
14 changes: 10 additions & 4 deletions src/action/get.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use super::Action;
use crate::cmd::get::GetCmd;
use crate::core::dir::get_app_dir;
use crate::core::dir::{get_app_dir, get_generated_dir, get_project_dir};
use crate::core::shell::run_command;
use anyhow::Result;
use anyhow::{Context, Result};
use std::fs;
use std::process::Command;

impl Action for GetCmd {
Expand All @@ -17,9 +18,14 @@ impl Action for GetCmd {
.arg(&self.name),
)?;

let project_dir = get_project_dir(&self.name)?;

fs::create_dir_all(get_generated_dir(&project_dir))
.context("failed to create the generated directory")?;

println!(
"The environment is now available in {}",
app_dir.join(&self.name).display()
"\nYou can now open the environment with:\n$ hocus open {}\n",
&self.name
);

Ok(())
Expand Down
12 changes: 6 additions & 6 deletions src/action/open.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use super::Action;
use crate::cmd::open::OpenCmd;
use crate::core::config::ProjectConfig;
use crate::core::dir::get_app_dir;
use crate::core::dir::{get_generated_dir, get_project_dir};
use crate::core::shell::{code_command, run_command};
use crate::core::state::ProjectState;
use anyhow::Result;
Expand All @@ -10,8 +10,8 @@ use std::process::Command;

impl Action for OpenCmd {
fn run(&self) -> Result<()> {
let hocus_dir = get_app_dir()?;
let project_dir = hocus_dir.join(&self.name);
let project_dir = get_project_dir(&self.name)?;
let generated_dir = get_generated_dir(&project_dir);

let project_config = ProjectConfig::open(&project_dir)?;

Expand All @@ -32,10 +32,10 @@ impl Action for OpenCmd {
service = project_config.mount_service
);

let mut project_state = ProjectState::open(&project_dir)?;
let mut project_state = ProjectState::open(&generated_dir)?;
if !project_state.is_init {
println!("Creating the .env file using template.env...");
fs::copy(project_dir.join("template.env"), project_dir.join(".env"))?;
fs::copy(project_dir.join("template.env"), generated_dir.join(".env"))?;

println!("Running the init.sh script...");
run_command(
Expand All @@ -53,7 +53,7 @@ impl Action for OpenCmd {
)),
)?;
project_state.is_init = true;
project_state.save(&project_dir)?;
project_state.save(&generated_dir)?;
}

println!("Opening the project in VSCode...");
Expand Down
12 changes: 11 additions & 1 deletion src/core/dir.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,19 @@
use anyhow::{anyhow, Result};
use std::path::PathBuf;
use std::path::{Path, PathBuf};

const HOCUS_DIR_NAME: &str = ".hocus";
const GENERATED_DIR_NAME: &str = ".generated";

pub fn get_app_dir() -> Result<PathBuf> {
let dir = dirs::home_dir().ok_or(anyhow!("failed to get the path to the home directory"))?;
Ok(dir.join(HOCUS_DIR_NAME))
}

pub fn get_project_dir(project_name: &str) -> Result<PathBuf> {
let hocus_dir = get_app_dir()?;
Ok(hocus_dir.join(project_name))
}

pub fn get_generated_dir(project_dir: &Path) -> PathBuf {
project_dir.join(GENERATED_DIR_NAME)
}

0 comments on commit 5b7521a

Please sign in to comment.