Github user robertkowalski commented on a diff in the pull request:

    https://github.com/apache/couchdb-nmo/pull/14#discussion_r46948360
  
    --- Diff: src/query.js ---
    @@ -0,0 +1,87 @@
    +import prettyjson from 'prettyjson';
    +import nmo from './nmo.js';
    +import Promise from 'bluebird';
    +import { getUrlFromCluster, sendJsonToNode } from './utils';
    +
    +export function cli (cluster, dbname, ...args) {
    +  return new Promise((resolve, reject) => {
    +    if (!cluster || !dbname || !args) {
    +      const msg = [
    +        'Usage:',
    +        '',
    +        'nmo query cluster database create <fields> [--json]',
    +        'nmo query cluster database selector [--json]',
    +      ].join('\n');
    +
    +      const err = new Error(msg);
    +      err.type = 'EUSAGE';
    +      return reject(err);
    +    }
    +
    +    let promise;
    +
    +    if (args[0] === 'create') {
    +      if (!args[1] || !args[1].length === 0) {
    +        const err = new Error('Please supply one or more fields to be 
indexed');
    +        err.type = 'EUSAGE';
    +        reject(err);
    +      }
    +
    +      const fields = args[1].split(',').map(f => f.trim());
    +      promise = create(cluster, dbname, fields);
    +    } else {
    +      let selector;
    +      try {
    +        eval('selector = ' + args[0]);
    +      } catch (e) {
    +        if (/Unexpected token/.test(e.message)) {
    +          const err = new Error('Incorrect selector, it could be you used 
\" instead of \' for your selector');
    +          err.type = 'EUSAGE';
    +          return reject(err);
    +        }
    +      }
    +      promise = query(cluster, dbname, selector);
    +    }
    +
    +    promise
    +    .then(resp => {
    +      const jsonOut = nmo.config.get('json');
    +
    +      if (jsonOut) {
    +        console.log(resp);
    +      } else {
    +        console.log(prettyjson.render(resp.docs));
    +      }
    +      resolve(resp);
    +    })
    +    .catch(err => {
    +      err.type = 'EUSAGE';
    --- End diff --
    
    i mean not every error is automatically a usage error. eusage is to help 
the user when they used the cli in a wrong way. but errors thrown here could 
also be just bugs when something throws, in this case we want the stacktrace 
with the small note "please copy this log and send it to the issue tracker"


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to