Logo

Programming-Idioms

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

Idiom #233 Read a command line string flag

Print the value of the flag -country passed to the program command line, or the default value "Canada" if no such flag was passed.

uses CustApp;
S := Application.GetOptionValue('country');
if S = '' then S := 'Canada';
writeln('Country = ',S);
import "flag"
var country = flag.String("country", "Canada", "user home country")
flag.Parse()
fmt.Println("country is", *country)

country has pointer type *string.
Call Parse only once, after all flags are defined and before flags are read.
Flags must be passed before the non-flag arguments.

New implementation...
< >
programming-idioms.org