Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/checkout-flag-precedence.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@openfn/cli': patch
---

An explicit `--checkout` or `--no-checkout` on `project deploy` now overrides `OPENFN_NO_CHECKOUT_AFTER_DEPLOY`
6 changes: 3 additions & 3 deletions packages/cli/src/projects/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ export const checkout: CLIOption = {
name: 'checkout',
yargs: {
boolean: true,
default: true,
description:
'Checkout the project after deploying. Use --no-checkout or OPENFN_NO_CHECKOUT_AFTER_DEPLOY=true to skip',
},
ensure: (opts: any) => {
if (process.env.OPENFN_NO_CHECKOUT_AFTER_DEPLOY === 'true') {
opts.checkout = false;
// An explicit --checkout or --no-checkout always beats the env var
if (opts.checkout === undefined) {
opts.checkout = process.env.OPENFN_NO_CHECKOUT_AFTER_DEPLOY !== 'true';
}
},
};
Expand Down
63 changes: 63 additions & 0 deletions packages/cli/test/projects/options.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import test from 'ava';
import yargs from 'yargs';

import { command } from '../../src/projects/deploy';

const ENV = 'OPENFN_NO_CHECKOUT_AFTER_DEPLOY';
const original = process.env[ENV];

test.afterEach.always(() => {
if (original === undefined) {
delete process.env[ENV];
} else {
process.env[ENV] = original;
}
});

// Parsing runs the command handler (ensure), so this returns the final options
const parse = (cmd: string) =>
yargs()
.command(command as any)
.parse(cmd) as any;

test.serial('checkout defaults to true', (t) => {
delete process.env[ENV];
const options = parse('deploy');
t.true(options.checkout);
});

test.serial('env=true with no flag skips checkout', (t) => {
process.env[ENV] = 'true';
const options = parse('deploy');
t.false(options.checkout);
});

test.serial('env=false with no flag checks out', (t) => {
process.env[ENV] = 'false';
const options = parse('deploy');
t.true(options.checkout);
});

test.serial('env=1 (truthy but not "true") with no flag checks out', (t) => {
process.env[ENV] = '1';
const options = parse('deploy');
t.true(options.checkout);
});

test.serial('env=true with --checkout checks out', (t) => {
process.env[ENV] = 'true';
const options = parse('deploy --checkout');
t.true(options.checkout);
});

test.serial('env=false with --no-checkout skips checkout', (t) => {
process.env[ENV] = 'false';
const options = parse('deploy --no-checkout');
t.false(options.checkout);
});

test.serial('env unset with --no-checkout skips checkout', (t) => {
delete process.env[ENV];
const options = parse('deploy --no-checkout');
t.false(options.checkout);
});
Loading