Skip to content

Commit

Permalink
Refine examples
Browse files Browse the repository at this point in the history
  • Loading branch information
alexcanessa committed Sep 24, 2017
1 parent 44fbd9e commit 224244c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ If you don't want to save the token, you can specify one as an option:
gren release --token=[your token]
```

### [See all the options here](https://github-tools.github.io/github-release-notes/options.html)

### Commands

There are two main commands that can be ran with 🤖:
Expand Down Expand Up @@ -178,6 +180,12 @@ gren --help
gren help release # or gren release --help
```

It's also possible to see all the examples [here](https://github-tools.github.io/github-release-notes/examples.html) or directly in the terminal:

```shell
gren examples release
```

## Configuration file

You can create a configuration file where the task will be ran, where to specify your options. [See how to set up the config file](https://github-tools.github.io/github-release-notes/options.html#configuration-file)
Expand Down
13 changes: 5 additions & 8 deletions lib/_examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,25 @@ const chalk = require('chalk');
*/
function generateExamples(title, examples) {
process.stdout.write(`\n Examples for ${title}:`);
const spaceify = number => new Array(number ? number + 1 : 0).join(' ');
const spaceify = number => new Array(!number || number < 0 ? 0 : number + 1).join(' ');
const spaces = spaceify(6);
const namePlaceholder = spaceify(Math.max(...examples.map(({ name }) => name ? name.length : 0)));
const descriptionPlaceholder = spaceify(Math.max(...examples.map(({ description }) => description ? description.length : 0)));

examples.forEach(({ name, description, code }) => {
const tabs = spaceify(description && descriptionPlaceholder.length - description.length);
const tabs = spaceify(descriptionPlaceholder.length - (description ? description.length : 0));

if (name) {
process.stdout.write(`\n\n ${chalk.blue(name)}:\n`);
} else {
process.stdout.write(namePlaceholder);
}

if (description) {
process.stdout.write(`\n ${description}`);
process.stdout.write(`\n${spaces}${description}`);
} else {
process.stdout.write(descriptionPlaceholder);
process.stdout.write(spaces);
}

if (code) {
process.stdout.write(`${spaces}${tabs}${chalk.green(`[ ${code} ]`)}\n`);
process.stdout.write(`${tabs}${spaces}${chalk.green(`$ ${code}`)}\n`);
}
});
}
Expand Down
9 changes: 9 additions & 0 deletions lib/gren-examples.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ gren
.name('gren examples')
.description(`See few examples for how to use gren. For more informations (and a bit of UI) check ${chalk.blue('https://github-tools.github.io/github-release-notes/examples.html')}`)
.usage('<command>')
.on('--help', () => {
console.log('');
console.log(' Commands:');
console.log('');
console.log(' $ gren examples gren');
console.log(' $ gren examples release');
console.log(' $ gren examples changelog');
console.log('');
})
.action(cmd => {
command = cmd;
})
Expand Down

0 comments on commit 224244c

Please sign in to comment.