Skip to content

Commit

Permalink
Use CTFE more for version information
Browse files Browse the repository at this point in the history
Basically pull everything from dub.json that we can
  • Loading branch information
rushsteve1 committed Jul 14, 2022
1 parent 65f5ea0 commit 2b734ad
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
3 changes: 2 additions & 1 deletion dub.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"authors": ["Steven vanZyl <rushsteve1@rushsteve1.us>"],
"copyright": "Copyright © 2021, Steven vanZyl",
"copyright": "Copyright © 2022, Steven vanZyl",
"description": "A near drop-in replacement for rm that uses the trash bin",
"version": "18",
"versionName": "M. Bison",
"license": "MIT",
"name": "trash-d",
"homepage": "https://github.com/rushsteve1/trash-d",
Expand Down
39 changes: 29 additions & 10 deletions source/trash/ver.d
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,49 @@ Version and copyright information that gets bundled in with trash-d

module trash.ver;

import std.conv : to;
import std.format : format;
import std.json;

/// The dub.json file inlined as a string
const string DUB_JSON = import("dub.json");

/// trash-d is versioned sequentially starting at 1
const int VER = version_from_json();

/// Ever major release is given a new name
/// Names are based on video game bosses
const string VER_NAME = "M. Bison";
const string VER_NAME = version_name_from_json();

/// The full version string
const string VER_TEXT = format("trash-d version %s '%s'", VER, VER_NAME);

/// The short copyright text and info
const string COPY_TEXT = "Copyright (C) 2021 Steven vanZyl.
License MIT <https://mit-license.org/>.
Fork on GitHub <https://github.com/rushsteve1/trash-d>
const string COPY_TEXT = copy_text_from_json();

This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
private int version_from_json() {
return DUB_JSON.parseJSON()["version"].str.to!int;
}

private string version_name_from_json() {
return DUB_JSON.parseJSON()["versionName"].str;
}

private string copy_text_from_json() {
import std.range;
import std.array;
import std.algorithm;

auto j = DUB_JSON.parseJSON();
string authors = j["authors"].array.map!(`a.str`).join(", ");

Written by Steven vanZyl <rushsteve1@rushsteve1.us>.";
return format("%s
License %s <https://spdx.org/licenses/%s.html>.
Fork on GitHub <%s>
int version_from_json() {
import std.json, std.conv;
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
return import("dub.json").parseJSON()["version"].str.to!int;
Written by %s.", j["copyright"].str, j["license"].str, j["license"].str,
j["homepage"].str, authors);
}

0 comments on commit 2b734ad

Please sign in to comment.