Skip to content

Commit

Permalink
feat(cli): add --quiet / -q option
Browse files Browse the repository at this point in the history
Stops any successful output. Errors are still outputted.
  • Loading branch information
aarondill committed Jan 21, 2023
1 parent 3b32e04 commit 9f76548
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ $ sort-package-json "**/package.json" --check
# 2 of 5 matched files are not sorted.
```

#### `--quiet` flag

In order to silence any successful output, you can run CLI with the `--quiet` flag (or `-q`). This will stop the CLI from outputting if it runs successfully, but will still display errors if they occur. Exit codes will not change.

```bash
$ sort-package-json "**/package.json" --check --quiet
$ sort-package-json "**/package.json" --quiet
```

## API

### Install
Expand Down
4 changes: 4 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import { globbySync } from 'globby'
import sortPackageJson from './index.js'

const isCheckFlag = (argument) => argument === '--check' || argument === '-c'
const isQuietFlag = (argument) => argument === '--quiet' || argument === '-q'

const cliArguments = process.argv.slice(2)
const isCheck = cliArguments.some(isCheckFlag)
const isQuiet = cliArguments.some(isQuietFlag)

const patterns = cliArguments.filter((argument) => !isCheckFlag(argument))

Expand All @@ -21,6 +23,8 @@ if (files.length === 0) {
process.exit(1)
}

if (isQuiet) console.log = function () {}

let notSortedFiles = 0

files.forEach((file) => {
Expand Down

0 comments on commit 9f76548

Please sign in to comment.