mirror of
https://gitlab.com/freepascal.org/fpc/pas2js.git
synced 2025-04-08 05:48:05 +02:00
* Node command-line demos
This commit is contained in:
parent
84b1c93a7d
commit
dddcdbb4d2
@ -40,6 +40,16 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="source">
|
||||
<div class="source-inner">
|
||||
<div>
|
||||
Created using <a target="_blank" href="https://wiki.freepascal.org/pas2js">pas2js.</a> Sources: <a target="new" href="basic.lpr">Program
|
||||
sources</a>.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
rtl.run();
|
||||
|
77
demo/rtl/demonodecmdlineoptions.lpi
Normal file
77
demo/rtl/demonodecmdlineoptions.lpi
Normal file
@ -0,0 +1,77 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<CONFIG>
|
||||
<ProjectOptions>
|
||||
<Version Value="12"/>
|
||||
<General>
|
||||
<Flags>
|
||||
<MainUnitHasCreateFormStatements Value="False"/>
|
||||
<MainUnitHasTitleStatement Value="False"/>
|
||||
<MainUnitHasScaledStatement Value="False"/>
|
||||
<Runnable Value="False"/>
|
||||
</Flags>
|
||||
<SessionStorage Value="InProjectDir"/>
|
||||
<Title Value="demonodecmdlineoptions"/>
|
||||
<UseAppBundle Value="False"/>
|
||||
<ResourceType Value="res"/>
|
||||
</General>
|
||||
<BuildModes>
|
||||
<Item Name="Default" Default="True"/>
|
||||
</BuildModes>
|
||||
<PublishOptions>
|
||||
<Version Value="2"/>
|
||||
<UseFileFilters Value="True"/>
|
||||
</PublishOptions>
|
||||
<RunParams>
|
||||
<FormatVersion Value="2"/>
|
||||
</RunParams>
|
||||
<Units>
|
||||
<Unit>
|
||||
<Filename Value="demonodecmdlineoptions.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
</Unit>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
<Version Value="11"/>
|
||||
<Target FileExt=".js">
|
||||
<Filename Value="demonodecmdlineoptions"/>
|
||||
</Target>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||
<UnitOutputDirectory Value="js"/>
|
||||
</SearchPaths>
|
||||
<Parsing>
|
||||
<SyntaxOptions>
|
||||
<AllowLabel Value="False"/>
|
||||
<CPPInline Value="False"/>
|
||||
<UseAnsiStrings Value="False"/>
|
||||
</SyntaxOptions>
|
||||
</Parsing>
|
||||
<CodeGeneration>
|
||||
<TargetOS Value="nodejs"/>
|
||||
</CodeGeneration>
|
||||
<Linking>
|
||||
<Debugging>
|
||||
<GenerateDebugInfo Value="False"/>
|
||||
<UseLineInfoUnit Value="False"/>
|
||||
</Debugging>
|
||||
</Linking>
|
||||
<Other>
|
||||
<CustomOptions Value="-Jeutf-8 -Jminclude -Jirtl.js"/>
|
||||
<CompilerPath Value="$(pas2js)"/>
|
||||
</Other>
|
||||
</CompilerOptions>
|
||||
<Debugging>
|
||||
<Exceptions>
|
||||
<Item>
|
||||
<Name Value="EAbort"/>
|
||||
</Item>
|
||||
<Item>
|
||||
<Name Value="ECodetoolError"/>
|
||||
</Item>
|
||||
<Item>
|
||||
<Name Value="EFOpenError"/>
|
||||
</Item>
|
||||
</Exceptions>
|
||||
</Debugging>
|
||||
</CONFIG>
|
54
demo/rtl/demonodecmdlineoptions.pas
Normal file
54
demo/rtl/demonodecmdlineoptions.pas
Normal file
@ -0,0 +1,54 @@
|
||||
program demonodecmdlineoptions;
|
||||
|
||||
{$mode objfpc}
|
||||
|
||||
uses
|
||||
nodejsapp, JS, Classes, SysUtils, nodeJS;
|
||||
|
||||
type
|
||||
|
||||
{ TMyApplication }
|
||||
|
||||
TMyApplication = class(TNodeJSApplication)
|
||||
procedure doRun; override;
|
||||
private
|
||||
procedure Usage(Msg: string);
|
||||
end;
|
||||
|
||||
procedure TMyApplication.Usage(Msg : string);
|
||||
|
||||
begin
|
||||
if Msg<>'' then
|
||||
Writeln('Error :',Msg);
|
||||
Writeln('Usage:');
|
||||
Writeln(ExeName,' [options]');
|
||||
Writeln('Where options is one or more of');
|
||||
Writeln('-h --help this help message');
|
||||
Writeln('-e --echo echo option');
|
||||
ExitCode:=Ord(Msg<>'');
|
||||
end;
|
||||
|
||||
procedure TMyApplication.doRun;
|
||||
|
||||
Var
|
||||
S : String;
|
||||
begin
|
||||
S:=CheckOptions('he:',['help','echo']);
|
||||
if (S<>'') or HasOption('h','help') then
|
||||
Usage(S);
|
||||
if HasOption('e','echo') then
|
||||
Writeln(GetoptionValue('e','echo'));
|
||||
for S in GetNonOptions('he:',['help','echo']) do
|
||||
Writeln(s);
|
||||
Terminate;
|
||||
end;
|
||||
|
||||
var
|
||||
Application : TMyApplication;
|
||||
|
||||
begin
|
||||
Application:=TMyApplication.Create(nil);
|
||||
Application.Initialize;
|
||||
Application.Run;
|
||||
Application.Free;
|
||||
end.
|
Loading…
Reference in New Issue
Block a user