Skip to content

Commit

Permalink
fix: path param in init mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mathio committed Feb 14, 2025
1 parent 6cbb8a3 commit e9aebd9
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions packages/cli/src/cli/cmd/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Ora from "ora";
import { getConfig, saveConfig } from "../utils/config";
import { defaultConfig, LocaleCode, resolveLocaleCode, bucketTypes } from "@lingo.dev/_spec";
import fs from "fs";
import path from "path";
import { spawn } from "child_process";
import _ from "lodash";
import { confirm } from "@inquirer/prompts";
Expand Down Expand Up @@ -67,24 +68,26 @@ export default new InteractiveCommand()
.default("json"),
)
.addOption(
new InteractiveOption("-p, --paths <path...>", "List of paths for the bucket")
new InteractiveOption("-p, --paths [path...]", "List of paths for the bucket")
.argParser((value) => {
if (!value || value.length === 0) return [];
const values = value.includes(",") ? value.split(",") : value.split(" ");

for (const path of values) {
for (const p of values) {
try {
const stats = fs.statSync(path);
const dirPath = path.dirname(p);
const stats = fs.statSync(dirPath);
if (!stats.isDirectory()) {
throw new Error(`${path} is not a directory`);
throw new Error(`${dirPath} is not a directory`);
}
} catch (err) {
throw new Error(`Invalid directory path: ${path}`);
throw new Error(`Invalid path: ${p}`);
}
}

return values;
})
.default("."),
.default([]),
)
.action(async (options) => {
const settings = getSettings(undefined);
Expand All @@ -102,7 +105,9 @@ export default new InteractiveCommand()
newConfig.locale.source = options.source;
newConfig.locale.targets = options.targets;
newConfig.buckets = {
[options.bucket]: options.paths,
[options.bucket]: {
include: options.paths || [],
},
};

await saveConfig(newConfig);
Expand Down

0 comments on commit e9aebd9

Please sign in to comment.