This language bar is your friend. Select your favorite languages!

Idiom #162 Execute procedures depending on options

execute bat if b is a program option and fox if f is a program option.

import sys
if 'b' in sys.argv[1:]: bat()
if 'f' in sys.argv[1:]: fox()
import std.getopt;
void main(string[] args)
{
    void bat(){} void fox(){}
    getopt(args, "b", &bat, "f", &fox);
}
import "flag"
var b = flag.Bool("b", false, "Do bat")
var f = flag.Bool("f", false, "Do fox")

func main() {
	flag.Parse()
	if *b {
		bar()
	}
	if *f {
		fox()
	}
}
function HasOption(c: char): Boolean;
var
  i: integer;
begin
  Result := False;
  for i := 1 to ParamCount do
    if (ParamStr(i) = ('-' + c)) then Exit(True);
end;  

begin
  if HasOption('b') then Bat;
  if HasOption('f') then Fox;
end.
bat if ARGV.include?("b")
fox if ARGV.include?("f")
if let Some(arg) = ::std::env::args().nth(1) {
    if &arg == "f" {
        fox();
    } else if &arg = "b" {
        bat();
    } else {
	eprintln!("invalid argument: {}", arg),
    }
} else {
    eprintln!("missing argument");
}

Do you know the best way to do this in your language ?
New implementation...

Idiom created by

Bzzzzzzzzzz