Allow changing whether a distribution group is public.#808
Allow changing whether a distribution group is public.#808anywherepilot merged 4 commits intomasterfrom
Conversation
| @shortName("p") | ||
| @longName("isPublic") | ||
| @hasArg | ||
| public isPublic: string; |
There was a problem hiding this comment.
public or maybe is-public though the is is not relevant.
Do we natively support bool here by any chance?
There was a problem hiding this comment.
Also it looks like this should act like a switch, where -p (or even --public) alone should set the value to true.
There was a problem hiding this comment.
I considered that, but then how do you set it to not public? With another switch?
There was a problem hiding this comment.
we apparently have support for booleans in the base class, let's see what it can do, and whether we need to expand it for this (which would not be worth the effort)
There was a problem hiding this comment.
Alternatively, a common convention is to prefix with no as in --no-public (no short form here)
There was a problem hiding this comment.
We're using names like isMandatory and isDisabled in other places, but I can rename it to just public. We also have precedent for that. It's a mix.
This is not a flag, it's a setter. It's setting a value to true or false, not on the command but on the distribution group it's modifying.
Problem with making it bool is that it will need to default to false, and we'll no longer be able to check whether it is passed or not. TypeScript doesn't support nullable booleans. We can't work with that, because we can't just go set the value based on that information. Since it's a setter, not a flag.
If providing a string value for a boolean is really unwanted, we can have two parameters called makePublic and makePrivate or something. I'm not sure that looks nicer.
There was a problem hiding this comment.
We're using names like
isMandatoryandisDisabledin other places, but I can rename it to justpublic. We also have precedent for that. It's a mix.
Sorry, but that's not true. From the code right there:
@help("Specifies whether this release should be considered mandatory. (Putting -m flag means mandatory)")
@shortName("m")
@longName("mandatory")
public isMandatory: boolean;
The option is called mandatory and it's a boolean switch. Specifically for casing, the only mistake I could find was displayKeys (we may want to consider fixing that in another PR, it should be display-keys).
This is not a flag, it's a setter. It's setting a value to true or false, not on the command but on the distribution group it's modifying.
I understand that. There are ways to make this work. Either the option could also accept an optional argument, or we could use something like --no-public or --private as you proposed.
Problem with making it bool is that it will need to default to false, and we'll no longer be able to check whether it is passed or not. TypeScript doesn't support nullable booleans. We can't work with that, because we can't just go set the value based on that information. Since it's a setter, not a flag.
The default value of a boolean field is "the field does not even exist", and "undefined" is perfectly acceptable for a boolean in TS. Yay.
The only question is how much effort is it to have an optional argument to a boolean switch, not whether it's possible or impossible.
There was a problem hiding this comment.
One more vote for having it as boolean using undefined. Otherwise we should handle the string to be a boolean value and that sound like more work.
There was a problem hiding this comment.
You are right on the naming. I was looking at the variable names, not the argument names.
The way booleans work in the CLI is by not setting the hasArg attribute on a property. It then becomes a boolean (regardless of what you say it should be in the property definition). The value is false when not provided. There is no undefined. Unless we add support for an optional parameter, which would be difficult*, there is mathematically speaking no difference between false and undefined. It's just the "not true" option, and cannot be used. So we need two switches.
- It would require defining an actual switch type parameter with a new syntax for taking an optional
falseargument.
There is no other example that I know of in the CLI that sets a boolean as obviously as this one, so we have to make a new decision. You and @yujincat are in favor of having two switches (or against a parameter taking a "true"/"false" string), and I don't have an opinion. So let's go with the two switches. I'll call them --public and --no-public as you suggested.
This is a good discussion btw, I'm glad we're having it :)
Things may be built on top of this in the future.
| @shortName("p") | ||
| @longName("isPublic") | ||
| @hasArg | ||
| public isPublic: string; |
There was a problem hiding this comment.
One more vote for having it as boolean using undefined. Otherwise we should handle the string to be a boolean value and that sound like more work.
jp-andre
left a comment
There was a problem hiding this comment.
Since you've chosen the 2 switches option and started the code implementation, let's use that.
The other name is incompatible with the way we initialize minimist. Add and refactor tests.
isPublic option to distribute groups update.| function testCommandFailure(executionScope: Nock.Scope, abortScope?: Nock.Scope) { | ||
| expect(abortScope.isDone()).to.eql(false, "Unexpected requests were made"); | ||
| function testCommandFailure(executionScope: Nock.Scope, skippedScope?: Nock.Scope) { | ||
| expect(skippedScope.isDone()).to.eql(false, "Unexpected requests were made"); |
There was a problem hiding this comment.
Why doesn't it have null check like testCommandSuccess?
There was a problem hiding this comment.
A better question would be why is this method copied into every test class 😛
I didn't need to fix this one to make my code work. Let's fix them all at once later. Thanks for your review.
yujincat
left a comment
There was a problem hiding this comment.
Approve with suggestion
Add
publicandprivateswitches todistribute groups update. These allow making a group public or the opposite.Resolves #642.