Skip to content

Commit

Permalink
fix parsing of boolean options that use 'true' as the default.
Browse files Browse the repository at this point in the history
Using `_ || true` will always evaluate to true, and as such, the
option can never be set to false.
  • Loading branch information
darora committed Aug 5, 2021
1 parent dba89d8 commit 5db701e
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ import fs from 'fs';
import {keyboardFunction} from './keyboard';
import path from 'path';

function getBoolWithDefault(key: string, defaultVal: boolean): boolean {
const val = core.getInput(key);
if (val === '') {
return defaultVal;
}
return !!val;
}

async function run() {
const host: string = core.getInput('host') || 'localhost';
const username: string = core.getInput('username');
Expand All @@ -14,13 +22,13 @@ async function run() {
const password: string = core.getInput('password');
const passphrase: string = core.getInput('passphrase');
const tryKeyboard: boolean = !!core.getInput('tryKeyboard');
const verbose: boolean = !!core.getInput('verbose') || true;
const recursive: boolean = !!core.getInput('recursive') || true;
const verbose: boolean = getBoolWithDefault('verbose', true);
const recursive: boolean = getBoolWithDefault('recursive', true);
const concurrency: number = +core.getInput('concurrency') || 1;
const local: string = core.getInput('local');
const dotfiles: boolean = !!core.getInput('dotfiles') || true;
const dotfiles: boolean = getBoolWithDefault('dotfiles', true);
const remote: string = core.getInput('remote');
const rmRemote: boolean = !!core.getInput('rmRemote') || false;
const rmRemote: boolean = getBoolWithDefault('rmRemote', false);
const atomicPut: string = core.getInput('atomicPut');

if (atomicPut) {
Expand Down

0 comments on commit 5db701e

Please sign in to comment.