InitCommand

- Set dependencies

Project

- Added support for dependencies
This commit is contained in:
Tristan B. Velloza Kildaire 2024-04-28 15:56:24 +02:00
parent 8e85087b4e
commit 91c1e5e1ad
2 changed files with 31 additions and 0 deletions

View File

@ -115,6 +115,7 @@ struct InitCommand
answers[2].getValues(projDeps);
projDeps = unique(projDeps);
DEBUG("Dependencies wanted: ", projDeps);
proj.setDependencies(projDeps);
JSONValue json = proj.serialize();
string jsonStr = json.toPrettyString();

View File

@ -28,6 +28,7 @@ public struct Project
private string description;
private ProjectType type;
private string entrypoint;
private string[] dependencies;
public void setName(string name)
{
@ -49,6 +50,11 @@ public struct Project
this.entrypoint = entrypoint;
}
public void setDependencies(string[] dependencies)
{
this.dependencies = dependencies;
}
public string getName()
{
return this.name;
@ -69,12 +75,18 @@ public struct Project
return this.entrypoint;
}
public string[] getDependencies()
{
return this.dependencies;
}
public JSONValue serialize()
{
JSONValue root;
root["name"] = this.name;
root["description"] = this.description;
root["dependencies"] = this.dependencies;
DEBUG(format("Serialized to: %s ", root));
@ -149,6 +161,24 @@ public struct Project
proj.setEntrypoint(json["entrypoint"].str());
}
JSONValue* projectDepsPtr = "dependencies" in json;
string[] deps;
if(projectDepsPtr)
{
foreach(JSONValue arrElem; projectDepsPtr.array())
{
if(arrElem.type() == JSONType.string)
{
deps ~= arrElem.str();
}
else
{
ERROR(format("A dependency must be a string not a '%s'", arrElem.type()));
return false;
}
}
}
return true;
}
}