Skip to content

Instantly share code, notes, and snippets.

@Zalexanninev15
Created February 17, 2022 07:26
Show Gist options
  • Save Zalexanninev15/30b3cb8fad634c69ff2aa593d8014387 to your computer and use it in GitHub Desktop.
Save Zalexanninev15/30b3cb8fad634c69ff2aa593d8014387 to your computer and use it in GitHub Desktop.
Work with commands (arguments)
// Written in the D Programming Language, version 2
import std.stdio;
import std.string;
import std.conv;
import std.math;
import std.exception;
int main(string[] args)
{
bool usage;
for (int i=1; i<args.length; i++)
switch (args[i])
{
case "-h":
case "--help":
usage = true;
break;
case "-g":
case "--gamma":
// code for gamma
break;
case "--sRGB":
// code for sRGB
break;
default:
string expr = join(args[i..$], " ");
writeln(eval(expr));
return 0;
}
if (args.length == 1 || usage)
{
stderr.writeln("Usage: " ~ args[0] ~ " [OPTIONS]... EXPRESSION");
stderr.writeln("Options:");
stderr.writeln(" -h --help Display this help screen.");
stderr.writeln(" -g --gamma GAMMA Use specified gamma value (default: 2.2).");
stderr.writeln(" Specify 0 to disable gamma correction (mathematically equivalent to specifying 1).");
stderr.writeln(" --sRGB Use sRGB instead of gamma correction.");
return 2;
}
throw new Exception("No expression given.");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment