Skip to content

Commit

Permalink
Make an ability to omit --query option
Browse files Browse the repository at this point in the history
  • Loading branch information
Konard committed Dec 15, 2024
1 parent 5997ea6 commit 918938f
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions Foundation.Data.Doublets.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,43 +11,53 @@
description: "Path to the links database file",
getDefaultValue: () => "db.links"
);
dbOption.AddAlias("-d");

var queryOption = new Option<string>(
name: "--query",
description: "LiNo query for CRUD operation"
);
queryOption.AddAlias("-q");

var queryArgument = new Argument<string>(
name: "query",
description: "LiNo query for CRUD operation"
);
queryArgument.Arity = ArgumentArity.ZeroOrOne;

var rootCommand = new RootCommand("LiNo CLI Tool for managing links data store")
{
dbOption,
queryOption
queryOption,
queryArgument
};

rootCommand.SetHandler((string db, string query) =>
rootCommand.SetHandler((string db, string queryOptionValue, string queryArgumentValue) =>
{
using var links = new UnitedMemoryLinks<uint>(db);

var decoratedLinks = links.DecorateWithAutomaticUniquenessAndUsagesResolution();

if (!string.IsNullOrWhiteSpace(query))
{
// ProcessQuery(links, query);

QueryProcessor.Options options = query;
var effectiveQuery = !string.IsNullOrWhiteSpace(queryOptionValue) ? queryOptionValue : queryArgumentValue;

options.ChangesHandler = (before, after) =>
if (!string.IsNullOrWhiteSpace(effectiveQuery))
{
var options = new QueryProcessor.Options
{
var beforeLink = new DoubletLink(before);
var afterLink = new DoubletLink(after);
Console.WriteLine($"{links.Format(beforeLink)}{links.Format(afterLink)}");
// Console.WriteLine(links.Format(link));
return links.Constants.Continue;
Query = effectiveQuery,
ChangesHandler = (before, after) =>
{
var beforeLink = new DoubletLink(before);
var afterLink = new DoubletLink(after);
Console.WriteLine($"{links.Format(beforeLink)}{links.Format(afterLink)}");
return links.Constants.Continue;
}
};

QueryProcessor.ProcessQuery(decoratedLinks, options);
}
PrintAllLinks(decoratedLinks);
}, dbOption, queryOption);
}, dbOption, queryOption, queryArgument);

await rootCommand.InvokeAsync(args);

Expand Down

0 comments on commit 918938f

Please sign in to comment.