summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs32
1 files changed, 23 insertions, 9 deletions
diff --git a/src/lib.rs b/src/lib.rs
index d45d449..3f7bf59 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -20,7 +20,26 @@ pub const WIDE_MODE: u8 = 0x40;
pub const IMMEDIATE_MODE: u8 = 0x20;
-pub fn assemble(mut args: Switchboard, invocation: &str) {
+pub fn assemble(mut args: Switchboard, invocation: &str) -> ! {
+ args.named("help").short('h');
+ args.named("version");
+ args.named("verbose").short('v');
+
+ if args.get("help").as_bool() {
+ print_help(invocation);
+ std::process::exit(0);
+ }
+ if args.get("version").as_bool() {
+ let name = env!("CARGO_PKG_NAME");
+ let version = env!("CARGO_PKG_VERSION");
+ eprintln!("{name} v{version}");
+ eprintln!("Written by Ben Bridle.");
+ std::process::exit(0);
+ }
+ if args.get("verbose").as_bool() {
+ log::set_log_level(log::LogLevel::Info);
+ }
+
args.positional("source");
args.positional("destination");
args.named("extension").default("brc");
@@ -34,14 +53,8 @@ pub fn assemble(mut args: Switchboard, invocation: &str) {
args.named("dry-run").short('n');
args.named("tree");
args.named("with-symbols");
- args.named("help").short('h');
args.raise_errors();
- if args.get("help").as_bool() {
- print_help(invocation);
- std::process::exit(0);
- }
-
let source_path = args.get("source").as_path_opt().map(
|p| p.canonicalize().unwrap_or_else(|e| fatal!("{p:?}: {e:?}")));
let destination_path = args.get("destination").as_path_opt();
@@ -169,6 +182,7 @@ pub fn assemble(mut args: Switchboard, invocation: &str) {
};
write_bytes_and_exit(&bytes, destination_path.as_ref());
}
+ std::process::exit(0);
}
@@ -191,7 +205,7 @@ fn print_help(invocation: &str) {
eprintln!("\
Usage: {invocation} [source] [destination]
-Convert Bedrock source code into an assembled Bedrock program.
+Assembler for the Bedrock computer system.
Usage:
To assemble a Bedrock program from a source file and write to an output
@@ -204,7 +218,7 @@ Usage:
Environment variables:
BEDROCK_LIBS
- A list of colon-separated paths which will be searched to find Bedrock
+ A list of colon-separated paths that will be searched to find Bedrock
source code files to use as libraries when assembling a Bedrock program.
If a library file resolves an unresolved symbol in the program being
assembled, the library file will be merged into the program.