Skip to content

Commit ede69ed

Browse files
committed
add --no-template option and default-template global config option
1 parent b90f7aa commit ede69ed

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

src/cli/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ commander
1515
.option("-f, --force", "ignore existent directories")
1616
.option("-d, --contest-dirname-format <format>", "specify the format to name contest directory. defaults to \"{ContestID}\"")
1717
.option("-t, --task-dirname-format <format>", "specify the format to name task directories. defaults to \"{tasklabel}\"")
18-
.option("--template <name>", "specify the provisioning template")
1918
.option("--no-tests", "skip downloading sample cases by using online-judge-tools")
19+
.option("--template <name>", "specify the provisioning template")
20+
.option("--no-template", "do not use templates, even if specified by global config")
2021
.description("create new contest project directory")
2122
.on("--help", function () {
2223
console.log("");
@@ -36,8 +37,9 @@ commander
3637
.option('-c, --choice <choice>', "how to choice tasks to add", /^(inquire|all|none|rest|next)$/i)
3738
.option("-f, --force", "ignore existent directories")
3839
.option("-t, --task-dirname-format <format>", "specify the format to name task directories. defaults to \"{tasklabel}\"")
39-
.option("--template <name>", "specify the provisioning template")
4040
.option("--no-tests", "skip downloading sample cases by using online-judge-tools")
41+
.option("--template <name>", "specify the provisioning template")
42+
.option("--no-template", "do not use templates, even if specified by global config")
4143
.description("add new directory for the task in the project directory")
4244
.on("--help", function () {
4345
console.log("");

src/commands.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ function checkValidChoiceOption(choice: any): choice is Choices {
317317
return false;
318318
}
319319

320-
export async function setup(contest_id: string, options: { choice: Choices, force?: boolean, contestDirnameFormat?: string, taskDirnameFormat?: string, template?: string, tests?: boolean }) {
320+
export async function setup(contest_id: string, options: { choice: Choices, force?: boolean, contestDirnameFormat?: string, taskDirnameFormat?: string, template?: string | boolean, tests?: boolean }) {
321321
try {
322322
const {contest} = await init(contest_id, options);
323323
console.log(`create project of ${contest.title}`);
@@ -327,7 +327,7 @@ export async function setup(contest_id: string, options: { choice: Choices, forc
327327
}
328328
}
329329

330-
export async function add(options: { choice?: Choices | boolean, force?: boolean, taskDirnameFormat?: string, template?: string, tests?: boolean }) {
330+
export async function add(options: { choice?: Choices | boolean, force?: boolean, taskDirnameFormat?: string, template?: string | boolean, tests?: boolean }) {
331331
try {
332332
const {path, data} = await findProjectJSON();
333333
const {contest, tasks} = data;
@@ -344,9 +344,17 @@ export async function add(options: { choice?: Choices | boolean, force?: boolean
344344
}
345345
return await selectTasks(tasks, c, options.force);
346346
})(options.choice);
347-
const template = options.template !== undefined ? (await getTemplate(options.template).catch((e) => {
348-
throw new Error(`Failed to load template "${options.template}".\n ${e}`);
349-
})) : undefined;
347+
const template = await (async t => {
348+
// --no-templateオプションが指定された場合は何も選ばない
349+
if (t === false) return undefined;
350+
// 未指定の場合はコンフィグよりデフォルト値を取得
351+
if (t === undefined || t === true) t = (await getConfig()).get("default-template") as string | undefined;
352+
// デフォルト値も指定されていなければ何も選ばない
353+
if (t === undefined) return undefined;
354+
return await getTemplate(t).catch((e) => {
355+
throw new Error(`Failed to load template "${t}".\n ${e}`);
356+
});
357+
})(options.template);
350358
// 更新があった問題の数を数えておく
351359
let count = 0;
352360
for (const {index, task} of choices) {

src/config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ export const defaults = {
77
["default-contest-dirname-format"]: "{ContestID}",
88
["default-task-dirname-format"]: "{tasklabel}",
99
["default-test-dirname-format"]: "tests",
10-
["default-task-choice"]: "inquire"
10+
["default-task-choice"]: "inquire",
11+
["default-template"]: undefined
1112
};
1213

1314
/**

0 commit comments

Comments
 (0)