Permalink
Browse files

Adding help and version command line options.

  • Loading branch information...
1 parent 3e945d8 commit 1f86e43cebab9661d22cda311d5a2ff405056913 @chazomaticus committed Apr 15, 2012
Showing with 43 additions and 15 deletions.
  1. +35 −12 src/bomns3_base.vala
  2. +4 −0 src/common.vala
  3. +4 −3 src/sdl_bomns3.vala
View
@@ -109,7 +109,11 @@ namespace Bomns3 {
ArrayList<string> unused_args = new ArrayList<string>();
for(int i = 1; i < _args.length; ++i) {
- if(_args[i] == "--font")
+ if(_args[i] == "--help" || _args[i] == "-h")
+ _options.print_help = true;
+ else if(_args[i] == "--version")
+ _options.print_version = true;
+ else if(_args[i] == "--font")
_options.font_filename = _args[++i];
else if(_args[i] == "--show-fps")
_options.show_fps = true;
@@ -122,29 +126,48 @@ namespace Bomns3 {
return unused_args.to_array();
}
- protected virtual void help(FileStream o) {
- o.printf("%s - an old-school arcade-style tile-based bomb-dropping deathmatch jam\n", NAME);
- o.printf("Version: %s\n", VERSION);
- o.printf("Usage: %s [options]\n", _args[0]);
- o.printf("Options:\n");
- o.printf(" --font FILENAME Uses FILENAME (must be a TTF file) to render text inside\n");
- o.printf(" the game (default:\n");
- o.printf(" %s)\n", Options.DEFAULT_FONT_FILENAME);
- o.printf(" --show-fps Shows a frames-per-second counter\n");
+ protected virtual void version() {
+ stdout.printf("%s %s\n", NAME, VERSION);
+ }
+
+ protected virtual void help() {
+ stdout.printf("%s - an old-school arcade-style tile-based bomb-dropping deathmatch jam\n", NAME);
+ stdout.printf("Version: %s\n", VERSION);
+ stdout.printf("Usage: %s [options]\n", _args[0]);
+ stdout.printf("Options:\n");
+ stdout.printf(" --help, -h Prints this help and exits.\n");
+ stdout.printf(" --version Prints version information and exits.\n");
+ stdout.printf(" --font FILENAME Uses FILENAME (must be a TTF file) to render in-game text\n");
+ stdout.printf(" (default:\n");
+ stdout.printf(" %s)\n", Options.DEFAULT_FONT_FILENAME);
+ stdout.printf(" --show-fps Shows an in-game frames-per-second counter\n");
}
protected virtual void unknown_arg(string arg) {
stderr.printf("Unknown argument: %s\n", arg);
- help(stderr);
+ stderr.printf("Run '%s --help' for help.\n", _args[0]);
}
// Must be called from run().
- protected virtual bool init() {
+ protected virtual bool init(out int rc) {
+ rc = 0;
+
string[] unused_args = process_args();
if(unused_args.length > 0) {
unknown_arg(unused_args[0]);
+ rc = 1;
return false;
}
+
+ if(_options.print_help) {
+ help();
+ return false;
+ }
+ if(_options.print_version) {
+ version();
+ return false;
+ }
+
return true;
}
View
@@ -91,11 +91,15 @@ namespace Bomns3 {
// be a class that can be extended.
public static const string DEFAULT_FONT_FILENAME = "/usr/share/fonts/truetype/ttf-dejavu/DejaVuSansMono.ttf";
+ public bool print_help;
+ public bool print_version;
public string font_filename;
public bool show_fps;
public KeyConfig[] key_configs;
public Options() {
+ print_help = false;
+ print_version = false;
font_filename = DEFAULT_FONT_FILENAME;
show_fps = false;
key_configs = new KeyConfig[2];
View
@@ -43,8 +43,9 @@ namespace Bomns3 {
}
public override int run() {
- if(!init())
- return 1;
+ int rc;
+ if(!init(out rc))
+ return rc;
_input_handler = new Input.Sdl.InputHandler();
init_subsystems(new Render.Sdl.RenderProvider(), _input_handler);
@@ -68,7 +69,7 @@ namespace Bomns3 {
run_frame();
}
close();
- return 0;
+ return rc;
}
protected virtual void process_events() {

0 comments on commit 1f86e43

Please sign in to comment.