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")]
|
||||
use camera::Webcam;
|
||||
use clap::{ArgGroup, Parser, ValueEnum};
|
||||
use clap::{ArgGroup, Parser, Subcommand, ValueEnum};
|
||||
use debug::Debugger;
|
||||
use gb_emu_lib::{
|
||||
config::ConfigManager,
|
||||
|
@ -53,10 +53,14 @@ impl From<SerialTargetOption> for SerialTarget {
|
|||
#[derive(Parser, Debug)]
|
||||
#[command(author, version, about, long_about = None)]
|
||||
#[command(group(ArgGroup::new("saves").args(["save","no_save"])))]
|
||||
#[command(subcommand_negates_reqs = true)]
|
||||
struct Args {
|
||||
#[command(subcommand)]
|
||||
command: Option<Commands>,
|
||||
|
||||
/// Path to ROM
|
||||
#[arg(value_hint = clap::ValueHint::FilePath)]
|
||||
rom: PathBuf,
|
||||
#[arg(value_hint = clap::ValueHint::FilePath, required = true)]
|
||||
rom: Option<PathBuf>,
|
||||
|
||||
/// Save path
|
||||
#[arg(long, value_hint = clap::ValueHint::FilePath)]
|
||||
|
@ -93,6 +97,25 @@ struct Args {
|
|||
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)]
|
||||
#[serde(default)]
|
||||
pub struct StandaloneConfig {
|
||||
|
@ -118,6 +141,7 @@ struct Configs {
|
|||
}
|
||||
|
||||
static CONFIGS: OnceLock<Configs> = OnceLock::new();
|
||||
const CONFIG_NAME: &str = "standalone";
|
||||
|
||||
fn access_config<'a>() -> &'a Configs {
|
||||
CONFIGS.get().expect("accessed config before it was set!")
|
||||
|
@ -126,10 +150,49 @@ fn access_config<'a>() -> &'a Configs {
|
|||
fn main() {
|
||||
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) -> ! {
|
||||
let rom = args
|
||||
.rom
|
||||
.expect("error with clap - this shouldn't be possible!");
|
||||
|
||||
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 = 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
|
||||
.load(
|
||||
|
|
|
@ -73,6 +73,13 @@ impl ConfigManager {
|
|||
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)]
|
||||
|
|
Loading…
Add table
Reference in a new issue