open instance folder
This commit is contained in:
17
src/main.rs
17
src/main.rs
@@ -1,3 +1,6 @@
|
|||||||
|
#[cfg(not(target_os = "linux"))]
|
||||||
|
compile_error!("UML only supports Linux.");
|
||||||
|
|
||||||
mod auth; // this is painful, ai helped a bit btw (i try to use ai as little as possible, but this part's just ANNOYING)
|
mod auth; // this is painful, ai helped a bit btw (i try to use ai as little as possible, but this part's just ANNOYING)
|
||||||
mod download;
|
mod download;
|
||||||
mod fabric;
|
mod fabric;
|
||||||
@@ -12,6 +15,8 @@ use launch::run;
|
|||||||
use meta::fetch_version;
|
use meta::fetch_version;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
|
use crate::util::{is_valid_name, open_path};
|
||||||
|
|
||||||
/// Untitled Minecraft Launcher
|
/// Untitled Minecraft Launcher
|
||||||
#[derive(Parser)]
|
#[derive(Parser)]
|
||||||
#[command(name = "uml")]
|
#[command(name = "uml")]
|
||||||
@@ -42,6 +47,8 @@ enum Command {
|
|||||||
#[command(subcommand)]
|
#[command(subcommand)]
|
||||||
action: InstanceCmd,
|
action: InstanceCmd,
|
||||||
},
|
},
|
||||||
|
/// Open an instance folder
|
||||||
|
Folder { name: String },
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Subcommand)]
|
#[derive(Subcommand)]
|
||||||
@@ -107,6 +114,16 @@ fn main() -> anyhow::Result<()> {
|
|||||||
|
|
||||||
let cli = Cli::parse();
|
let cli = Cli::parse();
|
||||||
match cli.command {
|
match cli.command {
|
||||||
|
Command::Folder { name } => {
|
||||||
|
if !is_valid_name(&name) {
|
||||||
|
anyhow::bail!("invalid instance name: {name:?}");
|
||||||
|
}
|
||||||
|
let dir = instances_dir.join(&name);
|
||||||
|
if !dir.exists() {
|
||||||
|
anyhow::bail!("no instance named {name}");
|
||||||
|
}
|
||||||
|
open_path(&dir)?;
|
||||||
|
}
|
||||||
Command::Instances { action } => match action {
|
Command::Instances { action } => match action {
|
||||||
InstanceCmd::New { name, version } => {
|
InstanceCmd::New { name, version } => {
|
||||||
if !meta::version_exists(&version)? {
|
if !meta::version_exists(&version)? {
|
||||||
|
|||||||
@@ -13,3 +13,7 @@ pub fn is_safe_relative_path(path: &str) -> bool {
|
|||||||
&& p.components()
|
&& p.components()
|
||||||
.all(|c| matches!(c, std::path::Component::Normal(_)))
|
.all(|c| matches!(c, std::path::Component::Normal(_)))
|
||||||
}
|
}
|
||||||
|
pub fn open_path(path: &Path) -> anyhow::Result<()> {
|
||||||
|
std::process::Command::new("xdg-open").arg(path).spawn()?;
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user