Skip to content
This repository was archived by the owner on Nov 20, 2018. It is now read-only.

Add an init command for adding a UserSecretsId #500

Merged
merged 10 commits into from
Nov 5, 2018
Merged

Add an init command for adding a UserSecretsId #500

merged 10 commits into from
Nov 5, 2018

Conversation

liamdawson
Copy link
Contributor

Adds an init command for adding a UserSecretsId

Addresses #166

@dnfclas
Copy link

dnfclas commented Oct 13, 2018

CLA assistant check
All CLA requirements met.

@liamdawson
Copy link
Contributor Author

There are a couple of things I would like some help fixing appropriately:

  1. Any test cases I'm missing? e.g. I feel I am missing test cases for invalid/missing project files for init, as they won't return the same output as they do for other commands right now.
  2. As the above point, some error cases (invalid/missing project file) won't return output consistent with other subcommands - what's the best DRY way to solve that?
  3. How should I indicate a command failure for https://github.com/aspnet/DotNetTools/pull/500/files#diff-0207ee8b1aa083ec78304322c8b620c7R65 ?
  4. How do I add a localized error for "Project already has a UserSecretsId"? Adding it to the resources.resx didn't add the functions in the designer.cs that exist for the other resource entries.

@natemcmaster
Copy link
Contributor

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,
Nate

@natemcmaster natemcmaster changed the base branch from release/2.2 to master October 15, 2018 18:41
Copy link
Contributor

@natemcmaster natemcmaster left a 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;
Copy link
Contributor

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... :-/
    [*.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>");
Copy link
Contributor

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");

Copy link
Contributor Author

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>");
Copy link
Contributor

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;
Copy link
Contributor

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.

Copy link
Contributor Author

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).

Copy link
Contributor

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.

Copy link
Contributor Author

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?

@natemcmaster natemcmaster self-assigned this Oct 15, 2018
@natemcmaster natemcmaster added this to the 3.0.0 milestone Oct 15, 2018
@liamdawson
Copy link
Contributor Author

Thanks for the thorough feedback @natemcmaster, I'll see to that soon.

Could I also get a pointer on how to add messages via resources.resx? I'll need to add a couple, and adding them in VS didn't seem to update the appropriate designer file (which says it is auto-generated).

Thanks again!

@natemcmaster
Copy link
Contributor

Re: resx files.

Edit the .resx file in VS (or an xml editor) and then run dotnet msbuild -restore -t:Resx from command line.

@natemcmaster
Copy link
Contributor

Sorry, missed a piece: run dotnet msbuild -restore -t:Resx in the src/dotnet-user-secrets/ project dir.

@liamdawson liamdawson changed the title [WIP] Add an init command for adding a UserSecretsId Add an init command for adding a UserSecretsId Oct 28, 2018
@liamdawson
Copy link
Contributor Author

I'll open another PR to cover the status code returns on ICommand, otherwise I believe I've addressed all your PR feedback (and have removed changes to korebuild and csproj files)

@natemcmaster
Copy link
Contributor

@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.

@liamdawson
Copy link
Contributor Author

@natemcmaster, belatedly pinging you as requested.

@natemcmaster
Copy link
Contributor

Thanks for making the requested changes. I'll bring this in once CI is green (I've just re-triggered a build).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants