@@ -18,7 +18,7 @@ class Seed extends Command
1818 *
1919 * @var string
2020 */
21- protected $ signature = 'seed {name} {count=10 } ' ;
21+ protected $ signature = 'seed {name} {count=} {locale= } ' ;
2222
2323 /**
2424 * The full command description.
@@ -35,7 +35,8 @@ class Seed extends Command
3535 protected $ descriptions = [
3636 'seed ' => 'Run a seed ' ,
3737 'name ' => 'The name of the seed ' ,
38- 'count ' => 'The number of rows, the seed will create '
38+ 'count ' => 'The number of rows, the seed will create ' ,
39+ 'locale ' => 'The default locale '
3940 ];
4041
4142 /**
@@ -46,30 +47,43 @@ class Seed extends Command
4647 */
4748 protected function execute (InputInterface $ input , OutputInterface $ output )
4849 {
49- $ name = strtolower ($ input ->getArgument ('name ' ));
50- $ count = (int )$ input ->getOption ('count ' );
50+ $ name = strtolower ($ input ->getArgument ('name ' ));
51+ $ count = (!in_array ((int )$ input ->getOption ('count ' ), ['' , null ]) ? (int )$ input ->getOption ('count ' ) : null );
52+ $ locale = (!in_array ($ input ->getOption ('locale ' ), ['' , null ]) ? $ input ->getOption ('locale ' ) : null );
53+
54+ /**
55+ * Check if locale is supported before proceeding
56+ */
57+ if (
58+ $ locale &&
59+ !in_array ($ locale , (is_array (config ('faker.locale.supported ' )) ? config ('faker.locale.supported ' ) : []))
60+ ) {
61+ return $ output ->writeln ('<info>Locale " ' . $ locale .'" is not supported.</info> ' );
62+ }
5163
5264 $ seeds = ModulusCLI::$ appdir . DIRECTORY_SEPARATOR . 'database ' . DIRECTORY_SEPARATOR . 'seeds ' . DIRECTORY_SEPARATOR ;
5365
5466 $ seed = $ seeds . $ name . '.php ' ;
5567
5668 if (file_exists ($ seed )) {
5769
58- if (!is_int ($ count )) return $ output ->writeln ('<error>" ' .$ count .'" is not a real number</error> ' );
70+ if ($ count !== null && !is_int ($ count )) return $ output ->writeln ('<error>" ' .$ count .'" is not a real number</error> ' );
5971
6072 require $ seed ;
6173
6274 $ className = $ this ->className (substr ($ name , strrpos ($ name , '/ ' )));
6375
6476 if (class_exists ($ className )) {
77+ $ seed = new $ className ;
78+ $ seed ->count = ($ count ?? $ seed ->count );
79+ $ seed ->locale = ($ locale ?? $ seed ->locale );
80+
6581 ProgressBar::setFormatDefinition ('count ' , 'Processing: %current%/%max%. ' );
6682
67- $ progressBar = new ProgressBar ($ output , $ count );
83+ $ progressBar = new ProgressBar ($ output , $ seed -> count );
6884 $ progressBar ->setFormat ('count ' );
6985 $ progressBar ->start ();
7086
71- $ seed = new $ className ;
72- $ seed ->count = $ count ;
7387 $ results = $ seed ->run ($ progressBar );
7488
7589 if (!$ results ) {
0 commit comments