Skip to content

Commit 89218f2

Browse files
feat(cli): add task section arg to CLI
1 parent 896191f commit 89218f2

File tree

4 files changed

+117
-0
lines changed

4 files changed

+117
-0
lines changed

quick-add/cli/ArgumentParser.vala

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ namespace PlanifyCLI {
3131
public string? description { get; set; default = null; }
3232
public string? project_name { get; set; default = null; }
3333
public string? project_id { get; set; default = null; }
34+
public string? section_name { get; set; default = null; }
35+
public string? section_id { get; set; default = null; }
3436
public string? parent_id { get; set; default = null; }
3537
public int priority { get; set; default = 4; }
3638
public string? due_date { get; set; default = null; }
@@ -49,6 +51,8 @@ namespace PlanifyCLI {
4951
public string? description { get; set; default = null; }
5052
public string? project_name { get; set; default = null; }
5153
public string? project_id { get; set; default = null; }
54+
public string? section_name { get; set; default = null; }
55+
public string? section_id { get; set; default = null; }
5256
public string? parent_id { get; set; default = null; }
5357
public int priority { get; set; default = -1; }
5458
public string? due_date { get; set; default = null; }
@@ -170,6 +174,22 @@ namespace PlanifyCLI {
170174
exit_code = 1;
171175
return null;
172176
}
177+
} else if (arg == "-s" || arg == "--section") {
178+
if (i + 1 < args.length) {
179+
update_args.section_name = args[++i];
180+
} else {
181+
stderr.printf ("Error: %s requires an argument\n", arg);
182+
exit_code = 1;
183+
return null;
184+
}
185+
} else if (arg == "-S" || arg == "--section-id") {
186+
if (i + 1 < args.length) {
187+
update_args.section_id = args[++i];
188+
} else {
189+
stderr.printf ("Error: %s requires an argument\n", arg);
190+
exit_code = 1;
191+
return null;
192+
}
173193
} else if (arg == "-a" || arg == "--parent-id") {
174194
if (i + 1 < args.length) {
175195
update_args.parent_id = args[++i];
@@ -277,6 +297,22 @@ namespace PlanifyCLI {
277297
exit_code = 1;
278298
return null;
279299
}
300+
} else if (arg == "-s" || arg == "--section") {
301+
if (i + 1 < args.length) {
302+
task_args.section_name = args[++i];
303+
} else {
304+
stderr.printf ("Error: %s requires an argument\n", arg);
305+
exit_code = 1;
306+
return null;
307+
}
308+
} else if (arg == "-S" || arg == "--section-id") {
309+
if (i + 1 < args.length) {
310+
task_args.section_id = args[++i];
311+
} else {
312+
stderr.printf ("Error: %s requires an argument\n", arg);
313+
exit_code = 1;
314+
return null;
315+
}
280316
} else if (arg == "-a" || arg == "--parent-id") {
281317
if (i + 1 < args.length) {
282318
task_args.parent_id = args[++i];
@@ -360,6 +396,8 @@ namespace PlanifyCLI {
360396
stdout.printf (" -d, --description=DESC Task description\n");
361397
stdout.printf (" -p, --project=PROJECT Project name (defaults to inbox)\n");
362398
stdout.printf (" -i, --project-id=ID Project ID (preferred over name)\n");
399+
stdout.printf (" -s, --section=SECTION Section name\n");
400+
stdout.printf (" -S, --section-id=ID Section ID (preferred over name)\n");
363401
stdout.printf (" -a, --parent-id=ID Parent task ID (creates a subtask)\n");
364402
stdout.printf (" -P, --priority=1-4 Priority: 1=high, 2=medium, 3=low, 4=none (default: 4)\n");
365403
stdout.printf (" -D, --due=DATE Due date in YYYY-MM-DD format\n");
@@ -376,6 +414,8 @@ namespace PlanifyCLI {
376414
stdout.printf (" -d, --description=DESC New task description\n");
377415
stdout.printf (" -p, --project=PROJECT Move to project by name\n");
378416
stdout.printf (" -i, --project-id=ID Move to project by ID (preferred over name)\n");
417+
stdout.printf (" -s, --section=SECTION Move to section by name\n");
418+
stdout.printf (" -S, --section-id=ID Move to section by ID (preferred over name)\n");
379419
stdout.printf (" -a, --parent-id=ID New parent task ID\n");
380420
stdout.printf (" -P, --priority=1-4 Priority: 1=high, 2=medium, 3=low, 4=none\n");
381421
stdout.printf (" -D, --due=DATE Due date in YYYY-MM-DD format\n");

quick-add/cli/Main.vala

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,28 @@ namespace PlanifyCLI {
133133
}
134134
}
135135

136+
// Handle section change if provided
137+
if (args.section_id != null || args.section_name != null) {
138+
Objects.Project? current_project = Services.Store.instance ().get_project (item.project_id);
139+
if (current_project != null) {
140+
Objects.Section? target_section = TaskCreator.find_section (
141+
args.section_id,
142+
args.section_name,
143+
current_project,
144+
out error_message
145+
);
146+
147+
if (target_section == null) {
148+
stderr.printf ("%s\n", error_message);
149+
return 1;
150+
}
151+
152+
if (item.section_id != target_section.id) {
153+
item.section_id = target_section.id;
154+
}
155+
}
156+
}
157+
136158
// Update parent_id if provided
137159
if (args.parent_id != null) {
138160
if (!TaskValidator.validate_parent_id (args.parent_id, out error_message)) {
@@ -285,6 +307,23 @@ namespace PlanifyCLI {
285307
args.parent_id
286308
);
287309

310+
// Find and set section if provided
311+
if (args.section_id != null || args.section_name != null) {
312+
Objects.Section? target_section = TaskCreator.find_section (
313+
args.section_id,
314+
args.section_name,
315+
target_project,
316+
out error_message
317+
);
318+
319+
if (target_section == null) {
320+
stderr.printf ("%s\n", error_message);
321+
return 1;
322+
}
323+
324+
item.section_id = target_section.id;
325+
}
326+
288327
// Add labels if provided
289328
if (args.labels != null && args.labels.strip () != "") {
290329
string[] label_names = args.labels.split (",");

quick-add/cli/OutputFormatter.vala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ namespace PlanifyCLI {
4444
{ "checked", (builder) => builder.add_boolean_value (item.checked) },
4545
{ "pinned", (builder) => builder.add_boolean_value (item.pinned) },
4646
{ "project-id", (builder) => builder.add_string_value (item.project_id) },
47+
{ "section-id", (builder) => builder.add_string_value (item.section_id) },
4748
{ "parent-id", (builder) => builder.add_string_value (item.parent_id) },
4849
{ "added-at", (builder) => builder.add_string_value (item.added_at) },
4950
{ "completed-at", (builder) => builder.add_string_value (item.completed_at) },

quick-add/cli/TaskCreator.vala

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,43 @@
1919

2020
namespace PlanifyCLI {
2121
public class TaskCreator : Object {
22+
public static Objects.Section? find_section (string? section_id, string? section_name, Objects.Project project, out string? error_message) {
23+
error_message = null;
24+
Objects.Section? target_section = null;
25+
26+
// Prefer section ID over name
27+
if (section_id != null && section_id.strip () != "") {
28+
// Search by section ID
29+
foreach (var section in Services.Store.instance ().get_sections_by_project (project)) {
30+
if (section.id == section_id.strip ()) {
31+
target_section = section;
32+
break;
33+
}
34+
}
35+
36+
if (target_section == null) {
37+
error_message = "Error: Section ID '%s' not found in project '%s'".printf (section_id, project.name);
38+
return null;
39+
}
40+
} else if (section_name != null && section_name.strip () != "") {
41+
// Search for section by name (case-insensitive)
42+
string search_name = section_name.strip ().down ();
43+
foreach (var section in Services.Store.instance ().get_sections_by_project (project)) {
44+
if (section.name.down () == search_name) {
45+
target_section = section;
46+
break;
47+
}
48+
}
49+
50+
if (target_section == null) {
51+
error_message = "Error: Section '%s' not found in project '%s'".printf (section_name, project.name);
52+
return null;
53+
}
54+
}
55+
56+
return target_section;
57+
}
58+
2259
public static Objects.Project? find_project (string? project_id, string? project_name, out string? error_message) {
2360
error_message = null;
2461
Objects.Project? target_project = null;

0 commit comments

Comments
 (0)