print config options
This commit is contained in:
parent
5078712142
commit
9681706516
2 changed files with 76 additions and 6 deletions
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
#[cfg(feature = "camera")]
|
#[cfg(feature = "camera")]
|
||||||
use camera::Webcam;
|
use camera::Webcam;
|
||||||
use clap::{ArgGroup, Parser, ValueEnum};
|
use clap::{ArgGroup, Parser, Subcommand, ValueEnum};
|
||||||
use debug::Debugger;
|
use debug::Debugger;
|
||||||
use gb_emu_lib::{
|
use gb_emu_lib::{
|
||||||
config::ConfigManager,
|
config::ConfigManager,
|
||||||
|
@ -53,10 +53,14 @@ impl From<SerialTargetOption> for SerialTarget {
|
||||||
#[derive(Parser, Debug)]
|
#[derive(Parser, Debug)]
|
||||||
#[command(author, version, about, long_about = None)]
|
#[command(author, version, about, long_about = None)]
|
||||||
#[command(group(ArgGroup::new("saves").args(["save","no_save"])))]
|
#[command(group(ArgGroup::new("saves").args(["save","no_save"])))]
|
||||||
|
#[command(subcommand_negates_reqs = true)]
|
||||||
struct Args {
|
struct Args {
|
||||||
|
#[command(subcommand)]
|
||||||
|
command: Option<Commands>,
|
||||||
|
|
||||||
/// Path to ROM
|
/// Path to ROM
|
||||||
#[arg(value_hint = clap::ValueHint::FilePath)]
|
#[arg(value_hint = clap::ValueHint::FilePath, required = true)]
|
||||||
rom: PathBuf,
|
rom: Option<PathBuf>,
|
||||||
|
|
||||||
/// Save path
|
/// Save path
|
||||||
#[arg(long, value_hint = clap::ValueHint::FilePath)]
|
#[arg(long, value_hint = clap::ValueHint::FilePath)]
|
||||||
|
@ -93,6 +97,25 @@ struct Args {
|
||||||
record: bool,
|
record: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Subcommand, Debug, Clone, Copy)]
|
||||||
|
enum Commands {
|
||||||
|
PrintConfig {
|
||||||
|
/// Which config to print
|
||||||
|
#[arg(long, value_enum, default_value_t = ConfigType::Base)]
|
||||||
|
config: ConfigType,
|
||||||
|
|
||||||
|
/// Print current config instead of default
|
||||||
|
#[arg(long)]
|
||||||
|
current: bool,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(ValueEnum, Debug, Clone, Copy)]
|
||||||
|
enum ConfigType {
|
||||||
|
Base,
|
||||||
|
Standalone,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub struct StandaloneConfig {
|
pub struct StandaloneConfig {
|
||||||
|
@ -118,6 +141,7 @@ struct Configs {
|
||||||
}
|
}
|
||||||
|
|
||||||
static CONFIGS: OnceLock<Configs> = OnceLock::new();
|
static CONFIGS: OnceLock<Configs> = OnceLock::new();
|
||||||
|
const CONFIG_NAME: &str = "standalone";
|
||||||
|
|
||||||
fn access_config<'a>() -> &'a Configs {
|
fn access_config<'a>() -> &'a Configs {
|
||||||
CONFIGS.get().expect("accessed config before it was set!")
|
CONFIGS.get().expect("accessed config before it was set!")
|
||||||
|
@ -126,10 +150,49 @@ fn access_config<'a>() -> &'a Configs {
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = Args::parse();
|
let args = Args::parse();
|
||||||
|
|
||||||
run(args);
|
if let Some(subcommand) = args.command {
|
||||||
|
match subcommand {
|
||||||
|
Commands::PrintConfig { config, current } => {
|
||||||
|
if let Some(string) = if current {
|
||||||
|
let config_manager =
|
||||||
|
ConfigManager::get().expect("Could not open config folder");
|
||||||
|
match config {
|
||||||
|
ConfigType::Base => ConfigManager::get_custom_config_string(
|
||||||
|
config_manager.load_or_create_base_config(),
|
||||||
|
)
|
||||||
|
.ok(),
|
||||||
|
ConfigType::Standalone => config_manager
|
||||||
|
.load_custom_config::<StandaloneConfig>(CONFIG_NAME)
|
||||||
|
.and_then(|v| ConfigManager::get_custom_config_string(v).ok()),
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
match config {
|
||||||
|
ConfigType::Base => ConfigManager::get_custom_config_string(
|
||||||
|
gb_emu_lib::config::Config::default(),
|
||||||
|
)
|
||||||
|
.ok(),
|
||||||
|
ConfigType::Standalone => {
|
||||||
|
ConfigManager::get_custom_config_string(StandaloneConfig::default())
|
||||||
|
.ok()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} {
|
||||||
|
println!("{string}");
|
||||||
|
} else {
|
||||||
|
println!("Error getting config string");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
run(args);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run(args: Args) -> ! {
|
fn run(args: Args) -> ! {
|
||||||
|
let rom = args
|
||||||
|
.rom
|
||||||
|
.expect("error with clap - this shouldn't be possible!");
|
||||||
|
|
||||||
let (sender, receiver) = channel::<EmulatorMessage>();
|
let (sender, receiver) = channel::<EmulatorMessage>();
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -142,9 +205,9 @@ fn run(args: Args) -> ! {
|
||||||
|
|
||||||
let config_manager = ConfigManager::get().expect("Could not open config folder");
|
let config_manager = ConfigManager::get().expect("Could not open config folder");
|
||||||
let config = config_manager.load_or_create_base_config();
|
let config = config_manager.load_or_create_base_config();
|
||||||
let standalone_config: StandaloneConfig = config_manager.load_or_create_config("standalone");
|
let standalone_config: StandaloneConfig = config_manager.load_or_create_config(CONFIG_NAME);
|
||||||
|
|
||||||
let rom_file = RomFile::Path(args.rom);
|
let rom_file = RomFile::Path(rom);
|
||||||
|
|
||||||
let (rom, camera) = rom_file
|
let (rom, camera) = rom_file
|
||||||
.load(
|
.load(
|
||||||
|
|
|
@ -73,6 +73,13 @@ impl ConfigManager {
|
||||||
Default::default(),
|
Default::default(),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_custom_config_string<C>(config: C) -> Result<String, ron::Error>
|
||||||
|
where
|
||||||
|
C: Serialize,
|
||||||
|
{
|
||||||
|
ron::ser::to_string_pretty(&config, Default::default())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
|
|
Loading…
Add table
Reference in a new issue