// TODO: Header use cxx_qt_lib::QString; use std::error::Error; use structopt::StructOpt; pub mod colors; pub mod filesystem; fn run_gui(root_path: std::path::PathBuf) -> Result<(), Box> { println!("Starting the GUI editor at {:?}", root_path); use cxx_qt_lib::{QGuiApplication, QQmlApplicationEngine, QUrl}; let mut app = QGuiApplication::new(); let mut engine = QQmlApplicationEngine::new(); if let Some(engine) = engine.as_mut() { engine.add_import_path(&QString::from("qml/")); } if let Some(engine) = engine.as_mut() { engine.load(&QUrl::from("qml/main.qml")); } if let Some(app) = app.as_mut() { app.exec(); } Ok(()) } fn run_tui(root_path: std::path::PathBuf) -> Result<(), Box> { println!("Starting the TUI editor at {:?}", root_path); Ok(()) } #[derive(StructOpt, Debug)] #[structopt(name = "clide")] struct Cli { /// The root path to open with the clide editor. #[structopt(parse(from_os_str))] pub path: Option, /// Run in headless mode if this flag is present. #[structopt(name = "tui", short, long)] pub tui: bool, } fn main() -> Result<(), Box> { let args = Cli::from_args(); let root_path = match args.path { // If the CLI was provided a directory convert it to absolute. Some(path) => std::path::absolute(path)?, // If no path was provided, use current directory. None => std::env::current_dir().unwrap_or_else(|_| // If we can't find the CWD attempt to open the home directory. dirs::home_dir().expect("Failed to access filesystem.")), }; // Open the TUI editor if requested, otherwise use the QML GUI by default. match args.tui { true => run_tui(root_path), false => run_gui(root_path), } }