Skip to content

Commit

Permalink
src: rename session file to .atmpt-session.json
Browse files Browse the repository at this point in the history
More descriptive and the starting dot will hide it
from Unix systems for when you choose a new tmp dir.
+ put program and file name into const variables
  • Loading branch information
marcelohdez committed May 22, 2024
1 parent edf678a commit 1d252c8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@ use std::{
use anyhow::{bail, Context, Ok};
use chrono::Local;

pub const PROGRAM_NAME: &str = "atmpt";
const SESSION_FILE_NAME: &str = ".atmpt.json";

pub fn get_atmpt_dir(tmp_dir: &Option<PathBuf>) -> Cow<PathBuf> {
match tmp_dir {
Some(d) => Cow::Borrowed(d),
None => Cow::Owned(env::temp_dir().join("atmpt")),
None => Cow::Owned(env::temp_dir().join(PROGRAM_NAME)),
}
}

pub fn get_session_path(tmp_dir: &Option<PathBuf>) -> PathBuf {
get_atmpt_dir(tmp_dir).join("session.json")
get_atmpt_dir(tmp_dir).join(SESSION_FILE_NAME)
}

pub fn try_template(
Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use clap::Parser;
use directories::ProjectDirs;

fn main() -> anyhow::Result<()> {
let Some(dirs) = ProjectDirs::from("me", "marcelohdez", "Atmpt") else {
let Some(dirs) = ProjectDirs::from("me", "marcelohdez", atmpt::PROGRAM_NAME) else {
bail!("Could not generate any directories for this OS!");
};

Expand Down

1 comment on commit 1d252c8

@marcelohdez
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops it's actually ".atmpt.json"

Please sign in to comment.