in datastore/api/TaskList/Program.cs [125:165]
void HandleCommandLine(string commandLine)
{
string[] args = commandLine.Split(null, 2);
if (args.Length < 1)
throw new ArgumentException("not enough args");
string command = args[0];
switch (command)
{
case "new":
if (args.Length != 2)
throw new ArgumentException("missing description");
AddTask(args[1]);
Console.WriteLine("task added");
break;
case "done":
if (args.Length != 2)
throw new ArgumentException("missing task id");
long id = long.Parse(args[1]);
if (MarkDone(id))
Console.WriteLine("task marked done");
else
Console.WriteLine($"did not find a Task entity with ID {id}");
break;
case "list":
var tasks = FormatTasks(ListTasks());
Console.WriteLine($"found {tasks.Count()} tasks");
Console.WriteLine("task ID : description");
Console.WriteLine("---------------------");
foreach (string task in tasks)
Console.WriteLine(task);
break;
case "delete":
if (args.Length != 2)
throw new ArgumentException("missing task id");
DeleteTask(long.Parse(args[1]));
Console.WriteLine("task deleted (if it existed)");
break;
default:
throw new ArgumentException($"unrecognized command: {command}");
}
}