59 lines
2.0 KiB
Rust
59 lines
2.0 KiB
Rust
// TODO: Header
|
|
|
|
use std::error::Error;
|
|
use std::process::{Command, Stdio};
|
|
use structopt::StructOpt;
|
|
|
|
pub mod gui;
|
|
pub mod tui;
|
|
|
|
/// 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.
|
|
#[derive(StructOpt, Debug)]
|
|
#[structopt(name = "clide", verbatim_doc_comment)]
|
|
struct Cli {
|
|
/// The root directory for the project to open with the clide editor.
|
|
#[structopt(parse(from_os_str))]
|
|
pub path: Option<std::path::PathBuf>,
|
|
|
|
/// Run clide in headless mode.
|
|
#[structopt(name = "tui", short, long)]
|
|
pub tui: bool,
|
|
|
|
/// Run the clide GUI in the current process, blocking the terminal and showing all output streams.
|
|
#[structopt(name = "gui", short, long)]
|
|
pub gui: bool,
|
|
}
|
|
|
|
fn main() -> Result<(), Box<dyn Error>> {
|
|
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 the 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.")),
|
|
};
|
|
|
|
match args.gui {
|
|
true => gui::run(root_path),
|
|
false => match args.tui {
|
|
// Open the TUI editor if requested, otherwise use the QML GUI by default.
|
|
true => Ok(tui::start(root_path)?),
|
|
false => {
|
|
// Relaunch the CLIDE GUI in a separate process.
|
|
Command::new(std::env::current_exe()?)
|
|
.args(&["--gui", root_path.to_str().unwrap()])
|
|
.stdout(Stdio::null())
|
|
.stderr(Stdio::null())
|
|
.stdin(Stdio::null())
|
|
.spawn()?;
|
|
Ok(())
|
|
}
|
|
},
|
|
}
|
|
}
|