digitalmars.D.learn - implementing --version?
- mab-on (5/5) Nov 21 2016 I would like to implement a "--version" switch for a command line
- Karabuta (6/11) Nov 21 2016 There is a package in the dub registry called commando
- mab-on (7/9) Nov 21 2016 Hm.. maybe i explained it wrong.
- Basile B. (9/13) Nov 21 2016 enum versionData = import("version.dat");
- Basile B. (4/17) Nov 21 2016 I have an example here:
- Meta (11/21) Nov 21 2016 You could write a little script to generate an increasing version
- Meta (4/14) Nov 21 2016 Also another thread I created on the Dub subforum where the
- Jacob Carlborg (10/19) Nov 21 2016 Use "git describe" to get the latest tag and/or commit hash. Use the
- mab-on (1/1) Nov 22 2016 Thanks! These tips are exactly what i needed :)
I would like to implement a "--version" switch for a command line application. Is there a clever way to do that without using the brain on every build? :) A dub-solution would be nice - but i didnt find it.
Nov 21 2016
On Monday, 21 November 2016 at 19:33:54 UTC, mab-on wrote:I would like to implement a "--version" switch for a command line application. Is there a clever way to do that without using the brain on every build? :) A dub-solution would be nice - but i didnt find it.There is a package in the dub registry called commando (https://code.dlang.org/packages/commando) for that. Example usage can be found at https://github.com/SirTony/commando/tree/master/examples/find. The README file describes the code found in the src folder.
Nov 21 2016
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.
Nov 21 2016
On Monday, 21 November 2016 at 21:32:16 UTC, mab-on wrote: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.enum versionData = import("version.dat"); enum min = anyCTFEFunctionThatParsesMin(versionData); enum maj = anyCTFEFunctionThatParsesMaj(versionData); // etc... you can even use compile-time regex... The path to the file "version.dat" must be specified with the -J DMD command line. Generating the file is another story, maybe a git script could do that.
Nov 21 2016
On Monday, 21 November 2016 at 23:46:41 UTC, Basile B. wrote:On Monday, 21 November 2016 at 21:32:16 UTC, mab-on wrote:I have an example here: https://github.com/BBasile/Coedit/blob/master/cesetup/cesetup.d#L165 I don't use semVer but you basically get the method.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.enum versionData = import("version.dat"); enum min = anyCTFEFunctionThatParsesMin(versionData); enum maj = anyCTFEFunctionThatParsesMaj(versionData); // etc... you can even use compile-time regex... The path to the file "version.dat" must be specified with the -J DMD command line. Generating the file is another story, maybe a git script could do that.
Nov 21 2016
On Monday, 21 November 2016 at 21:32:16 UTC, mab-on wrote:On Monday, 21 November 2016 at 20:56:41 UTC, Karabuta wrote:You could write a little script to generate an increasing version and save it in a file. Then with Dub you can use a pre-build or pre-generate command to call that script, and in your D code do `enum version = import("version.txt");`. You can do whatever you want with this text; process it, convert it to an internal data structure, populate settings, etc. I created a thread a little while ago that's somewhat on this topic... It was partially about Dub pre-build and pre-generate commands so you may find it useful. http://forum.dlang.org/thread/mzipqtnimvexeddjtcju forum.dlang.orgThere 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.
Nov 21 2016
On Tuesday, 22 November 2016 at 00:41:42 UTC, Meta wrote:You could write a little script to generate an increasing version and save it in a file. Then with Dub you can use a pre-build or pre-generate command to call that script, and in your D code do `enum version = import("version.txt");`. You can do whatever you want with this text; process it, convert it to an internal data structure, populate settings, etc. I created a thread a little while ago that's somewhat on this topic... It was partially about Dub pre-build and pre-generate commands so you may find it useful. http://forum.dlang.org/thread/mzipqtnimvexeddjtcju forum.dlang.orgAlso another thread I created on the Dub subforum where the creator goes into a little more detail: http://forum.rejectedsoftware.com/groups/rejectedsoftware.dub/thread/8012/
Nov 21 2016
On 2016-11-21 22:32, mab-on wrote:On Monday, 21 November 2016 at 20:56:41 UTC, Karabuta wrote: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 CarlborgThere 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.
Nov 21 2016