Skip to content

Commit

Permalink
Support setting a string parameter to the empty string.
Browse files Browse the repository at this point in the history
Signed-off-by: Eric Promislow <[email protected]>
  • Loading branch information
ericpromislow committed Apr 14, 2022
1 parent 1f50e9f commit ecbeab9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion src/config/__tests__/settings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,15 @@ describe('updateFromCommandLine', () => {

expect(newPrefs.kubernetes.options.traefik).toBeFalsy();
newPrefs.kubernetes.options.traefik = true;
expect(newPrefs).toMatchObject(origPrefs);
expect(newPrefs).toEqual(origPrefs);
});

test('nothing after an = should set target to empty string', () => {
const newPrefs = settings.updateFromCommandLine(prefs, ['--images-namespace=']);

expect(newPrefs.images.namespace).toBe('');
newPrefs.images.namespace = origPrefs.images.namespace;
expect(newPrefs).toEqual(origPrefs);
});

test('should change several values (and no others)', () => {
Expand Down
4 changes: 2 additions & 2 deletions src/config/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,12 @@ export function updateFromCommandLine(cfg: Settings, args: string[]): Settings {
throw new Error(`Can't overwrite existing setting ${ arg } in current settings at ${ join(paths.config, 'settings.json') }`);
case 'boolean':
// --some-boolean-setting ==> --some-boolean-setting=true
if (!value) {
if (value === undefined) {
finalValue = 'true'; // JSON.parse to boolean `true` a few lines later.
}
break;
default:
if (!value) {
if (value === undefined) {
if (i === lim - 1) {
throw new Error(`No value provided for option ${ arg } in command-line [${ args.join(' ') }]`);
}
Expand Down

0 comments on commit ecbeab9

Please sign in to comment.