1 file changed
+21
-2
smbpndk-cli/src/main.rs
+21
-2
@@ -2,7 +2,11 @@ use anyhow::{anyhow, Result};
2
use clap::Parser;
3
use console::style;
4
use dotenv::dotenv;
5
-use std::{fs::OpenOptions, path::PathBuf, str::FromStr};
5
+use std::{
6
+ fs::{create_dir_all, OpenOptions},
7
+ path::PathBuf,
8
+ str::FromStr,
9
+};
10
11
use smbpndk_cli::{
12
account::process_account,
@@ -17,7 +21,22 @@ use tracing_subscriber::{filter::LevelFilter, prelude::*, EnvFilter};
21
22
fn setup_logging(level: Option<EnvFilter>) -> Result<()> {
23
// Log in the current directory
20
- let log_path = PathBuf::from("smbpndk-cli.log");
24
+ let log_path = match home::home_dir() {
25
+ Some(path) => {
26
+ create_dir_all(path.join(".smb"))?;
27
+ let log_path = [path.to_str().unwrap(), "/.smb/smbpndk-cli.log"].join("");
28
+ // Create the file if it doesn't exist
29
+ let _file = OpenOptions::new()
30
+ .create(true)
31
+ .write(true)
32
+ .open(&log_path)?;
33
+
34
+ PathBuf::from(log_path)
35
+ }
36
+ None => {
37
+ return Err(anyhow!("Could not find home directory."));
38
+ }
39
+ };
40
41
let file = OpenOptions::new()
42
.create(true)