-
Notifications
You must be signed in to change notification settings - Fork 395
Does not allow arguments that start with the '@' character #1625
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is intentional. The |
To add to @jonsequitur's answer, it is possible to disable response files (and thus treating using System.CommandLine.Builder;
using System.CommandLine.Parser;
var myRootCmd = ... your normal command(s) setup ...
var parser = new CommandLineBuilder(myRootCmd)
.ParseResponseFileAs(ResponseFileHandling.Disabled)
.UseDefaults()
.Build();
parser.Invoke(args); |
There's an interesting question here about how the user rather than the tool developer should specify an argument beginning with "@" when response files are enabled. There should be a way to escape the string but I'm not sure there's one implemented. |
@jonsequitur @elgonzo just fyi, this issue was raised for dotnet/templating in dotnet/templating#4488 as well. In one of the templates, the author uses |
I've been unable to find prior art for escaping a token on the command line that could indicate a response file. Suggestions are welcome. I'll put forward an approach we could take in the absence of a better-established convention. We looked a bit at escaping using quotes but this tends to get quite confusing when combined with shell escaping requirements, so we discarded it. My proposal that could be a little easier for users is to prepend an additional > myapp --username @@jonsequitur Of course, communicating the existence of this convention would be a whole other challenge. Thoughts? |
I feel even |
Possibly a directive could be used… This would be difficult for users to discover, and cumbersome to use interactively. For scripts though, this would be easier than doubling the |
Could be made part of the error message.
|
These are all good suggestions, though I worry that interpreting the A simple escape mechanism and an error message would be pretty simple and effective, I think. |
The proposed solution is to enable response files for How does that sound? |
That sounds like an unnecessary regression. |
It's an unintended behavior so I think it probably makes sense to make it consistent now instead of maintaining it forever. |
How is the @@ escaping going to be handled in file name completion? |
I mean, System.CommandLine does not currently complete file names and instead leaves that to the shell. But the shell doesn't know about @@ escaping so you'd need to handle it either in the shell-specific completion function or in the System.CommandLine library. If response files are implemented in middleware that can be disabled or replaced by the application, I think this middleware should take care of the @@ escaping as well. So the completion callback of the argument outputs unescaped strings, the middleware escapes @ characters, and either the shell-specific completion function or the shell itself escapes shell metacharacters such as dollar signs. |
There's a separate issue to improve filename completions (#1697). We'd like System.CommandLine to do a better job at filename completions rather than the current all-or-nothing approach where you get either completions from the parser or from the file system but not both. In any case, the shell isn't typically handling response files anyway. Since response file expansion happens during tokenization, prior to parsing, the contents of the response file are taken into account when calculating completions. This happens before middleware. The response file expansion is still configurable, but the initial trigger to perform replacement (the |
If anyone using Beta 4 arrives here, you'll find that You'll need to create a .UseTokenReplacer((string tokenToReplace, out IReadOnlyList<string>? replacementTokens, out string? errorMessage) =>
{
replacementTokens = null;
errorMessage = null;
return false;
}) |
appreciate the follow-up. But since then, the code base of System.CommandLine has changed significantly. CommandLineBuilder is no more, and response file handling is now being configured via command-line-api/src/System.CommandLine/CliConfiguration.cs Lines 71 to 78 in a045dd5
Basically, now you would disable response file handling by setting up a CliConfiguration like that for example: var cliConf = new CliConfiguration(myRootCommand)
{
ResponseFileTokenReplacer = null
};
var parseResult = cliConf.Parse(args);
or
cliConf.Invoke(args); // or await cliConf.InvokeAsync(args, cancellationToken); Note that the nuget.org feed does not yet provide up-to-date builds of System.CommandLine. Up-to-date builds (more or less) of System.CommandLine are available through the daily builds nuget feed mentioned in the projects readme.md: https://github.com/dotnet/command-line-api#daily-builds. But be aware that the library is still under heavy development, and expect System.CommandLine's APIs possibly still changing (until either the project maintainers announce the APIs having become stable or a proper non-beta is released). |
Thanks for the update @elgonzo. I already dealt with a bunch of changes going from Beta1 through Beta4. I've been watching this repo for a few years now, and I've noticed (with dread) the massive API churn from Beta4 to present. I kind of regret taking a dependency on this library as early as I did, but I liked the high-level features and architecture discussed in the March 2019 MSDN article. I also liked that it was from Microsoft and part of the dotnet project. I was excited when Beta4 was documented in MSDN/Learn because it seemed like the library was getting close to release. Alas, no. At this point, I'm just sticking with Beta4 until I encounter something it doesn't handle or until System.CommandLine 2.0 is stable and out of beta. |
Fails when invoking the app from command line with a parameter that starts with the "@" character
The text was updated successfully, but these errors were encountered: