fix: switch default profile to terminal and fixed some comments
This commit is contained in:
1 parent
971375bf1f
commit
52787b57c7
71 files changed
+671
-188
No files matched your search
@@ -1,3 +1,4 @@
|
||||
// cli handlers for account management (microsoft oauth + offline accounts)
|
||||
use std::io;
|
||||
use std::time::Duration;
|
||||
|
||||
@@ -18,6 +19,7 @@ pub async fn handle_account(matches: &ArgMatches) -> CliResult {
|
||||
}
|
||||
}
|
||||
|
||||
// trait indirection so a mock store can be swapped in for tests
|
||||
trait AccountStoreLike {
|
||||
fn accounts(&self) -> &[Account];
|
||||
fn add_account(&mut self, account: Account);
|
||||
@@ -65,6 +67,10 @@ async fn add_account(matches: &ArgMatches) -> CliResult {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// microsoft auth runs on a background thread via device code flow.
|
||||
// polls two shared slots: one for the device code to display,
|
||||
// then one for the final auth result. not the prettiest pattern
|
||||
// but it keeps the oauth complexity out of the CLI layer.
|
||||
async fn add_microsoft_account() -> CliResult {
|
||||
if let Ok(mut slot) = crate::auth::DEVICE_CODE_DISPLAY.lock() {
|
||||
*slot = None;
|
||||
@@ -72,6 +78,7 @@ async fn add_microsoft_account() -> CliResult {
|
||||
|
||||
let result_arc = crate::auth::start_microsoft_auth();
|
||||
|
||||
// wait for the device code to become available before showing it
|
||||
loop {
|
||||
if let Ok(slot) = crate::auth::DEVICE_CODE_DISPLAY.lock()
|
||||
&& let Some(info) = slot.as_ref() {
|
||||
@@ -82,6 +89,7 @@ async fn add_microsoft_account() -> CliResult {
|
||||
tokio::time::sleep(Duration::from_millis(200)).await;
|
||||
}
|
||||
|
||||
// now wait for the user to complete auth in their browser
|
||||
loop {
|
||||
if let Ok(slot) = result_arc.lock()
|
||||
&& let Some(result) = slot.as_ref() {
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
// unified content management for mods, resource packs, and shaders.
|
||||
// all three content types share the same list/enable/disable workflow,
|
||||
// just with different scanner functions plugged in.
|
||||
use std::io;
|
||||
use std::path::Path;
|
||||
|
||||
@@ -51,6 +54,7 @@ fn handle_content(matches: &ArgMatches, kind: &str, scan: Scanner) -> CliResult
|
||||
}
|
||||
}
|
||||
|
||||
// match by filename stem (no extension) so users don't have to type ".jar"
|
||||
pub(crate) fn find_entry_by_stem<'a>(
|
||||
entries: &'a [ContentEntry],
|
||||
target: &str,
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// modpack importing from modrinth (remote slug/url) or local .mrpack files.
|
||||
// resolves the input, downloads if needed, then hands off to the import engine.
|
||||
use clap::ArgMatches;
|
||||
|
||||
use crate::instance::InstanceManager;
|
||||
@@ -15,6 +17,7 @@ pub async fn handle_import(matches: &ArgMatches) -> CliResult {
|
||||
let manager = InstanceManager::new(instances_dir, meta_dir);
|
||||
let client = crate::net::HttpClient::new();
|
||||
|
||||
// figure out what the user gave us: a local file, a project slug, or a versioned URL
|
||||
let parsed = modrinth::parse_input(input);
|
||||
|
||||
let mrpack_path = match parsed {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// instance lifecycle: create, delete, rename, launch, config, desktop shortcuts.
|
||||
// the heaviest handler in the CLI since instances are the core concept.
|
||||
use std::io;
|
||||
use std::time::Duration;
|
||||
|
||||
@@ -137,6 +139,8 @@ async fn launch_instance(matches: &ArgMatches) -> CliResult {
|
||||
.await
|
||||
.map_err(|error| io::Error::other(format!("Launch failed: {}", error)))?;
|
||||
|
||||
// poll until the game process exits. in CLI mode this blocks here
|
||||
// so the user gets a proper exit code at the end.
|
||||
loop {
|
||||
match crate::running::get(name) {
|
||||
Some(RunState::Crashed(Some(code))) => {
|
||||
@@ -237,6 +241,7 @@ fn config_instance(matches: &ArgMatches) -> CliResult {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// maps --set key=value pairs to config fields. empty value = clear the field.
|
||||
fn apply_config_update(
|
||||
config: &mut crate::instance::InstanceConfig,
|
||||
key: &str,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// viewing minecraft log files from the CLI, with optional `--follow` for tailing
|
||||
use std::io;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::time::Duration;
|
||||
@@ -46,6 +47,8 @@ async fn show_log(matches: &ArgMatches) -> CliResult {
|
||||
println!("{}", line);
|
||||
}
|
||||
|
||||
// ghetto tail -f: re-read the whole file and print new lines.
|
||||
// not efficient, but log files are small and this is simple.
|
||||
if follow {
|
||||
let mut last_len = lines.len();
|
||||
loop {
|
||||
@@ -61,6 +64,7 @@ async fn show_log(matches: &ArgMatches) -> CliResult {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// if no file is specified, grab the most recent log (first from the sorted scan)
|
||||
pub(crate) fn resolve_log_path(
|
||||
instances_dir: &Path,
|
||||
instance: &str,
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// cli entry point and clap command definitions.
|
||||
// no subcommand = launch TUI, otherwise dispatch to the appropriate handler.
|
||||
mod account;
|
||||
mod content;
|
||||
mod import;
|
||||
@@ -12,7 +14,9 @@ use clap::{Arg, ArgAction, ArgGroup, Command};
|
||||
pub async fn init() {
|
||||
let matches = build_command().get_matches();
|
||||
|
||||
// no subcommand means the user just ran `mcl` bare, so fall through to TUI mode
|
||||
if matches.subcommand().is_none() {
|
||||
// force-init the theme so it's ready before the TUI renders
|
||||
let _ = &*crate::config::theme::THEME;
|
||||
if let Err(e) = crate::tui::show().await {
|
||||
tracing::error!("TUI error: {}", e);
|
||||
@@ -206,6 +210,7 @@ fn build_command() -> Command {
|
||||
)
|
||||
}
|
||||
|
||||
// mods, resource packs, and shaders all share the same list/enable/disable shape
|
||||
fn build_content_command(name: &'static str, about: &'static str) -> Command {
|
||||
Command::new(name)
|
||||
.about(format!("Manage {}", about))
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
// plain-text table rendering for CLI output. no fancy box-drawing,
|
||||
// just left-aligned columns with two-space gaps. keeps it pipeable.
|
||||
use chrono::{DateTime, Utc};
|
||||
|
||||
pub fn print_table(headers: &[&str], rows: &[Vec<String>]) {
|
||||
@@ -39,6 +41,7 @@ pub fn active_marker(active: bool) -> &'static str {
|
||||
}
|
||||
}
|
||||
|
||||
// find the widest value in each column to pad everything evenly
|
||||
fn column_widths(headers: &[&str], rows: &[Vec<String>]) -> Vec<usize> {
|
||||
let mut widths: Vec<usize> = headers.iter().map(|header| header.len()).collect();
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// shared CLI helpers: confirmation prompts, arg extraction, instance validation
|
||||
use std::io::{self, Write};
|
||||
|
||||
use clap::ArgMatches;
|
||||
@@ -17,6 +18,8 @@ pub fn required_arg<'a>(matches: &'a ArgMatches, name: &str) -> Result<&'a str,
|
||||
.ok_or_else(|| io::Error::other(format!("missing required argument '{name}'")))
|
||||
}
|
||||
|
||||
// checks for instance.json rather than just the directory, since a folder
|
||||
// without config is just a sad empty directory pretending to be an instance
|
||||
pub fn require_instance(instances_dir: &std::path::Path, name: &str) -> Result<(), io::Error> {
|
||||
if !instances_dir.join(name).join("instance.json").exists() {
|
||||
return Err(io::Error::other(format!("Instance '{name}' not found")));
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
// lists available game versions, optionally filtered by mod loader support.
|
||||
// fetches the mojang manifest and cross-references with loader APIs
|
||||
// to show only versions that actually work with a given loader.
|
||||
use std::collections::HashSet;
|
||||
use std::io;
|
||||
|
||||
@@ -27,6 +30,8 @@ async fn list_versions(matches: &ArgMatches) -> CliResult {
|
||||
.map(|value| parse_loader(value).map_err(io::Error::other))
|
||||
.transpose()?;
|
||||
|
||||
// vanilla supports everything by definition, so only fetch loader-specific
|
||||
// version lists when the user actually asked for a modded loader
|
||||
let supported = match loader {
|
||||
Some(ModLoader::Vanilla) | None => None,
|
||||
Some(loader) => Some(fetch_supported_versions(&client, loader).await?),
|
||||
|
||||
Reference in new issue
Block a user