Skip to content

Commit 918938f

Browse files
committed
Make an ability to omit --query option
1 parent 5997ea6 commit 918938f

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

Foundation.Data.Doublets.Cli/Program.cs

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,43 +11,53 @@
1111
description: "Path to the links database file",
1212
getDefaultValue: () => "db.links"
1313
);
14+
dbOption.AddAlias("-d");
1415

1516
var queryOption = new Option<string>(
1617
name: "--query",
1718
description: "LiNo query for CRUD operation"
1819
);
20+
queryOption.AddAlias("-q");
21+
22+
var queryArgument = new Argument<string>(
23+
name: "query",
24+
description: "LiNo query for CRUD operation"
25+
);
26+
queryArgument.Arity = ArgumentArity.ZeroOrOne;
1927

2028
var rootCommand = new RootCommand("LiNo CLI Tool for managing links data store")
2129
{
2230
dbOption,
23-
queryOption
31+
queryOption,
32+
queryArgument
2433
};
2534

26-
rootCommand.SetHandler((string db, string query) =>
35+
rootCommand.SetHandler((string db, string queryOptionValue, string queryArgumentValue) =>
2736
{
2837
using var links = new UnitedMemoryLinks<uint>(db);
2938

3039
var decoratedLinks = links.DecorateWithAutomaticUniquenessAndUsagesResolution();
3140

32-
if (!string.IsNullOrWhiteSpace(query))
33-
{
34-
// ProcessQuery(links, query);
35-
36-
QueryProcessor.Options options = query;
41+
var effectiveQuery = !string.IsNullOrWhiteSpace(queryOptionValue) ? queryOptionValue : queryArgumentValue;
3742

38-
options.ChangesHandler = (before, after) =>
43+
if (!string.IsNullOrWhiteSpace(effectiveQuery))
44+
{
45+
var options = new QueryProcessor.Options
3946
{
40-
var beforeLink = new DoubletLink(before);
41-
var afterLink = new DoubletLink(after);
42-
Console.WriteLine($"{links.Format(beforeLink)}{links.Format(afterLink)}");
43-
// Console.WriteLine(links.Format(link));
44-
return links.Constants.Continue;
47+
Query = effectiveQuery,
48+
ChangesHandler = (before, after) =>
49+
{
50+
var beforeLink = new DoubletLink(before);
51+
var afterLink = new DoubletLink(after);
52+
Console.WriteLine($"{links.Format(beforeLink)}{links.Format(afterLink)}");
53+
return links.Constants.Continue;
54+
}
4555
};
4656

4757
QueryProcessor.ProcessQuery(decoratedLinks, options);
4858
}
4959
PrintAllLinks(decoratedLinks);
50-
}, dbOption, queryOption);
60+
}, dbOption, queryOption, queryArgument);
5161

5262
await rootCommand.InvokeAsync(args);
5363

0 commit comments

Comments
 (0)