Skip to content

Commit 6b9d7b0

Browse files
committed
Tweak console formatting
1 parent 93967ad commit 6b9d7b0

File tree

3 files changed

+33
-17
lines changed

3 files changed

+33
-17
lines changed

ScipDotnet/IndexCommandHandler.cs

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -70,27 +70,36 @@ private static async Task ScipIndex(IHost host, IndexCommandOptions options)
7070
stopwatch.Elapsed.ToFriendlyString());
7171
}
7272

73+
private static string FixThisProblem(string examplePath)
74+
{
75+
return "To fix this problem, pass the path of a solution (.sln) or project (.csproj) file to the `scip-dotnet index` command. " +
76+
$"For example, run: scip-dotnet index {examplePath}";
77+
}
78+
7379
private static string? FindSolutionOrProjectFile(FileInfo workingDirectory, ILogger<IndexCommandOptions> logger)
7480
{
75-
var files = Directory.GetFiles(workingDirectory.FullName).Where(file =>
81+
var paths = Directory.GetFiles(workingDirectory.FullName).Where(file =>
7682
string.Equals(Path.GetExtension(file), ".sln", StringComparison.OrdinalIgnoreCase) ||
7783
string.Equals(Path.GetExtension(file), ".csproj", StringComparison.OrdinalIgnoreCase)
7884
).ToList();
79-
if (files.Count == 0)
80-
{
81-
logger.LogError(
82-
"No solution (.sln) or .csproj file detected in the working directory '{WorkingDirectory}'. Use the --solution-file argument to specify which solution file to index", workingDirectory.FullName);
83-
return null;
84-
}
8585

86-
if (files.Count != 1)
86+
switch (paths.Count)
8787
{
88-
logger.LogError(
89-
"Ambiguous solution files: {Join}. Use the --solution-file argument to specify which solution file to index",
90-
String.Join(", ", files));
91-
return null;
88+
case 0:
89+
logger.LogError(
90+
"No solution (.sln) or .csproj file detected in the working directory '{WorkingDirectory}'. {FixThis}",
91+
workingDirectory.FullName, FixThisProblem("SOLUTION_FILE"));
92+
return null;
93+
case 1:
94+
return paths.First();
9295
}
9396

94-
return files.First();
97+
var relativePaths = paths.Select(path => Path.GetRelativePath(workingDirectory.FullName, path)).ToList();
98+
logger.LogError(
99+
"Ambiguous solution files: {Join}. {FixThis}",
100+
String.Join(", ", relativePaths),
101+
FixThisProblem(relativePaths.First()));
102+
return null;
103+
95104
}
96105
}

ScipDotnet/Program.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ public static async Task<int> Main(string[] args)
1919
{
2020
var indexCommand = new Command("index", "Index a solution file")
2121
{
22-
new Argument<FileInfo>("projects", "Path to the .sln (solution) or .csproj file") { Arity = ArgumentArity.ZeroOrOne },
22+
new Argument<FileInfo>("projects", "Path to the .sln (solution) or .csproj file")
23+
{ Arity = ArgumentArity.ZeroOrOne },
2324
new Option<string>("--output", () => "index.scip",
2425
"Path to the output SCIP index file"),
2526
new Option<FileInfo>("--working-directory",
@@ -41,15 +42,21 @@ public static async Task<int> Main(string[] args)
4142
};
4243
indexCommand.Handler = CommandHandler.Create(IndexCommandHandler.Process);
4344
var rootCommand =
44-
new RootCommand("SCIP indexer for the C# programming language. Built with the Roslyn .NET compiler. Supports MSBuild.")
45+
new RootCommand(
46+
"SCIP indexer for the C# programming language. Built with the Roslyn .NET compiler. Supports MSBuild.")
4547
{
4648
indexCommand,
4749
};
4850
var builder = new CommandLineBuilder(rootCommand);
4951
return await builder.UseHost(_ => Host.CreateDefaultBuilder(), host =>
5052
{
5153
host.ConfigureAppConfiguration(b => b.AddInMemoryCollection());
52-
host.ConfigureLogging(b => b.AddFilter("Microsoft.Hosting.Lifetime", LogLevel.None));
54+
host.ConfigureLogging(b => b.AddSimpleConsole(options =>
55+
{
56+
options.IncludeScopes = true;
57+
options.SingleLine = true;
58+
options.TimestampFormat = "HH:mm:ss ";
59+
}).AddFilter("Microsoft.Hosting.Lifetime", LogLevel.None));
5360
host.ConfigureServices((_, collection) =>
5461
collection
5562
.AddSingleton(_ => CreateWorkspace())

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ cd scip-dotnet
2020

2121
Finally, use `dotnet run` to run the indexer locally.
2222
```shell
23-
dotnet run --project ScipDotnet -- index --working-directory PATH_TO_DIRECTORY_YOU_WANT_TO_INDEX
23+
dotnet run --framework net6.0 --project ScipDotnet -- index --working-directory PATH_TO_DIRECTORY_YOU_WANT_TO_INDEX
2424
```
2525

2626
Once scip-dotnet has finished indexing the project, there should be an `index.scip` at the root of the

0 commit comments

Comments
 (0)