summaryrefslogtreecommitdiff
path: root/src/bin/br/main.rs
blob: 52c53b01bb99370c250cb00ba8b213531949aca7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
#![feature(path_add_extension)]

mod asm;
mod run;
mod formats;

use switchboard::*;


fn main() {
    let mut args = Switchboard::from_env();
    args.named("help").short('h');
    args.named("version");
    args.named("verbose").short('v');

    if args.get("help").as_bool() {
        print_help();
    }
    if args.get("version").as_bool() {
        print_version();
    }
    if args.get("verbose").as_bool() {
        log::set_log_level(log::LogLevel::Info);
    }
    match args.peek() {
        Some("run") => { args.pop(); run::main(args) },
        Some("asm") => { args.pop(); asm::main(args) },
        _ => run::main(args),
    }
}


fn print_help() -> ! {
    eprintln!("\
Usage: br [source]
       br asm [source] [destination]

Integrated Bedrock assembler and emulator.

Usage:
  To load a Bedrock program from a file, run `br <path>`, where
  <path> is the path to an assembled Bedrock program.

  To load a Bedrock program from piped input, run `<command> | br`,
  where <command> is a command that generates Bedrock bytecode.

  To assemble a Bedrock program from a source file and write to an
  output file, run `br asm <source> <output>`, where <source> is the
  path of the source file and <output> is the path to write to.

  To assemble and run a Bedrock program without saving to a file,
  run `br asm <source> | br`, where <source> is the path of the
  source file.

Environment variables:
  BEDROCK_PATH
    A list of colon-separated paths which will be searched to find
    a Bedrock program when the program doesn't exist in the current
    directory. This allows the user to run frequently-used programs
    from any directory.
  BEDROCK_LIBS
    A list of colon-separated paths which 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.

Arguments:
  [program]            Path to a Bedrock program to run

Switches:
  --fullscreen     (-f)  Start the program in fullscreen mode (toggle with F11)
  --size=<dim>     (-s)  Set the initial window size in the format <width>x<height>
  --zoom=<scale>   (-z)  Set the pixel size for the screen (change with F5/F6)
  --show-cursor    (-c)  Show the operating system cursor over the window
  --palette=<pal>        Set a debug colour palette in the format <rgb>,... (toggle with F2)
  --debug,         (-d)  Show debug information while the program is running
  --decode-stdin   (-i)  Decode transmissions on standard input from text lines.
  --encode-stdout  (-o)  Encode transmissions on standard output as text lines.
  --help           (-h)  Print this help information
  --verbose,       (-v)  Print additional information
  --version              Print the program version and exit

Arguments (asm mode):
  [source]               Bedrock source code file to assemble.
  [destination]          Destination path for assembler output.

Switches (asm mode):
  --dry-run        (-n)  Assemble and show errors only, don't write any output
  --extension            File extension to identify source files (default is 'brc')
  --format=<fmt>         Output format to use for assembled program (default is 'binary')
  --no-project-libs      Don't search for libraries in the source parent folder
  --no-env-libs          Don't search for libraries in the BEDROCK_LIBS path variable
  --no-libs              Combination of --no-project-libs and --no-env-libs
  --tree                 Display a tree visualisation of all included library files
  --with-symbols         Also generate debug symbols file with extension '.sym'
  --help           (-h)  Print this help information
  --verbose,       (-v)  Print additional information
  --version              Print the program version and exit
");
    std::process::exit(0);
}


fn print_version() -> ! {
    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);
}