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
| program CommandParser1;
{$APPTYPE CONSOLE}
{$R *.res}
uses
System.SysUtils, CommandParser;
var
cp: TCommandParser;
begin
try
// Paramètres :
// /longnames /infile='1.txt' /outfile="2.txt"
cp := TCommandParser.Create(FALSE, 'Unit names convertor');
WriteLn(cp.SwitchChars = '/-');
cp.AddSwitch('s', stBoolean, FALSE, '', 'Conversion to short names', 'shortnames');
cp.AddSwitch('l', stBoolean, FALSE, '', 'Conversion to long names', 'longnames');
cp.AddSwitch('i', stString, TRUE, '', 'Input file', 'infile');
cp.AddSwitch('o', stString, FALSE, '', 'Output file', 'outfile');
WriteLn(cp.Syntax);
//WriteLn(cp.HelpText);
//WriteLn(cp.Description);
cp.ProcessCommandLine(CmdLine);
WriteLn(cp.IndexOf('s') = 0);
WriteLn(cp.IndexOf('l') = 1);
WriteLn(cp.IndexOf('i') = 2);
WriteLn(cp.IndexOf('o') = 3);
WriteLn(cp.Switches[3].Name = 'o');
WriteLn(cp.Switches[3].Value = '"2.txt"');
WriteLn(cp.Switches[3].HasValue);
WriteLn(cp.Switches[1].HasValue = FALSE);
cp.Free;
ReadLn;
except
on E: Exception do
Writeln(E.ClassName, ': ', E.Message);
end;
end. |
Partager