Skip to content

Commit

Permalink
add check if path exists
Browse files Browse the repository at this point in the history
  • Loading branch information
HamzaOralK committed Jun 16, 2022
1 parent b8acebd commit 4eced2d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "gitten"
version = "0.2.2"
version = "0.2.3"
edition = "2021"
authors = ["okhuz <[email protected]>"]
license = "MIT"
Expand All @@ -26,3 +26,4 @@ futures = "0.3.21"
[profile.release]
opt-level = 3
debug = true
panic = 'abort'
3 changes: 1 addition & 2 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,8 @@ pub struct App {
}

impl App {
pub fn new() -> App {
pub fn new(path: String) -> App {
let mut content = Vec::new();
let path = std::env::args().nth(1).unwrap_or_else(|| "./".to_string());

App::generate_application_content(&path, &mut content);

Expand Down
8 changes: 7 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ mod repo;
use app::App;
use run_app::run_app;
use std::{io};
use std::path::Path;
use std::time::Duration;
use crossterm::event::{DisableMouseCapture, EnableMouseCapture};
use crossterm::execute;
Expand All @@ -17,13 +18,18 @@ use tui::{backend::CrosstermBackend, Terminal};

fn main() -> Result<(), io::Error> {

let path = std::env::args().nth(1).unwrap_or_else(|| "./".to_string());
if !Path::new(&path).exists() {
panic!("Path does not exists!");
}

enable_raw_mode()?;
let mut stdout = io::stdout();
execute!(stdout, EnterAlternateScreen, EnableMouseCapture)?;
let backend = CrosstermBackend::new(stdout);
let mut terminal = Terminal::new(backend)?;

let app = App::new();
let app = App::new(path);
let _ = run_app(&mut terminal, app, Duration::from_millis(5000));

disable_raw_mode()?;
Expand Down

0 comments on commit 4eced2d

Please sign in to comment.