useGetopt::Long;my$verbose=0;my$filepath='tasks.json';my$help=0;GetOptions('verbose|v'=>\$verbose,'file|f=s'=>\$filepath,'help|h'=>\$help,)ordie"Error in command line arguments\n";
if($help){print_help();exit;}subprint_help{print<<"END_HELP";
Usage: $0 [options] <command> [args]
Options:
-v, --verbose Verbose output
-f, --file=PATH Task file path (default: tasks.json)
-h, --help Show this help
Commands:
add <task> Add a new task
list List all tasks
complete <id> Complete a task by ID
END_HELP}
packageCommand::Add{useMoo;with'Command::Role';hasrepository=>(is=>'ro',required=>1);hastitle=>(is=>'ro',required=>1);hasverbose=>(is=>'ro',default=>sub{0});subexecute{my$self=shift;my$task=Task->new(title=>$self->title);$self->repository->save($task);if($self->verbose){print"[DEBUG] Saved to repository\n";print"[DEBUG] Task ID: ".$task->id."\n";}print"Added: ".$self->title." (ID: ".$task->id.")\n";}subdescription{return'Add a new task';}}
#!/usr/bin/env perlusestrict;usewarnings;useutf8;useGetopt::Long;useJSON;# クラス定義は省略(前回と同じ)# === メイン処理 ===packagemain;my$verbose=0;my$filepath='tasks.json';my$help=0;GetOptions('verbose|v'=>\$verbose,'file|f=s'=>\$filepath,'help|h'=>\$help,)ordie"Error in command line arguments\n";if($help){print_help();exit;}my$repository;if($ENV{TODO_TEST_MODE}){$repository=TaskRepository::InMemory->new;}else{$repository=TaskRepository::File->new(filepath=>$filepath);}my%command_map=(add=>sub{my$title=shift@ARGV;die"Usage: $0 add <task>\n"unlessdefined$title&&$titlene'';returnCommand::Add->new(repository=>$repository,title=>$title,verbose=>$verbose,);},list=>sub{returnCommand::List->new(repository=>$repository,verbose=>$verbose,);},complete=>sub{my$id=shift@ARGV;die"Usage: $0 complete <id>\n"unlessdefined$id&&$id=~ /^\d+$/;returnCommand::Complete->new(repository=>$repository,task_id=>$id,verbose=>$verbose,);},);my$cmd_name=shift@ARGV//'help';if(exists$command_map{$cmd_name}){my$command=$command_map{$cmd_name}->();$command->execute;}else{if($cmd_namene'help'){print"Unknown command: $cmd_name\n\n";}print_help();}subprint_help{print<<"END_HELP";
Usage: $0 [options] <command> [args]
Options:
-v, --verbose Verbose output
-f, --file=PATH Task file path (default: tasks.json)
-h, --help Show this help
Commands:
add <task> Add a new task
list List all tasks
complete <id> Complete a task by ID
END_HELP}
if($cmd_nameeq'complete'){my$id=shift@ARGV;if(!defined$id){die"Error: Task ID is required.\n"."Usage: $0 complete <id>\n";}if($id!~/^\d+$/){die"Error: Task ID must be a positive integer.\n"."You provided: '$id'\n";}returnCommand::Complete->new(repository=>$repository,task_id=>$id,verbose=>$verbose,);}