Skip to content

Allow changing whether a distribution group is public.#808

Merged
anywherepilot merged 4 commits intomasterfrom
jerietve/group-set-is-public
Apr 22, 2020
Merged

Allow changing whether a distribution group is public.#808
anywherepilot merged 4 commits intomasterfrom
jerietve/group-set-is-public

Conversation

@anywherepilot
Copy link
Contributor

@anywherepilot anywherepilot commented Apr 16, 2020

Add public and private switches to distribute groups update. These allow making a group public or the opposite.

Resolves #642.

@shortName("p")
@longName("isPublic")
@hasArg
public isPublic: string;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

public or maybe is-public though the is is not relevant.
Do we natively support bool here by any chance?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also it looks like this should act like a switch, where -p (or even --public) alone should set the value to true.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered that, but then how do you set it to not public? With another switch?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

--public=false

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, a common convention is to prefix with no as in --no-public (no short form here)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 false argument.

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

@jp-andre jp-andre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@anywherepilot anywherepilot changed the title Add isPublic option to distribute groups update. Allow changing whether a distribution group is public. Apr 21, 2020
@anywherepilot anywherepilot marked this pull request as ready for review April 21, 2020 06:41
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");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why doesn't it have null check like testCommandSuccess?

Copy link
Contributor Author

@anywherepilot anywherepilot Apr 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

@yujincat yujincat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve with suggestion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Set public distribute group access

3 participants

Comments