tsk-45: Root directory check #66
@@ -3,4 +3,34 @@ pub struct App {
|
|||||||
pub uri: String,
|
pub uri: String,
|
||||||
pub auth_uri: String,
|
pub auth_uri: String,
|
||||||
pub token: icarus_models::login_result::LoginResult,
|
pub token: icarus_models::login_result::LoginResult,
|
||||||
|
pub root_directory: String
|
||||||
|
}
|
||||||
|
|
||||||
|
impl App {
|
||||||
|
pub fn does_root_directory_exists(&self) -> bool {
|
||||||
|
let path = std::path::Path::new(&self.root_directory);
|
||||||
|
if path.exists() {
|
||||||
|
if path.is_dir() {
|
||||||
|
true
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pub async fn initialize_app_config() -> App {
|
||||||
|
App {
|
||||||
|
uri: icarus_envy::environment::get_icarus_base_api_url()
|
||||||
|
.await
|
||||||
|
.value,
|
||||||
|
auth_uri: icarus_envy::environment::get_icarus_auth_base_api_url()
|
||||||
|
.await
|
||||||
|
.value,
|
||||||
|
root_directory: icarus_envy::environment::get_root_directory().await.value,
|
||||||
|
..Default::default()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
19
src/main.rs
19
src/main.rs
@@ -11,21 +11,18 @@ pub const SECONDS_TO_SLEEP: u64 = 5;
|
|||||||
|
|
||||||
#[tokio::main]
|
#[tokio::main]
|
||||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
let mut app = config::App {
|
let mut app = config::initialize_app_config().await;
|
||||||
uri: icarus_envy::environment::get_icarus_base_api_url()
|
|
||||||
.await
|
|
||||||
.value,
|
|
||||||
auth_uri: icarus_envy::environment::get_icarus_auth_base_api_url()
|
|
||||||
.await
|
|
||||||
.value,
|
|
||||||
..Default::default()
|
|
||||||
};
|
|
||||||
println!("Base URL: {:?}", app.uri);
|
println!("Base URL: {:?}", app.uri);
|
||||||
println!("Auth URL: {:?}", app.auth_uri);
|
println!("Auth URL: {:?}", app.auth_uri);
|
||||||
|
|
||||||
match auth::get_token(&app).await {
|
if !app.does_root_directory_exists() {
|
||||||
|
eprintln!("Root directory does not exist");
|
||||||
|
std::process::exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
app.token = match auth::get_token(&app).await {
|
||||||
Ok(login_result) => {
|
Ok(login_result) => {
|
||||||
app.token = login_result;
|
login_result
|
||||||
}
|
}
|
||||||
Err(err) => {
|
Err(err) => {
|
||||||
eprintln!("Error: {err:?}");
|
eprintln!("Error: {err:?}");
|
||||||
|
|||||||
Reference in New Issue
Block a user