Skip to content
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

[eas-cli] Add flag sanitization in updates command #1473

Merged
merged 5 commits into from
Oct 31, 2022

Conversation

byCedric
Copy link
Member

Checklist

  • I've added an entry to CHANGELOG.md if necessary. You can comment this pull request with /changelog-entry [breaking-change|new-feature|bug-fix|chore] [message] and CHANGELOG.md will be updated automatically.

Why

This starts ENG-5926 and is the first of a couple of stacked PRs to clean this command up.

How

  • Added RawUpdateFlags and UpdateFlags
  • Added basic validation for incorrect combinations of flags
  • Renamed a few variables in runAsync to emphasize entity relation
    • groupgroupId
    • messageupdateMessage

Test Plan

eas update (with all flag-variations should work)

@byCedric byCedric requested a review from wschurman as a code owner October 24, 2022 16:52
@github-actions
Copy link

github-actions bot commented Oct 24, 2022

Size Change: -4.21 kB (0%)

Total Size: 40.1 MB

Filename Size Change
./packages/eas-cli/dist/eas-linux-x64.tar.gz 40.1 MB -4.21 kB (0%)

compressed-size-action

@codecov
Copy link

codecov bot commented Oct 24, 2022

Codecov Report

Merging #1473 (1983d52) into main (fa704c4) will decrease coverage by 0.03%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##             main    #1473      +/-   ##
==========================================
- Coverage   51.16%   51.13%   -0.02%     
==========================================
  Files         450      450              
  Lines       15483    15492       +9     
  Branches     3041     3045       +4     
==========================================
  Hits         7921     7921              
- Misses       7549     7558       +9     
  Partials       13       13              
Impacted Files Coverage Δ
packages/eas-cli/src/commands/update/index.ts 16.15% <0.00%> (-0.52%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@@ -577,6 +602,38 @@ export default class UpdatePublish extends EasCommand {
}
}
}

private sanitizeFlags(flags: RawUpdateFlags): UpdateFlags {
const nonInteractive = flags['non-interactive'] ?? false;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const nonInteractive = flags['non-interactive'] ?? false;
const nonInteractive = flags['non-interactive'];

(since this is type boolean)

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure, no strong opinions on this one. I just added it for clarity; this is the default (just like we do with some other flags). But it is indeed very explicit.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, the this.getContextAsync requires a boolean for nonInteractive. Since we have to provide a default anyways, I'll revert this change and put it in the santizeFlags method.


const { auto, branch: branchName, message: updateMessage } = flags;
if (nonInteractive && !auto && !(branchName && updateMessage)) {
Errors.error(
Copy link
Member

Choose a reason for hiding this comment

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

these exit/error methods (that return never) are pretty oddly-typed. For example, if you pass {exit: false} in as the second argument, it doesn't exit and the typescript types are incorrect.

I made a similar comment on another recent PR (#1427 (comment)) but my general feeling is that these add a bit of overhead for the reviewer since it's not immediately clear just from reading that they halt the procedure (like a throw would). That being said, I see that these are used in this param sanitization pretty consistently, so I guess it's okay here. It still took me a bit longer to review though, so just a data point.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I hate them too. Probably best to use throw new Error. Can follow up in a PR to get rid of this in all of the santizeFlags methods. For now, I just kept the code consistent with what we already have.

@byCedric byCedric requested a review from EvanBacon as a code owner October 25, 2022 20:58
@byCedric byCedric force-pushed the @bycedric/updates/input-refactor branch from 48eec6d to 1983d52 Compare October 28, 2022 16:03
@byCedric byCedric merged commit cb09906 into main Oct 31, 2022
@byCedric byCedric deleted the @bycedric/updates/input-refactor branch October 31, 2022 17:18
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.

2 participants