Skip to content

Commit 704231a

Browse files
update docs, change doc generation script to include sub commands
1 parent 63fe9d1 commit 704231a

File tree

12 files changed

+228
-161
lines changed

12 files changed

+228
-161
lines changed

DOCS.md

+173-113
Large diffs are not rendered by default.

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ Add a few lines to your `package.json`. Your [account id](https://console.aws.am
5252
5353
### Environments
5454
55-
Environments for a shep project are defined by the aliases on the functions associated with a project. Environments are created through `shep deploy --env new_env` and managed by using the `shep config` commands. Shep takes a strong stance against having different environments for different functions. If shep detects that some of your functions have different aliases, it will immediately error until you remedy the issue. Most issues can be automatically fixed by using `shep config sync`, the only issues this can't solve are conflicting environment variable values. Conflicting value issues can be solved by using `shep config set my_env CONFLICT_VARIABLE=value`.
55+
Environments for a shep project are defined by the aliases on the functions associated with a project. Environments are created through `shep deploy --env new_env` and managed by using the `shep config` commands. Shep takes a strong stance against having different environments for different functions within a project. If you attempt a command which requires the listing of environments and there is a mismatch detected, then shep will throw a `EnvironmentMistmach` error until you remedy the issue. Most issues can be automatically fixed by using `shep config sync`, the only issues this can't solve are conflicting environment variable values. Conflicting value issues can be solved by using `shep config set my_env CONFLICT_VARIABLE=value`.
5656

5757
### Custom Builds Commands
5858

docs.js

+26-13
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,36 @@
1-
const shep = require('./lib/index')
21
const { execSync } = require('child_process')
2+
const { readdirSync, statSync } = require('fs')
33

44
console.log(`### \`shep\``)
55
console.log('```')
66
console.log(execSync(`./cli.js --help`).toString().replace(/cli\.js/, 'shep').trim())
77
console.log('```')
88

9-
for (var cmd in shep) {
10-
if (cmd !== 'version') {
11-
let help = execSync(`./cli.js ${camelCaseToSpace(cmd)} --help`).toString().replace(/cli\.js/, 'shep').trim()
12-
console.log(`#### \`shep ${camelCaseToSpace(cmd)}\``)
13-
console.log('```')
14-
console.log(help)
15-
console.log('```')
16-
}
9+
const commandDir = './src/commands'
10+
const mainCommands = readdirSync(commandDir)
11+
const subCommands = mainCommands
12+
.filter(isDir)
13+
.map(findSubCommands)
14+
.reduce(flatten)
15+
const allCommands = mainCommands.concat(subCommands).map((c) => c.replace(/\.js/g, '')).sort()
16+
17+
allCommands.forEach((command) => {
18+
let help = execSync(`./cli.js ${command} --help`).toString().replace(/cli\.js/, 'shep').trim()
19+
console.log(`#### \`shep ${command}\``)
20+
console.log('```')
21+
console.log(help)
22+
console.log('```')
23+
})
24+
25+
function isDir (path) {
26+
return statSync(`${commandDir}/${path}`).isDirectory()
27+
}
28+
29+
function findSubCommands (path) {
30+
return readdirSync(`${commandDir}/${path}`)
31+
.map((c) => `${path} ${c}`)
1732
}
1833

19-
function camelCaseToSpace (str) {
20-
return str.split('')
21-
.map(x => /[A-Z]/.test(x) ? ` ${x.toLowerCase()}` : x)
22-
.reduce((sum, cur) => sum + cur, '')
34+
function flatten (acc, arr) {
35+
return acc.concat(arr)
2336
}

migration.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,4 @@ json, and it should live inside the `/environments` directory
8282

8383
## Migrating from shep 3.X to shep 4.0
8484

85-
- Shep 4.0 now handles environment variables in AWS. See the docs for `shep config` to add, remove, list, and sync environment variables for your functions.
85+
- Shep 4.0 now handles environment variables in the configuration of AWS Lambda Functions. If you have no undeployed changes in your `/environments` directory, then you should be able to safely delete the directory and use your exisiting project with shep `4.0.0`. See the docs for `shep config` to add, remove, list, and sync environment variables for your functions.

src/commands/config/dump.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ import configDump from '../../config-dump'
33
import * as load from '../../util/load'
44
import merge from 'lodash.merge'
55

6-
export const command = 'dump [env]'
6+
export const command = 'dump'
77
export const desc = 'Prints all common environmental variables and differences'
88
export function builder (yargs) {
99
return yargs
1010
.pkgConf('shep', process.cwd())
1111
.boolean('json')
12+
.describe('env', 'Specifies which environment to dump, if not provided an interactive menu will display the options')
1213
.describe('json', 'Formats output as JSON')
13-
.example('shep config dump beta', 'Print to console all environment variables of environment `beta` in JSON format')
14+
.example('shep config dump --env beta', 'Print to console all environment variables of environment `beta` in JSON format')
1415
}
1516

1617
export async function handler (opts) {

src/commands/config/list.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ import configList from '../../config-list'
33
import * as load from '../../util/load'
44
import merge from 'lodash.merge'
55

6-
export const command = 'list [env] [function]'
6+
export const command = 'list [function]'
77
export const desc = 'List environment variables on AWS for an alias'
88
export function builder (yargs) {
99
return yargs
1010
.pkgConf('shep', process.cwd())
11-
.example('shep config beta foo', 'List environment variables for function "foo" beta alias')
11+
.describe('env', 'Specifies which environment. If not provided an interactive menu will display the options')
12+
.example('shep config list --env beta foo', 'List environment variables for function "foo" beta alias')
1213
}
1314

1415
export async function handler (opts) {

src/commands/config/remove.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ import configRemove from '../../config-remove'
33
import * as load from '../../util/load'
44
import merge from 'lodash.merge'
55

6-
export const command = 'remove <env> <vars...>'
6+
export const command = 'remove <vars...>'
77
export const desc = 'Remove environment variables for alias on AWS'
88
export function builder (yargs) {
99
return yargs
1010
.pkgConf('shep', process.cwd())
11-
.example('shep config remove beta NEW_VARIABLE', 'Removes NEW_VARIABLE from all functions with beta alias')
11+
.describe('env', 'Specifies which environment to remove variables from. If not provided an interactive menu will display the options')
12+
.example('shep config remove --env beta NEW_VARIABLE', 'Removes NEW_VARIABLE from all functions with beta alias')
1213
}
1314

1415
export async function handler (opts) {
@@ -27,9 +28,7 @@ export async function handler (opts) {
2728
inquirer.prompt(questions.filter((q) => !opts[q.name]))
2829
.then((inputs) => merge({}, inputs, opts))
2930
.then(configRemove)
30-
} else {
31-
if (!opts.env) { console.log('no API found, cannot load available aliases') }
32-
33-
configRemove(opts)
31+
} else if (!opts.env) {
32+
throw new Error('Unable to load environments, please provide a specific one via the --env flag')
3433
}
3534
}

src/commands/config/set.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import configSet from '../../config-set'
33
import * as load from '../../util/load'
44
import merge from 'lodash.merge'
55

6-
export const command = 'set <env> <vars...>'
6+
export const command = 'set <vars...>'
77
export const desc = 'Set environment variables for alias on AWS'
88
export function builder (yargs) {
99
return yargs
1010
.pkgConf('shep', process.cwd())
11-
.example('shep config set beta FOO=bar', 'Set environment variable FOO with value BAR for alias beta')
11+
.example('shep config set --env beta FOO=bar', 'Set environment variable FOO with value BAR for alias beta')
1212
}
1313

1414
export async function handler (opts) {

src/commands/logs.js

+7-16
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ import logs from '../logs'
33
import * as load from '../util/load'
44
import merge from 'lodash.merge'
55

6-
export const command = 'logs [stage] [name]'
6+
export const command = 'logs [name]'
77
export const desc = 'Streams logs from the specified version of a function'
88
export function builder (yargs) {
99
return yargs
1010
.pkgConf('shep', process.cwd())
11-
.describe('stage', 'Name of stage to use')
11+
.describe('env', 'Specifies which environment to use. If not provided an interactive menu will display the options.')
1212
.describe('name', 'Name of function to use')
1313
.describe('region', 'Name of region to use, uses region in `package.json` if not given')
1414
.boolean('stream')
1515
.default('stream', true)
1616
.describe('stream', 'Stream logs')
1717
.example('shep logs', 'Launch an interactive CLI')
18-
.example('shep logs production foo', 'Shows logs for the `foo` function in the production environment')
18+
.example('shep logs --env production foo', 'Shows logs for the `foo` function in the production environment')
1919
}
2020

2121
export async function handler (opts) {
@@ -25,8 +25,8 @@ export async function handler (opts) {
2525
if (envs && envs.length > 0) {
2626
questions = [
2727
{
28-
name: 'stage',
29-
message: 'Stage',
28+
name: 'env',
29+
message: 'Environment',
3030
type: 'list',
3131
choices: () => envs
3232
},
@@ -37,17 +37,8 @@ export async function handler (opts) {
3737
choices: () => load.funcs()
3838
}
3939
]
40-
} else {
41-
if (!opts.env) { console.log('no API found, cannot load available aliases') }
42-
43-
questions = [
44-
{
45-
name: 'name',
46-
message: 'Function',
47-
type: 'list',
48-
choices: () => load.funcs()
49-
}
50-
]
40+
} else if (!opts.env) {
41+
throw new Error('Unable to load environments, please provide a specific one via the --env flag')
5142
}
5243

5344
inquirer.prompt(questions.filter((q) => !opts[q.name]))

src/logs/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import genName from '../util/generate-name'
88

99
export default function (opts) {
1010
const functionName = genName(opts.name).fullName
11-
const aliasName = opts.stage
11+
const aliasName = opts.env
1212
const stream = opts.stream
1313
const region = opts.region || pkg().shep.region
1414

src/util/load.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ export async function envs () {
2020
.concat(acc.filter((alias) => aliasSet.indexOf(alias) === -1))
2121

2222
if (missingAliases.length !== 0) {
23-
throw new Error('Mismatched aliases found, please run `shep config sync` to ensure all functions have the same environment')
23+
const err = new Error('Mismatched aliases found, please run `shep config sync` to ensure all functions have the same environment')
24+
err.name = 'EnvironmentMistmach'
25+
throw err
2426
}
2527

2628
return acc

test/commands/index.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ test([allFlags, noFlags], 'doctor', doctorParser, doctorArgs)
5252
td.replace('../../src/logs')
5353
const logsParser = yargs.command(require('../../src/commands/logs'))
5454
const logsArgs = {
55-
stage: 'development',
55+
env: 'development',
5656
name: 'myfunction',
5757
region: 'mordor',
5858
stream: 'true'
@@ -129,7 +129,7 @@ td.replace('../../src/config-remove')
129129
const removeParser = yargs.command(require('../../src/commands/config/remove'))
130130

131131
test('config remove command', (t) => {
132-
removeParser.parse('remove development MY_KEY OTHER_KEY', (err, argv, output) => {
132+
removeParser.parse('remove --env development MY_KEY OTHER_KEY', (err, argv, output) => {
133133
err ? t.fail(err) : t.pass()
134134
})
135135
})
@@ -138,7 +138,7 @@ td.replace('../../src/config-set')
138138
const setParser = yargs.command(require('../../src/commands/config/set'))
139139

140140
test('config set command', (t) => {
141-
setParser.parse('set development FOO=bar', (err, argv, output) => {
141+
setParser.parse('set --env development FOO=bar', (err, argv, output) => {
142142
err ? t.fail(err) : t.pass()
143143
})
144144
})

0 commit comments

Comments
 (0)