Merge pull request #2 from Seich/init

Added an init command to the CLI.
This commit is contained in:
Sergio Díaz 2017-12-27 21:55:42 -06:00 committed by GitHub
commit b3cbe5c544
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 45 additions and 0 deletions

View File

@ -116,6 +116,51 @@ program
}
});
program
.command('init')
.option(
'-e --endpoint <endpoint>',
'Allows you to set the default endpoint',
null
)
.action(({ endpoint }) => {
const newFile = `# Beau.yml
version: 1${endpoint === null ? `
# endpoint: http://example.com
` : `
endpoint: ${endpoint}
`}
# defaults:
# params:
# userId: 25
# GET /profile: profile
# GET /posts:
# alias: posts
# params:
# order: ASC
# POST /profile:
# alias: save-profile
# headers:
# authentication: Bearer token
# payload:
# name: David
# lastname: Diaz
`;
if (!fs.existsSync('beau.yml')) {
fs.writeFileSync('beau.yml', newFile);
console.info('beau.yml created!');
} else {
console.error('beau.yml already exists.');
}
});
program.parse(process.argv);
if (!program.args.length) program.help();