2025-03-29 16:55:26 -04:00
|
|
|
// TODO: Header
|
2025-03-29 08:01:13 -04:00
|
|
|
|
2025-04-13 09:35:55 -04:00
|
|
|
use std::error::Error;
|
2025-04-13 11:58:28 -04:00
|
|
|
use std::process::{Command, Stdio};
|
2025-04-13 10:20:43 -04:00
|
|
|
use structopt::StructOpt;
|
2025-03-30 11:20:21 -04:00
|
|
|
|
2025-04-13 12:15:31 -04:00
|
|
|
pub mod gui;
|
2025-04-13 12:17:11 -04:00
|
|
|
pub mod tui;
|
2025-04-13 09:35:55 -04:00
|
|
|
|
2025-04-13 11:58:28 -04:00
|
|
|
/// Command line interface IDE with full GUI and headless modes.
|
|
|
|
|
/// If no flags are provided the GUI editor is launched in a separate process.
|
|
|
|
|
/// If no path is provided the current directory is used.
|
2025-04-13 10:20:43 -04:00
|
|
|
#[derive(StructOpt, Debug)]
|
2025-04-13 11:58:28 -04:00
|
|
|
#[structopt(name = "clide", verbatim_doc_comment)]
|
2025-04-13 10:20:43 -04:00
|
|
|
struct Cli {
|
2025-04-13 11:58:28 -04:00
|
|
|
/// The root directory for the project to open with the clide editor.
|
2025-04-13 10:20:43 -04:00
|
|
|
#[structopt(parse(from_os_str))]
|
|
|
|
|
pub path: Option<std::path::PathBuf>,
|
|
|
|
|
|
2025-04-13 11:58:28 -04:00
|
|
|
/// Run clide in headless mode.
|
2025-04-13 10:20:43 -04:00
|
|
|
#[structopt(name = "tui", short, long)]
|
|
|
|
|
pub tui: bool,
|
2025-04-13 11:58:28 -04:00
|
|
|
|
|
|
|
|
/// Run the clide GUI in the current process, blocking the terminal and showing all output streams.
|
|
|
|
|
#[structopt(name = "gui", short, long)]
|
|
|
|
|
pub gui: bool,
|
2025-04-13 09:35:55 -04:00
|
|
|
}
|
|
|
|
|
|
2025-04-13 10:20:43 -04:00
|
|
|
fn main() -> Result<(), Box<dyn Error>> {
|
|
|
|
|
let args = Cli::from_args();
|
2025-04-13 09:35:55 -04:00
|
|
|
|
2025-04-13 11:01:37 -04:00
|
|
|
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.")),
|
|
|
|
|
};
|
2025-04-13 09:35:55 -04:00
|
|
|
|
2025-04-13 11:58:28 -04:00
|
|
|
match args.gui {
|
2025-04-13 12:15:31 -04:00
|
|
|
true => gui::run(root_path),
|
2025-04-13 12:09:18 -04:00
|
|
|
false => match args.tui {
|
2025-04-13 11:58:28 -04:00
|
|
|
// Open the TUI editor if requested, otherwise use the QML GUI by default.
|
2025-04-13 12:17:11 -04:00
|
|
|
true => tui::run(root_path),
|
2025-04-13 12:09:18 -04:00
|
|
|
false => {
|
|
|
|
|
// Relaunch the CLIDE GUI in a separate process.
|
|
|
|
|
Command::new(std::env::current_exe()?)
|
2025-04-13 13:47:12 -04:00
|
|
|
.args(&["--gui", root_path.to_str().unwrap()])
|
2025-04-13 12:09:18 -04:00
|
|
|
.stdout(Stdio::null())
|
|
|
|
|
.stderr(Stdio::null())
|
|
|
|
|
.stdin(Stdio::null())
|
|
|
|
|
.spawn()?;
|
|
|
|
|
Ok(())
|
2025-04-13 11:58:28 -04:00
|
|
|
}
|
2025-04-13 12:09:18 -04:00
|
|
|
},
|
2025-04-13 09:35:55 -04:00
|
|
|
}
|
2025-03-29 08:01:13 -04:00
|
|
|
}
|