refactor: streamline task path resolution in commands.js (#948)

- Replaced local `tasksPath` variable assignments with direct calls to `taskMaster.getTasksPath()` for consistency and clarity across multiple command functions.
- This change enhances maintainability by ensuring a single source of truth for task paths, reducing redundancy in path handling logic.
This commit is contained in:
Parthy
2025-07-10 09:25:56 +02:00
committed by GitHub
parent 31d395322f
commit 4bc8029080

View File

@@ -970,6 +970,8 @@ function registerCommands(programInstance) {
const prompt = options.prompt; const prompt = options.prompt;
const useResearch = options.research || false; const useResearch = options.research || false;
const tasksPath = taskMaster.getTasksPath();
// Resolve tag using standard pattern // Resolve tag using standard pattern
const tag = const tag =
options.tag || getCurrentTag(taskMaster.getProjectRoot()) || 'master'; options.tag || getCurrentTag(taskMaster.getProjectRoot()) || 'master';
@@ -1063,6 +1065,7 @@ function registerCommands(programInstance) {
const taskMaster = initTaskMaster({ const taskMaster = initTaskMaster({
tasksPath: options.file || true tasksPath: options.file || true
}); });
const tasksPath = taskMaster.getTasksPath();
// Resolve tag using standard pattern // Resolve tag using standard pattern
const tag = const tag =
@@ -1160,7 +1163,7 @@ function registerCommands(programInstance) {
} }
const result = await updateTaskById( const result = await updateTaskById(
tasksPath, taskMaster.getTasksPath(),
taskId, taskId,
prompt, prompt,
useResearch, useResearch,
@@ -1234,6 +1237,7 @@ function registerCommands(programInstance) {
const taskMaster = initTaskMaster({ const taskMaster = initTaskMaster({
tasksPath: options.file || true tasksPath: options.file || true
}); });
const tasksPath = taskMaster.getTasksPath();
// Resolve tag using standard pattern // Resolve tag using standard pattern
const tag = const tag =
@@ -1333,7 +1337,7 @@ function registerCommands(programInstance) {
} }
const result = await updateSubtaskById( const result = await updateSubtaskById(
tasksPath, taskMaster.getTasksPath(),
subtaskId, subtaskId,
prompt, prompt,
useResearch, useResearch,
@@ -1571,7 +1575,7 @@ function registerCommands(programInstance) {
// Updated call to the refactored expandAllTasks // Updated call to the refactored expandAllTasks
try { try {
const result = await expandAllTasks( const result = await expandAllTasks(
tasksPath, taskMaster.getTasksPath(),
options.num, // Pass num options.num, // Pass num
options.research, // Pass research flag options.research, // Pass research flag
options.prompt, // Pass additional context options.prompt, // Pass additional context
@@ -1598,7 +1602,7 @@ function registerCommands(programInstance) {
try { try {
// Call the refactored expandTask function // Call the refactored expandTask function
await expandTask( await expandTask(
tasksPath, taskMaster.getTasksPath(),
options.id, options.id,
options.num, options.num,
options.research, options.research,
@@ -2091,7 +2095,6 @@ ${result.result}
.option('--all', 'Clear subtasks from all tasks') .option('--all', 'Clear subtasks from all tasks')
.option('--tag <tag>', 'Specify tag context for task operations') .option('--tag <tag>', 'Specify tag context for task operations')
.action(async (options) => { .action(async (options) => {
const tasksPath = options.file || TASKMASTER_TASKS_FILE;
const taskIds = options.id; const taskIds = options.id;
const all = options.all; const all = options.all;
const tag = options.tag; const tag = options.tag;
@@ -2249,7 +2252,7 @@ ${result.result}
try { try {
const { newTaskId, telemetryData } = await addTask( const { newTaskId, telemetryData } = await addTask(
tasksPath, taskMaster.getTasksPath(),
options.prompt, options.prompt,
dependenciesArray, dependenciesArray,
options.priority, options.priority,
@@ -2288,8 +2291,6 @@ ${result.result}
) )
.option('--tag <tag>', 'Specify tag context for task operations') .option('--tag <tag>', 'Specify tag context for task operations')
.action(async (options) => { .action(async (options) => {
const tasksPath = options.file || TASKMASTER_TASKS_FILE;
const reportPath = options.report;
const tag = options.tag; const tag = options.tag;
// Initialize TaskMaster // Initialize TaskMaster
@@ -4236,6 +4237,7 @@ Examples:
const taskMaster = initTaskMaster({ const taskMaster = initTaskMaster({
tasksPath: options.file || true tasksPath: options.file || true
}); });
const tasksPath = taskMaster.getTasksPath();
// Validate tasks file exists // Validate tasks file exists
if (!fs.existsSync(tasksPath)) { if (!fs.existsSync(tasksPath)) {
@@ -4305,7 +4307,7 @@ Examples:
}; };
await createTagFromBranch( await createTagFromBranch(
tasksPath, taskMaster.getTasksPath(),
currentBranch, currentBranch,
branchOptions, branchOptions,
context, context,
@@ -4375,6 +4377,7 @@ Examples:
const taskMaster = initTaskMaster({ const taskMaster = initTaskMaster({
tasksPath: options.file || true tasksPath: options.file || true
}); });
const tasksPath = taskMaster.getTasksPath();
// Validate tasks file exists // Validate tasks file exists
if (!fs.existsSync(tasksPath)) { if (!fs.existsSync(tasksPath)) {
@@ -4429,6 +4432,7 @@ Examples:
const taskMaster = initTaskMaster({ const taskMaster = initTaskMaster({
tasksPath: options.file || true tasksPath: options.file || true
}); });
const tasksPath = taskMaster.getTasksPath();
// Validate tasks file exists // Validate tasks file exists
if (!fs.existsSync(tasksPath)) { if (!fs.existsSync(tasksPath)) {
@@ -4478,6 +4482,7 @@ Examples:
const taskMaster = initTaskMaster({ const taskMaster = initTaskMaster({
tasksPath: options.file || true tasksPath: options.file || true
}); });
const tasksPath = taskMaster.getTasksPath();
// Validate tasks file exists // Validate tasks file exists
if (!fs.existsSync(tasksPath)) { if (!fs.existsSync(tasksPath)) {
@@ -4523,6 +4528,7 @@ Examples:
const taskMaster = initTaskMaster({ const taskMaster = initTaskMaster({
tasksPath: options.file || true tasksPath: options.file || true
}); });
const tasksPath = taskMaster.getTasksPath();
// Validate tasks file exists // Validate tasks file exists
if (!fs.existsSync(tasksPath)) { if (!fs.existsSync(tasksPath)) {
@@ -4574,6 +4580,7 @@ Examples:
const taskMaster = initTaskMaster({ const taskMaster = initTaskMaster({
tasksPath: options.file || true tasksPath: options.file || true
}); });
const tasksPath = taskMaster.getTasksPath();
// Validate tasks file exists // Validate tasks file exists
if (!fs.existsSync(tasksPath)) { if (!fs.existsSync(tasksPath)) {
@@ -4594,7 +4601,7 @@ Examples:
}; };
await copyTag( await copyTag(
taskMaster.getTasksPath(), tasksPath,
sourceName, sourceName,
targetName, targetName,
copyOptions, copyOptions,