Skip to content

Commit

Permalink
--name exits with non-zero status if object isn't found
Browse files Browse the repository at this point in the history
closes #23
  • Loading branch information
phette23 committed Dec 1, 2023
1 parent 1b24c05 commit e9bb105
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 11 deletions.
2 changes: 1 addition & 1 deletion endpoints.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,5 +130,5 @@ Shortcuts: user, users

```sh
# look up user by (case sensitive) name
eq user --name 'xsun1' # -q also works
eq user --name 'phette23' # -q also works
```
3 changes: 2 additions & 1 deletion endpoints/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ export default function (options) {
handle(err, data)

if (data.results.length === 0) {
return console.error('Unable to find', options.name, 'in list of users')
console.error(`Unable to find "${options.name}" in list of users`)
return process.exit(1)
}

// only print 1st result
Expand Down
13 changes: 4 additions & 9 deletions lib/find-by-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ export function findByName(options) {
options.querystring.length = 5000

// support usage like eq tax --name 'Taxo to delete' --method del
if (options.method !== 'get') {
options.original_method = options.method
options.method = 'get'
}
options.original_method = options.method
options.method = 'get'

req(options, function(err, resp, data) {
handle(err, data)
Expand All @@ -27,11 +25,8 @@ export function findByName(options) {
})[0]

if (object === undefined) {
return console.error(
'Unable to find %s in list of %s',
options.name,
plural(options.endpoint)
)
console.error(`Unable to find "${options.name}" in list of ${plural(options.endpoint)}`)
return process.exit(1)
} else {
let newOpts = options
delete newOpts.querystring // no longer needed, we found the object
Expand Down

0 comments on commit e9bb105

Please sign in to comment.