implementing --version?

Jacob Carlborg via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Mon Nov 21 23:41:13 PST 2016


On 2016-11-21 22:32, mab-on wrote:
> On Monday, 21 November 2016 at 20:56:41 UTC, Karabuta wrote:
>>
>> There is a package in the dub registry called commando
>> (https://code.dlang.org/packages/commando) for that.
>
> Hm.. maybe i explained it wrong.
> My problem is not to pass a argument to the application.
>
> What i want is a clever mechanism to store the SemVer (or Commit-ID) in
> the binary at compiletime - automatically. Otherwise i have to think to
> update a const in the code every time i build a new Version.

Use "git describe" to get the latest tag and/or commit hash. Use the 
"preGenerateCommands" field in Dub to generate the version before 
compiling the application. Write the result of "git describe" to a file 
and import that file in the application.

Use std.getopt to parse the command line arguments.

https://github.com/jacob-carlborg/dstep/blob/master/dub.json#L14
https://github.com/jacob-carlborg/dstep/blob/master/dstep/Configuration.d#L18

-- 
/Jacob Carlborg


More information about the Digitalmars-d-learn mailing list