Skip to content

Commit dab5f62

Browse files
committed
Implement EditTodoCommand to open todo.txt in VS Code and update command line arguments
1 parent 93d3e34 commit dab5f62

File tree

5 files changed

+61
-4
lines changed

5 files changed

+61
-4
lines changed

.vscode/launch.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
// Use IntelliSense to learn about possible attributes.
3+
// Hover to view descriptions of existing attributes.
4+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
5+
"version": "0.2.0",
6+
"configurations": [
7+
{
8+
"name": "C#: todo Debug",
9+
"type": "dotnet",
10+
"request": "launch",
11+
"projectPath": "${workspaceFolder}/src/todo/todo.csproj"
12+
}
13+
]
14+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
using Alteridem.Todo.Domain.Interfaces;
2+
using MediatR;
3+
using System.Threading;
4+
using System.Threading.Tasks;
5+
6+
namespace Alteridem.Todo.Application.Commands
7+
{
8+
public class EditTodoCommand : IRequest<Unit>
9+
{
10+
// No parameters for this command
11+
}
12+
13+
public class EditTodoCommandHandler : IRequestHandler<EditTodoCommand, Unit>
14+
{
15+
private readonly ITaskConfiguration _configuration;
16+
17+
public EditTodoCommandHandler(ITaskConfiguration configuration)
18+
{
19+
_configuration = configuration;
20+
}
21+
22+
public Task<Unit> Handle(EditTodoCommand request, CancellationToken cancellationToken)
23+
{
24+
// Step 1: Get the directory that contains todo.txt from the configuration
25+
var todoDirectory = _configuration.TodoDirectory;
26+
27+
// Step 2: Launch a process 'code' with the todoDirectory as a parameter
28+
var processStartInfo = new System.Diagnostics.ProcessStartInfo
29+
{
30+
FileName = "code",
31+
Arguments = $"\"{todoDirectory}\"",
32+
UseShellExecute = true,
33+
CreateNoWindow = true,
34+
WorkingDirectory = $"\"{todoDirectory}\"",
35+
};
36+
System.Diagnostics.Process.Start(processStartInfo);
37+
38+
// Stub implementation for editing logic
39+
return Task.FromResult(Unit.Value);
40+
}
41+
}
42+
}

src/todo/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ namespace Alteridem.Todo;
22

33
class Program
44
{
5-
static void Main()
5+
static void Main(string[] args)
66
{
77
var app = new TodoApplication();
88
app.Run();

src/todo/Properties/launchSettings.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"profiles": {
33
"todo": {
44
"commandName": "Project",
5-
"commandLineArgs": "ls"
5+
"commandLineArgs": "edit"
66
}
77
}
88
}

src/todo/TodoApplication.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,9 @@ private async Task AddPriority(int item, char priority)
307307

308308
private async Task Edit()
309309
{
310-
// TODO: Implement logic to open the folder containing the todo.txt file in VS Code
311-
Console.WriteLine("Opening folder in VS Code...");
310+
Console.WriteLine("Opening todo.txt in VS Code...");
311+
var command = new EditTodoCommand();
312+
await Mediator.Send(command);
312313
}
313314

314315
private RootCommand CreateCommands()

0 commit comments

Comments
 (0)