Skip to content

Commit 60010ba

Browse files
author
Andrei Canta
authored
Merge pull request #7 from StackerHQ/shell-command
add shell command
2 parents a9bf7cd + 7b449bc commit 60010ba

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/commands/shell.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import inquirer from 'inquirer';
2+
3+
import { StackConfig, StackManager } from 'stacker-core';
4+
5+
6+
async function getServiceName(stack) {
7+
const choices = stack.services.values().filter(service => service.shell).map(service => service.name);
8+
const answers = await inquirer.prompt({
9+
type: 'list',
10+
name: 'service',
11+
message: 'Select service',
12+
choices,
13+
});
14+
return answers.service;
15+
}
16+
17+
async function handle(args, options, logger) {
18+
const config = await StackConfig.loadRecursive(process.cwd());
19+
const manager = new StackManager(config);
20+
const service = args.service || await getServiceName(manager.stack);
21+
22+
try {
23+
manager.shell(service);
24+
} catch (error) {
25+
logger.info(error.message);
26+
}
27+
}
28+
29+
function register(program) {
30+
program
31+
.command('shell', 'Open shell')
32+
.alias('sh')
33+
.argument('[service]', 'Service name')
34+
.action(handle);
35+
}
36+
37+
export default { register };

src/stacker.js

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import run from './commands/run';
1515
import start from './commands/start';
1616
import stop from './commands/stop';
1717
import unlink from './commands/unlink';
18+
import shell from './commands/shell';
1819

1920

2021
// caporal hack
@@ -39,5 +40,6 @@ run.register(program);
3940
start.register(program);
4041
stop.register(program);
4142
unlink.register(program);
43+
shell.register(program);
4244

4345
program.parse(process.argv);

0 commit comments

Comments
 (0)