| Name | Message | Date |
|---|---|---|
| 📄 Cfa.Cli.csproj | 7 days ago | |
| 📄 packages.lock.json | 7 days ago | |
| 📄 Program.cs | 7 days ago | |
| 📄 ScanCommand.cs | 7 days ago |
📄
cli/src/ScanCommand.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
using System; using System.CommandLine; using System.CommandLine.Invocation; using System.IO; using System.Linq; using System.Threading; using System.Threading.Tasks; namespace Cfa.Cli; internal sealed class ScanCommand : Command { private static Argument<FileInfo> PathArgument { get; } = new("path") { Description = "Path to the solution file, or the directory containing it. (Defaults to the current directory.)", DefaultValueFactory = result => { var directory = new DirectoryInfo(Directory.GetCurrentDirectory()); switch ( directory .GetFiles("*.sln?", SearchOption.TopDirectoryOnly) .Where(f => f.Extension is ".sln" or ".slnx") .ToArray() ) { case []: result.AddError("No solution files found in the current directory."); return null!; case [var file]: return file; default: result.AddError("Multiple solution files found in the current directory."); return null!; } }, CustomParser = result => { if (result.Tokens is not [var token] || string.IsNullOrWhiteSpace(token.Value)) { result.AddError("No path specified."); return null; } if (Directory.Exists(token.Value)) { var directory = new DirectoryInfo(token.Value); switch ( directory .GetFiles("*.sln?", SearchOption.TopDirectoryOnly) .Where(f => f.Extension is ".sln" or ".slnx") .ToArray() ) { case []: result.AddError("No solution files found in the specified directory."); return null; case [var file]: return file; default: result.AddError("Multiple solution files found in the specified directory."); return null; } } if (File.Exists(token.Value)) { return new FileInfo(token.Value); } result.AddError("The specified path does not exist."); return null; }, }; private static Option<(FileInfo, int)> StartFileOption { get; } = new("--start-file", "-f") { Description = "The start file and line number for the analysis.", Required = true, CustomParser = result => { if (result.Tokens is not [var fileAndLine]) { result.AddError("Start file must be specified."); return default; } if (fileAndLine.Value.Split(":", 2) is not [var file, var lineString]) { result.AddError("Start file must include a line number separated by ':'."); return default; } if (!int.TryParse(lineString, out var line) || line <= 0) { result.AddError("Invalid line number specified."); return default; } return (new FileInfo(file), line); }, }; public ScanCommand() : base("scan", "Scan the code for analysis") { Action = new ScanAction(); Arguments.Add(PathArgument); Options.Add(StartFileOption); } internal sealed class ScanAction : AsynchronousCommandLineAction { public override async Task<int> InvokeAsync(ParseResult parseResult, CancellationToken cancellationToken) { var solutionFile = parseResult.GetRequiredValue(PathArgument); using var scanner = await Scanner.Create(solutionFile, cancellationToken); var (startFile, startLine) = parseResult.GetRequiredValue(StartFileOption); var symbol = await scanner.BuildCallGraph(startFile, startLine, cancellationToken); Console.WriteLine($"Found symbol: {symbol}"); Console.WriteLine($"Symbol type: {symbol.GetType().FullName}"); return 0; } } }