## Modules

<dl>
<dt><a href="#module_cli">cli</a> : <code>object</code></dt>
<dd><p>CLI parser based on <a href="https://github.com/tj/commander.js/">commander</a>
with some additions and overrides.</p>
</dd>
<dt><a href="#module_error">error</a> : <code>object</code></dt>
<dd><p>Create the new instance of the CommandError object,
ensuring that it properly extends from the Error class.</p>
</dd>
<dt><a href="#module_log">log</a> : <code>object</code></dt>
<dd><p>Shared logging system based on the default <a href="https://github.com/npm/npmlog">npmlog</a> system.</p>
</dd>
<dt><a href="#module_sh">sh</a> : <code>object</code></dt>
<dd><p>Portable (Windows/Linux/OS X) implementation of Unix shell commands
based on <a href="https://github.com/shelljs/shelljs">shelljs</a></p>
</dd>
<dt><a href="#module_ui">ui</a> : <code>object</code></dt>
<dd><p>User Interface for the terminal (Prompting / Styles / Spinners / Progress)</p>
</dd>
<dt><a href="#module_utils">utils</a> : <code>object</code></dt>
<dd><p>Set of utilities.</p>
</dd>
</dl>

<a name="module_cli"></a>

## cli : <code>object</code>
CLI parser based on [commander](https://github.com/tj/commander.js/)
with some additions and overrides.

**Link**: https://github.com/tj/commander.js/  
**Example**  
Create a main command with 3 sub-commands:

``` javascript
import { cli } from '@bb-cli/base';

cli.version('0.0.1')
  .command('install [...packages]', 'install one or more packages')
  .command('search [query]', 'search with optional query')
  .command('list', 'list packages installed', {isDefault: true})
  .parse(process.argv);
```

Create the `install` sub-command:

``` javascript
import { cli } from '@bb-cli/base';

cli
  .description('Install package from registry')
  .arguments('[...packages]', 'install one or more packages')
  .option('-f, --force [force]', 'force installation ', false)
  .option('-r, --registry [registry]', 'registry host ')
  .alias('i')
  .man( path.resolve(__dirname, '../../man/install.md'))
  .parse(process.argv);

let packages = cli.args; // get the packages as variadic arguments
let force = cli.force  // get the force option
```
<a name="module_error"></a>

## error : <code>object</code>
Create the new instance of the CommandError object,
ensuring that it properly extends from the Error class.

**Example**  
Setting up the log header:

```javascript
import { error } from '@bb-cli/base';

const out = sh.exec('ls', { silent: true });
if (out.code !== 0) {
  throw error({
    type: 'Shell.Exec',
    code: out.code,
    message: out.stderr.trim(),
  });
}
```
<a name="module_log"></a>

## log : <code>object</code>
Shared logging system based on the default [npmlog](https://github.com/npm/npmlog) system.

**Link**: https://github.com/npm/npmlog  
**Example**  
Setting up the log header:

```javascript
import { log } from '@bb-cli/base';
import { name as packageName } from './package.json';
log.heading = `[${packageName}]`;
```
Basic commands:

```javascript
log.silly(prefix, message, ...)
log.verbose(prefix, message, ...)
log.info(prefix, message, ...)
log.http(prefix, message, ...)
log.warn(prefix, message, ...)
log.error(prefix, message, ...)
```

Setting up the global env LOG_LEVEL:

```bash
LOG_LEVEL=verbose bb-my-command
```
<a name="module_sh"></a>

## sh : <code>object</code>
Portable (Windows/Linux/OS X) implementation of Unix shell commands
based on [shelljs](https://github.com/shelljs/shelljs)

**Link**: https://github.com/shelljs/shelljs  
**Example**  
Basic Example

```javascript
import { sh } from '@bb-cli/base';
sh.ls(`./`)
// or
sh.exec(`ls ./`, function(exitCode, stdOut, stdErr) {
    log.verbose('cmd exitcode:', exitCode);
    log.verbose('cmd output:', stdOut);
    log.verbose('cmd stderr:', stdErr);
});
```
<a name="module_ui"></a>

## ui : <code>object</code>
User Interface for the terminal (Prompting / Styles / Spinners / Progress)


* [ui](#module_ui) : <code>object</code>
    * [.prompt](#module_ui.prompt) ⇒ <code>Promise</code>
    * [.colors](#module_ui.colors) : <code>object</code>
        * [.defaultTheme](#module_ui.colors.defaultTheme) : <code>enum</code>

<a name="module_ui.prompt"></a>

### ui.prompt ⇒ <code>Promise</code>
Create a self contained [inquirer](https://github.com/sboudrias/Inquirer.js)
module via `inquirer.createPromptModule` method.

**Kind**: static constant of <code>[ui](#module_ui)</code>  
**Access:** public  
**Link**: https://github.com/sboudrias/Inquirer.js  

| Param | Type | Description |
| --- | --- | --- |
| questions | <code>array</code> &#124; <code>object</code> | A collection of inquirer questions |

**Example**  
Basic example:

```javascript
import { ui } from '@bb-cli/base';
const questions = [{
  type: 'input',
  name: 'name',
  message: 'Who are you?',
  default: 'Guest',
  validate: value => true,
  filter: value => value,
}];

ui.prompt(questions).then( answers => {
    // do something with the answers here.
})
```
<a name="module_ui.colors"></a>

### ui.colors : <code>object</code>
Colors styles console based on [colors](https://github.com/Marak/colors.js)

**Kind**: static constant of <code>[ui](#module_ui)</code>  
**Access:** public  
**Link**: https://github.com/Marak/colors.js  
**Example**  
Basic example:

```javascript
import { ui } from '@bb-cli/base';
let logInfo = ui.colors.info('Some info style output');
log.verbose(`Show ${logInfo}`);
```
Custom heading style:

```javascript
let logHead = ui.colors.heading('Some bold white heading');
log.info(logHead);
```
<a name="module_ui.colors.defaultTheme"></a>

#### colors.defaultTheme : <code>enum</code>
Colors default styles

**Kind**: static constant of <code>[colors](#module_ui.colors)</code>  
**Properties**

| Name | Type | Default |
| --- | --- | --- |
| silly | <code>object</code> | <code>rainbow</code> | 
| input | <code>object</code> | <code>grey</code> | 
| verbose | <code>object</code> | <code>cyan</code> | 
| prompt | <code>object</code> | <code>grey</code> | 
| info | <code>object</code> | <code>[&quot;green&quot;,&quot;underline&quot;]</code> | 
| data | <code>object</code> | <code>grey</code> | 
| help | <code>object</code> | <code>cyan</code> | 
| warn | <code>object</code> | <code>yellow</code> | 
| debug | <code>object</code> | <code>blue</code> | 
| error | <code>object</code> | <code>red</code> | 
| heading | <code>object</code> | <code>[&quot;white&quot;,&quot;bold&quot;]</code> | 

<a name="module_utils"></a>

## utils : <code>object</code>
Set of utilities.


* [utils](#module_utils) : <code>object</code>
    * [.md2html(mdStr)](#module_utils.md2html) ⇒ <code>string</code>
    * [.md2term(mdStr)](#module_utils.md2term) ⇒ <code>string</code>

<a name="module_utils.md2html"></a>

### utils.md2html(mdStr) ⇒ <code>string</code>
Converts markdown to html output

**Kind**: static method of <code>[utils](#module_utils)</code>  
**Returns**: <code>string</code> - html string  

| Param | Type | Description |
| --- | --- | --- |
| mdStr | <code>string</code> | Markdown content string |

**Example**  
Basic Example

```javascript
const htmlStr = utils.md2html(fs.readFileSync('some-markdown-file.md', 'utf8').toString());
```
<a name="module_utils.md2term"></a>

### utils.md2term(mdStr) ⇒ <code>string</code>
**Kind**: static method of <code>[utils](#module_utils)</code>  
**Todo**

- [ ] Make it work with colors instead of ansi-styles


| Param | Type | Description |
| --- | --- | --- |
| mdStr | <code>string</code> | markdown content string |

**Example**  
Basic Example

```javascript
const termMdOut = utils.md2term(fs.readFileSync('some-markdown-file.md', 'utf8').toString());
```
