Add support for dry-run flag

This commit is contained in:
2025-04-03 00:09:41 +02:00
parent 89b59dee50
commit caf0a96ee0
3 changed files with 5 additions and 3 deletions

View File

@@ -8,6 +8,7 @@ export function run(...args: string[]) {
.name("actual-importer") .name("actual-importer")
.version("0.0.1") .version("0.0.1")
.requiredOption("-c, --config <file>", "sets the path to the YAML file with configuration") .requiredOption("-c, --config <file>", "sets the path to the YAML file with configuration")
.option("-d, --dry-run", "simulates the import by printing out what will be imported")
.option("-p, --profile <name>", "sets the desired profile to invoke") .option("-p, --profile <name>", "sets the desired profile to invoke")
.option("-s, --server <name>", "sets the desired server to upload transactions to") .option("-s, --server <name>", "sets the desired server to upload transactions to")
.option("-x, --set <arg>", "overrides the config option for this specific run (arg: <key>=<name>, i.e. profiles.myprofile.parser=pl.ing", (v: string, prev: string[]) => prev.concat([v]), []) .option("-x, --set <arg>", "overrides the config option for this specific run (arg: <key>=<name>, i.e. profiles.myprofile.parser=pl.ing", (v: string, prev: string[]) => prev.concat([v]), [])
@@ -49,5 +50,5 @@ function handle(file: string, options: CLIOptions) {
const profile = options.profile ?? config.defaultProfile ?? Object.keys(config.profiles)[0]; const profile = options.profile ?? config.defaultProfile ?? Object.keys(config.profiles)[0];
const server = options.server ?? config.defaultServer ?? Object.keys(config.servers)[0]; const server = options.server ?? config.defaultServer ?? Object.keys(config.servers)[0];
loadTransactions(file, profile, server, config); loadTransactions(file, profile, server, config, options.dryRun);
} }

View File

@@ -6,7 +6,7 @@ import { Actual } from "@/server";
import { Config } from "@/types/config"; import { Config } from "@/types/config";
export function loadTransactions(file: string, profile: string, server: string, config: Config) { export function loadTransactions(file: string, profile: string, server: string, config: Config, dryRun?: boolean) {
const profileConfig = config.profiles[profile]; const profileConfig = config.profiles[profile];
if (!profileConfig) { if (!profileConfig) {
throw new Error(`Unknown profile: ${profile}`); throw new Error(`Unknown profile: ${profile}`);
@@ -19,7 +19,7 @@ export function loadTransactions(file: string, profile: string, server: string,
const parser = createParser(profileConfig, serverConfig); const parser = createParser(profileConfig, serverConfig);
const actualServer = new Actual(serverConfig, false); const actualServer = new Actual(serverConfig, dryRun);
const skipped: string[] = []; const skipped: string[] = [];
const handleRow = async (data: string[]) => { const handleRow = async (data: string[]) => {

View File

@@ -1,5 +1,6 @@
export type CLIOptions = { export type CLIOptions = {
config: string; config: string;
dryRun?: boolean;
profile?: string; profile?: string;
server?: string; server?: string;
set: string[]; set: string[];