|
11 | 11 | description: "Path to the links database file",
|
12 | 12 | getDefaultValue: () => "db.links"
|
13 | 13 | );
|
| 14 | +dbOption.AddAlias("-d"); |
14 | 15 |
|
15 | 16 | var queryOption = new Option<string>(
|
16 | 17 | name: "--query",
|
17 | 18 | description: "LiNo query for CRUD operation"
|
18 | 19 | );
|
| 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; |
19 | 27 |
|
20 | 28 | var rootCommand = new RootCommand("LiNo CLI Tool for managing links data store")
|
21 | 29 | {
|
22 | 30 | dbOption,
|
23 |
| - queryOption |
| 31 | + queryOption, |
| 32 | + queryArgument |
24 | 33 | };
|
25 | 34 |
|
26 |
| -rootCommand.SetHandler((string db, string query) => |
| 35 | +rootCommand.SetHandler((string db, string queryOptionValue, string queryArgumentValue) => |
27 | 36 | {
|
28 | 37 | using var links = new UnitedMemoryLinks<uint>(db);
|
29 | 38 |
|
30 | 39 | var decoratedLinks = links.DecorateWithAutomaticUniquenessAndUsagesResolution();
|
31 | 40 |
|
32 |
| - if (!string.IsNullOrWhiteSpace(query)) |
33 |
| - { |
34 |
| - // ProcessQuery(links, query); |
35 |
| - |
36 |
| - QueryProcessor.Options options = query; |
| 41 | + var effectiveQuery = !string.IsNullOrWhiteSpace(queryOptionValue) ? queryOptionValue : queryArgumentValue; |
37 | 42 |
|
38 |
| - options.ChangesHandler = (before, after) => |
| 43 | + if (!string.IsNullOrWhiteSpace(effectiveQuery)) |
| 44 | + { |
| 45 | + var options = new QueryProcessor.Options |
39 | 46 | {
|
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 | + } |
45 | 55 | };
|
46 | 56 |
|
47 | 57 | QueryProcessor.ProcessQuery(decoratedLinks, options);
|
48 | 58 | }
|
49 | 59 | PrintAllLinks(decoratedLinks);
|
50 |
| -}, dbOption, queryOption); |
| 60 | +}, dbOption, queryOption, queryArgument); |
51 | 61 |
|
52 | 62 | await rootCommand.InvokeAsync(args);
|
53 | 63 |
|
|
0 commit comments