Skip to content

Commit

Permalink
add --silent flag, and naive subshell detection, implements #160
Browse files Browse the repository at this point in the history
  • Loading branch information
philmillman committed Nov 13, 2024
1 parent beb9c44 commit d610fcb
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
10 changes: 9 additions & 1 deletion packages/core/src/cli/commands/resolve.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ import { addWatchMode } from '../lib/watch-mode-helpers';
import { CliExitError } from '../lib/cli-error';
import { checkForConfigErrors, checkForSchemaErrors } from '../lib/check-errors-helpers';
import { stringifyObjectAsEnvFile } from '../lib/env-file-helpers';
import { isSubshell } from '../lib/shell-helpers';

const program = new DmnoCommand('resolve')
.summary('Loads config schema and resolves config values')
.description('Loads the resolved config for a service')
.option('-f,--format <format>', 'format to output resolved config (ex. json)')
.option('--public', 'only loads public (non-sensitive) values')
.option('--show-all', 'shows all items, even when config is failing')
.option('--silent', 'automatically select defaults and do not prompt for any input')
.example('dmno resolve', 'Loads the resolved config for the root service')
.example('dmno resolve --service service1', 'Loads the resolved config for service1')
.example('dmno resolve --service service1 --format json', 'Loads the resolved config for service1 in JSON format')
Expand All @@ -43,12 +45,18 @@ program.action(async (opts: {
format?: string,
public?: boolean,
showAll?: boolean,
silent?: boolean,
}, thisCommand) => {
const ctx = getCliRunCtx();

const isSilent = !!opts.silent || isSubshell();
// console.log('isSilent', isSilent);
// console.log('subshell', isSubshell());

if (opts.format) ctx.expectingOutput = true;

if (!ctx.selectedService) return; // error message already handled
if (!ctx.selectedService && !isSilent) return; // error message already handled


ctx.log(`\nResolving config for service ${kleur.magenta(ctx.selectedService.serviceName)}\n`);

Expand Down
15 changes: 15 additions & 0 deletions packages/core/src/cli/lib/shell-helpers.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { execSync, spawn } from 'child_process';
import { expect, test, describe } from 'vitest';
import { isSubshell } from './shell-helpers';

describe('isSubshell', () => {
test('basic', () => {
expect(isSubshell()).toBe(false);
});
test('subshell', () => {
const child = spawn('bash', ['-c', 'echo $PPID $(echo $PPID)']);
child.stdout.on('data', () => {
expect(isSubshell()).toBe(true);
});
});
});
1 change: 1 addition & 0 deletions packages/core/src/cli/lib/shell-helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const isSubshell = () => (process.env.BASH_SUBSHELL && process.env.BASH_SUBSHELL !== '0') || false;

0 comments on commit d610fcb

Please sign in to comment.