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

feat: add --stdin flag #296

Merged
merged 10 commits into from
Jul 2, 2023
Merged

feat: add --stdin flag #296

merged 10 commits into from
Jul 2, 2023

Conversation

danielpza
Copy link
Contributor

@danielpza danielpza commented Apr 19, 2023

Passing the --stdin flag would make it so it reads from stdin and outputs to stdout. This is useful for some tools/editors integration

Usage example:

$ cat package.json | sort-package-json --stdin

Closes #293

cli.js Outdated Show resolved Hide resolved
@danielpza danielpza requested a review from fisker April 19, 2023 04:06
@fisker
Copy link
Collaborator

fisker commented Apr 19, 2023

Is it possible to test?

@fisker
Copy link
Collaborator

fisker commented Apr 19, 2023

Maybe we can use child_process or worker_thread to do that.

@danielpza
Copy link
Contributor Author

Is it possible to test?
Maybe we can use child_process or worker_thread to do that.

Added some tests in 14bb2fb (#296)

package.json Outdated Show resolved Hide resolved
tests/cli.js Outdated Show resolved Hide resolved
@fisker
Copy link
Collaborator

fisker commented Apr 19, 2023

I forgot we already use child_process to run CLI test, we can add an option to accept stdin.

function runCLI({ args = [], cwd = process.cwd() }) {

But it can be done in future, since it's not important.

@danielpza danielpza requested a review from fisker April 19, 2023 06:27
@danielpza
Copy link
Contributor Author

I forgot we already use child_process to run CLI test, we can add an option to accept stdin.

Applied these changes in f7c3b6f (#296)

tests/cli.js Show resolved Hide resolved
@fisker
Copy link
Collaborator

fisker commented Apr 19, 2023

We have --check flag. Do you think we should support cat package.json | sort-package-json --stdin --check?

@danielpza
Copy link
Contributor Author

We have --check flag do you think we should support cat package.json | sort-package-json --stdin --check?

I considered adding support for the other flags, but it's not a priority for my use case. I guess we can add more support in the future if needed

tests/cli.js Outdated Show resolved Hide resolved
Copy link
Collaborator

@fisker fisker left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

@@ -89,6 +89,14 @@ $ sort-package-json "**/package.json" --check --quiet
$ sort-package-json "**/package.json" --quiet
```

### `--stdin` flag
Copy link
Owner

Choose a reason for hiding this comment

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

I'm not particularly precious about this, but it makes me think; would --file <path>/-F <path> be a better option here - where one can use - to use stdin. This is how git does it (git commit -F my-template or echo foo | git commit -F -).

Copy link
Collaborator

Choose a reason for hiding this comment

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

We plan to use util.parseArgs #283, not sure if it supports that.

Copy link
Owner

Choose a reason for hiding this comment

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

> util.parseArgs({args: ['-f', '-'], options: {file: {type: 'string', short: 'f' }}})
{ values: [Object: null prototype] { file: '-' }, positionals: [] }

Looks like it does?

cli.js Show resolved Hide resolved
@danielpza
Copy link
Contributor Author

Is there any blocker for this PR, any chance to get it merged otherwise?

@keithamus keithamus merged commit cefbbcb into keithamus:main Jul 2, 2023
@keithamus
Copy link
Owner

Thanks for the reminder @danielpza! 🎉🎉

@github-actions
Copy link

github-actions bot commented Jul 2, 2023

🎉 This PR is included in version 2.5.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

abhi-markan pushed a commit to UK-Export-Finance/mdm-api that referenced this pull request Jul 3, 2023
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [sort-package-json](https://togithub.com/keithamus/sort-package-json)
| [`2.4.1` ->
`2.5.0`](https://renovatebot.com/diffs/npm/sort-package-json/2.4.1/2.5.0)
|
[![age](https://badges.renovateapi.com/packages/npm/sort-package-json/2.5.0/age-slim)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://badges.renovateapi.com/packages/npm/sort-package-json/2.5.0/adoption-slim)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://badges.renovateapi.com/packages/npm/sort-package-json/2.5.0/compatibility-slim/2.4.1)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://badges.renovateapi.com/packages/npm/sort-package-json/2.5.0/confidence-slim/2.4.1)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>keithamus/sort-package-json (sort-package-json)</summary>

###
[`v2.5.0`](https://togithub.com/keithamus/sort-package-json/releases/tag/v2.5.0)

[Compare
Source](https://togithub.com/keithamus/sort-package-json/compare/v2.4.1...v2.5.0)

##### Features

- add --stdin flag
([#&#8203;296](https://togithub.com/keithamus/sort-package-json/issues/296))
([cefbbcb](https://togithub.com/keithamus/sort-package-json/commit/cefbbcbda23fc4caaad0fd3b9a5968d7b1adc96e)),
closes
[/github.com/keithamus/sort-package-json/pull/296#discussion_r1170890491](https://togithub.com//github.com/keithamus/sort-package-json/pull/296/issues/discussion_r1170890491)
[/github.com/keithamus/sort-package-json/pull/296#discussion_r1170896656](https://togithub.com//github.com/keithamus/sort-package-json/pull/296/issues/discussion_r1170896656)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/UK-Export-Finance/mdm-api).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS4xNDQuMiIsInVwZGF0ZWRJblZlciI6IjM1LjE0NC4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feature: stdin / stdout
3 participants