mirror of
https://onedev.site.tesses.net/crosslang/crosslangextras
synced 2026-02-09 09:35:46 +00:00
Adding some documentation to crosslang shell
This commit is contained in:
83
Tesses.CrossLang.Documentation/src/main.tcross
Normal file
83
Tesses.CrossLang.Documentation/src/main.tcross
Normal file
@@ -0,0 +1,83 @@
|
||||
var fns = [];
|
||||
func Crawl(c,name)
|
||||
{
|
||||
if(TypeOf(c) == "Dictionary")
|
||||
{
|
||||
each(var item : Dictionary.Items(c))
|
||||
{
|
||||
Crawl(item.Value,name.Count == 0 ? item.Key : $"{name}.{item.Key}");
|
||||
}
|
||||
}
|
||||
else if(TypeOf(c) == "ExternalMethod")
|
||||
{
|
||||
fns.Add({
|
||||
Name = name,
|
||||
Documentation = c.Documentation,
|
||||
Arguments = c.Arguments
|
||||
});
|
||||
}
|
||||
}
|
||||
func main(args)
|
||||
{
|
||||
var md = "";
|
||||
if(args.Count == 2)
|
||||
{
|
||||
var strm = FS.Local.OpenFile(args[1],"rb");
|
||||
|
||||
var package = VM.LoadExecutable(strm);
|
||||
|
||||
strm.Close();
|
||||
|
||||
md = $"# {package.Name} Documentation\n";
|
||||
|
||||
each(var fn : package.Functions)
|
||||
{
|
||||
var fnName = "";
|
||||
for(var i = 0; i < fn.FunctionNameParts.Count; i++)
|
||||
{
|
||||
|
||||
if(i > 0) fnName += ".";
|
||||
fnName += fn.FunctionNameParts[i];
|
||||
|
||||
}
|
||||
fns.Add({
|
||||
Arguments=package.Chunks[i].Arguments,
|
||||
Documentation=fn.Documentation,
|
||||
Name=fnName
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
md = "# CrossLang Runtime Documentation\n";
|
||||
var dict = {};
|
||||
var rEnv = VM.CreateEnvironment(dict);
|
||||
rEnv.RegisterEverything();
|
||||
Crawl(dict,"");
|
||||
}
|
||||
|
||||
|
||||
each(var item : fns)
|
||||
{
|
||||
md += "```go\n";
|
||||
if(item.Documentation.Count > 0)
|
||||
{
|
||||
md += "/^ ";
|
||||
md += item.Documentation.Replace(",","");
|
||||
md += " ^/\n";
|
||||
}
|
||||
md += "func ";
|
||||
md += item.Name;
|
||||
md += "(";
|
||||
for(var i = 0; i < item.Arguments.Count; i++)
|
||||
{
|
||||
if(i > 0) md += ", ";
|
||||
md += item.Arguments[i];
|
||||
}
|
||||
md += ");\n";
|
||||
|
||||
md += "```\n\n";
|
||||
}
|
||||
|
||||
Console.WriteLine(md);
|
||||
}
|
||||
Reference in New Issue
Block a user