* Node command-line demos

This commit is contained in:
michael 2020-02-21 15:14:03 +00:00
parent 84b1c93a7d
commit dddcdbb4d2
3 changed files with 141 additions and 0 deletions

View File

@ -40,6 +40,16 @@
</div>
</div>
</div>
<div class="row">
<div class="source">
<div class="source-inner">
<div>
Created using &nbsp; <a target="_blank" href="https://wiki.freepascal.org/pas2js">pas2js.</a> &nbsp;&nbsp;Sources: &nbsp; <a target="new" href="basic.lpr">Program
sources</a>.
</div>
</div>
</div>
</div>
</div>
<script>
rtl.run();

View 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>

View 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.