Skip to content

Commit

Permalink
--cwd CLI option (#347)
Browse files Browse the repository at this point in the history
  • Loading branch information
jbolda authored Jul 13, 2024
1 parent b38fa8e commit ef274be
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changes/cwd-cli-option.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"covector": patch:enhance
---

Add `cwd` option to pass to the CLI. Useful for local development, at minimum.
13 changes: 12 additions & 1 deletion packages/covector/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { pino } from "pino";
import logStream from "./logger";

export function* cli(argv: readonly string[]): Generator<any, any, any> {
const { command, directory, yes, dryRun } = parseOptions(argv);
const { command, directory, yes, dryRun, cwd } = parseOptions(argv);
const stream = logStream();
const logger = pino(stream);
return yield covector({
Expand All @@ -13,6 +13,7 @@ export function* cli(argv: readonly string[]): Generator<any, any, any> {
changeFolder: directory,
yes,
dryRun,
cwd,
});
}

Expand All @@ -21,6 +22,7 @@ function parseOptions(argv: readonly string[]): {
dryRun: boolean;
yes?: boolean;
directory?: string;
cwd: string;
} {
let rawOptions = yargs
.scriptName("covector")
Expand Down Expand Up @@ -51,6 +53,13 @@ function parseOptions(argv: readonly string[]): {
"run a command that shows the expected command without executing",
},
})
.options({
cwd: {
type: "string",
default: ".",
describe: "context in which to run",
},
})
.demandCommand(1)
.help()
.epilogue(
Expand All @@ -68,5 +77,7 @@ function parseOptions(argv: readonly string[]): {
yes: rawOptions.yes,
// @ts-expect-error
directory: rawOptions.directory,
// @ts-expect-error
cwd: rawOptions.cwd,
};
}

0 comments on commit ef274be

Please sign in to comment.