tracks/perl5/bin/exercise-gen.pl in trackler-2.1.0.53 vs tracks/perl5/bin/exercise-gen.pl in trackler-2.1.0.54

- old
+ new

@@ -1,9 +1,8 @@ #!/usr/bin/env perl use feature qw(lexical_subs say); use YAML 'LoadFile'; -use JSON::PP 'decode_json'; use Path::Tiny qw(:DEFAULT cwd); use Template::Mustache 'render'; my $base_dir = path($0)->realpath->parent->parent; my @exercises; @@ -17,20 +16,27 @@ } else { say 'No args given; working in current directory.'; if ( path('example.yaml')->is_file ) { push @exercises, cwd->basename; } else { - say 'example.yaml not found; exiting.'; + say 'example.yaml not found in current directory; exiting.'; exit; } } +my @dir_not_found; +my @yaml_not_found; for my $exercise (@exercises) { my $exercise_dir = $base_dir->child("exercises/$exercise"); my $yaml = $exercise_dir->child('example.yaml'); + + unless ($exercise_dir->is_dir) { + push @dir_not_found, $exercise; + next; + } unless ($yaml->is_file) { - say "No example.yaml found for $exercise."; + push @yaml_not_found, $exercise; next; } print "Generating $exercise... "; my $data = LoadFile $yaml; @@ -54,7 +60,9 @@ $data->{module_file} = $data->{stub}; create_file($data->{exercise}.'.pm', 'module'); say 'Generated.'; - } + +if (@dir_not_found) {warn 'exercise directory does not exist for: ' . join ' ', @dir_not_found} +if (@yaml_not_found) {warn 'example.yaml not found for: ' . join ' ', @yaml_not_found}