dotnet / dotnet/command-line-api

CLI fails on read-only file system

Open
#2,379 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
C#
Stars
3.7k
Forks
428
PR merge metrics
No merged PRs in 30d

Description

Steps to reproduce:

1. Use `CommandLineBuilder` with `.UseDefaults()`
2. Build a Docker image and run with `--read-only` to use a read-only file system

Expected result: CommandLine shouldn't use RegisterWithDotnetSuggest by default (or at least shouldn't create new files)

Actual result:
```
Unhandled exception: System.IO.IOException: Read-only file system : '/tmp/system-commandline-sentinel-files'
at [System.IO](http://system.io/).FileSystem.CreateDirectory(String fullPath, UnixFileMode unixCreateMode)
at [System.IO](http://system.io/).DirectoryInfo.Create()
at System.CommandLine.Invocation.FeatureRegistration.EnsureRegistered(Func`1 onInitialize)
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c.<b__5_0>d.MoveNext()
--- End of stack trace from previous location ---
at System.CommandLine.Builder.CommandLineBuilderExtensions.<>c__DisplayClass8_0.<b__0>d.MoveNext()
```

Workaround:

```
// call extensions explicitly because .UseDefaults() calls .RegisterWithDotnetSuggest()
var rootCommand = new RootCommand("My App");
var commandLineBuilder = new CommandLineBuilder(rootCommand);
commandLineBuilder
.UseVersionOption()
.UseHelp()
.UseParseDirective()
.UseSuggestDirective()
.UseTypoCorrections()
.UseParseErrorReporting()
.UseExceptionHandler()
.CancelOnProcessTermination();
var parser = commandLineBuilder.Build();
return await parser.InvokeAsync(args);
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.