-
Notifications
You must be signed in to change notification settings - Fork 75
Add an init command for adding a UserSecretsId #500
Conversation
There are a couple of things I would like some help fixing appropriately:
|
Hi @liamdawson, thanks for doing this work! I'm going to help you merge this PR in. Unfortunately, we've missed the deadline for features in 2.2, so this PR will need to target 3.0 instead. I'm going to re-target your PR to the master branch and then review the code changes. Thanks, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a great start! I've left a few comments about specific parts of this implementation.
Can you also add test case for this particular error case?
- Init should failed when a bad ID given. Example:
init --id id/with/slash
should fail.
And ID is invalid if userSecretsId.IndexOfAny(Path.GetInvalidFileNameChars()) >= 0
@@ -0,0 +1,99 @@ | |||
using Microsoft.Extensions.CommandLineUtils; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two code formatting nit-picks and all new *.cs files:
- Can you add the copyright header?
- Can you sort using with System.* namespaces first? I wish VS enforced this better... :-/
Lines 12 to 14 in 581b316
[*.cs] indent_size = 4 dotnet_sort_system_directives_first = true:warning
// No valid property group, create a new one | ||
if (propertyGroup == null) | ||
{ | ||
propertyGroup = XElement.Parse(@"<PropertyGroup></PropertyGroup>"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work? Parsing seems like a little much.
propertyGroup = new XElement("PropertyGroup");
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I didn't actually try that because I was a bit superstitious about XName
. Will take a look later.
} | ||
|
||
// Add UserSecretsId element | ||
var userSecretsElement = XElement.Parse(@"<UserSecretsId></UserSecretsId>"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this work?
var userSecretsElement = new XElement("UserSecretsId", newSecretsId);
if (options.Command is InitCommand initCmd) | ||
{ | ||
initCmd.Execute(new CommandContext(null, reporter, _console), _workingDirectory); | ||
return 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In retrospec, Command.Execute should probably have returned int
so the command can set an exit code. I'd be happy to also take a PR that made this change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay - I looked at that but ran into the fact the interface had the expectation. At first glance though, I don't know how I'd safely modify the interface to allow a status code return without causing a breaking change (but that's a separate conversation).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have my blessing to make a breaking change on ICommand
. For projects like this, the ICommand
type is an internal implementation detail of these console tools. No one should be compiling an app against dotnet-user-secrets.dll
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ICommand
in this instance is from CommandLineUtils, so not part of this tool - do you still want that change?
Thanks for the thorough feedback @natemcmaster, I'll see to that soon. Could I also get a pointer on how to add messages via Thanks again! |
Re: resx files. Edit the .resx file in VS (or an xml editor) and then run |
Sorry, missed a piece: run |
I'll open another PR to cover the status code returns on |
@liamdawson ACK saw your comments. I'll take a closer look at this in a few days. Currently working on time-sensitive issues. Please ping me on this PR if I don't surface for air by Thurs. Nov. 1. |
@natemcmaster, belatedly pinging you as requested. |
Thanks for making the requested changes. I'll bring this in once CI is green (I've just re-triggered a build). |
Adds an init command for adding a UserSecretsId
Addresses #166