Skip to content

Commit 60176e2

Browse files
author
Daniel Robaszkiewicz
committed
RM: projections
1 parent 9ba3198 commit 60176e2

1 file changed

Lines changed: 28 additions & 28 deletions

File tree

src/Markdown2Toc/Program.cs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,34 @@
1-
using System;
2-
using System.Collections;
3-
using System.Collections.Generic;
41
using System.CommandLine;
5-
using System.IO;
6-
using System.Linq;
72

3+
var inOpt = new Option<string>("--input-file")
4+
{
5+
Description = "Input markdown file(s) path",
6+
Required = true
7+
};
8+
var outOpt = new Option<string>("--output-file")
9+
{
10+
Description = "Output TOC file or directory path",
11+
DefaultValueFactory = _ => "./"
12+
};
13+
var tocOpt = new Option<string?>("--toc-file")
14+
{
15+
Description = "TOC file to merge"
16+
};
817

9-
class Program
18+
var rootCommand = new RootCommand("Simple tool to generate table-of-content yaml files from Markdown files")
1019
{
11-
static async Task<int> Main(string[] args)
12-
{
13-
var inArg = new Argument<string>("--input-file");
14-
inArg.Description = "Input markdown file(s) path";
15-
var outArg = new Argument<string>("--output-file");
16-
outArg.DefaultValueFactory = (r) => "./";
17-
outArg.Description= "Output TOC file or directory path";
18-
var toc = new Option<string>("--toc-file");
19-
toc.Description="TOC file to merge";
20-
var rootCommand = new RootCommand();
21-
rootCommand.Description = "Simple tool to generate table-of-content yaml files from Markdown files";
22-
23-
rootCommand.Add(inArg);
24-
rootCommand.Add(outArg);
25-
rootCommand.Add(toc);
26-
rootCommand.SetAction(p => Md2TocGenerator.Generate(p.GetValue(inArg), p.GetValue(outArg), p.GetValue(toc)));
20+
inOpt,
21+
outOpt,
22+
tocOpt
23+
};
2724

28-
// Parse the incoming args and invoke the handler
29-
//return await rootCommand.InvokeAsync(args);
30-
throw new ArgumentException("WTF");
31-
}
25+
rootCommand.SetAction(async (parseResult, _) =>
26+
{
27+
await Md2TocGenerator.Generate(
28+
parseResult.GetValue(inOpt)!,
29+
parseResult.GetValue(outOpt)!,
30+
parseResult.GetValue(tocOpt) ?? string.Empty);
31+
return 0;
32+
});
3233

33-
34-
}
34+
return await rootCommand.Parse(args).InvokeAsync();

0 commit comments

Comments
 (0)