diff options
author | Ben Bridle <ben@derelict.engineering> | 2025-03-03 20:51:01 +1300 |
---|---|---|
committer | Ben Bridle <ben@derelict.engineering> | 2025-03-03 20:54:45 +1300 |
commit | 8a43a02b6950455aedbbdbee737bee1654aa91ef (patch) | |
tree | 64e31ff1cfbbdce22e104adcb1ad81f051019ca1 /src/main.rs | |
parent | ea70fa89659e5cf1a9d4ca6ea31fb67f7a2cc633 (diff) | |
download | switchboard-8a43a02b6950455aedbbdbee737bee1654aa91ef.zip |
Implement error reporting
The library has been redesigned so that all queries can be entered
before any values are parsed. This allows all errors unrelated to value
parsing to be displayed as a batch.
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs new file mode 100644 index 0000000..0f24c2c --- /dev/null +++ b/src/main.rs @@ -0,0 +1,60 @@ +use switchboard::*; + + +fn main() { + let mut args = Switchboard::from_env(); + args.named("version"); + args.named("verbose").short('v'); + match args.peek() { + Some("run") => { args.pop(); run_program(args) } + Some("asm") => { args.pop(); assemble_program(args) } + _ => run_program(args), + } +} + +fn run_program(mut args: Switchboard) { + println!("RUN PROGRAM"); + + args.positional("source").required(); + args.named("debug").short('d'); + args.named("fullscreen").short('f'); + args.named("zoom").short('z').quick("3").default("1"); + args.raise_errors(); + + let verbose = args.get("verbose").as_bool(); + let version = args.get("version").as_bool(); + let debug = args.get("debug").as_bool(); + let fullscreen = args.get("fullscreen").as_bool(); + let zoom = args.get("zoom").as_u32(); + let source = args.get("source").as_path(); + + println!("Verbose: {verbose:?}"); + println!("Version: {version:?}"); + println!("Source path: {source:?}"); + println!("Debug: {debug:?}"); + println!("Fullscreen: {fullscreen:?}"); + println!("Zoom: {zoom:?}"); +} + +fn assemble_program(mut args: Switchboard) { + println!("ASSEMBLE PROGRAM"); + + args.positional("source"); + args.positional("destination"); + args.positional("extension").default("brc"); + args.named("no-libs"); + args.named("no-project-libs"); + args.raise_errors(); + + let source_path = args.get("source").as_path(); + let destination_path = args.get("destination").as_path(); + let extension = args.get("extension").as_string(); + let no_libs = args.get("no-libs").as_bool(); + let no_project_libs = args.get("no-project-libs").as_bool(); + + println!("Source path: {source_path:?}"); + println!("Destination path: {destination_path:?}"); + println!("Extension: {extension:?}"); + println!("No libs: {no_libs:?}"); + println!("No project libs: {no_project_libs:?}"); +} |