@@ -88,7 +88,9 @@ protected function configure()
8888 ->addOption ('branch ' , null , InputOption::VALUE_REQUIRED , 'The branch that should be created for a new repository ' )
8989 ->addOption ('github ' , null , InputOption::VALUE_OPTIONAL , 'Create a new repository on GitHub ' , false )
9090 ->addOption ('repo ' , null , InputOption::VALUE_REQUIRED , 'Optionally specify the name of the GitHub repository ' )
91- ->addOption ('force ' , 'f ' , InputOption::VALUE_NONE , 'Force install even if the directory already exists ' );
91+ ->addOption ('force ' , 'f ' , InputOption::VALUE_NONE , 'Force install even if the directory already exists ' )
92+ ->addOption ('email ' , null , InputOption::VALUE_OPTIONAL , 'Creates a super user with this email address ' )
93+ ->addOption ('password ' , null , InputOption::VALUE_OPTIONAL , 'Password for the super user ' );
9294 }
9395
9496 protected function initialize (InputInterface $ input , OutputInterface $ output )
@@ -695,6 +697,12 @@ protected function installSsg()
695697
696698 protected function askToMakeSuperUser ()
697699 {
700+ if ($ this ->input ->getOption ('email ' )) {
701+ $ this ->makeUser = true ;
702+
703+ return $ this ;
704+ }
705+
698706 if (! $ this ->input ->isInteractive ()) {
699707 return $ this ;
700708 }
@@ -723,18 +731,35 @@ protected function makeSuperUser()
723731 return $ this ;
724732 }
725733
726- $ this ->output ->write (PHP_EOL .PHP_EOL );
727- intro ("Let's create your super user account. " );
734+ $ email = $ this ->input ->getOption ('email ' );
735+ $ password = $ this ->input ->getOption ('password ' ) ?? 'password ' ;
736+
737+ if (! $ email ) {
738+ $ this ->output ->write (PHP_EOL .PHP_EOL );
739+ intro ("Let's create your super user account. " );
740+ }
728741
729742 // Since Windows cannot TTY, we'll capture their input here and make a user.
730- if (PHP_OS_FAMILY === 'Windows ' ) {
743+ if ($ this -> input -> isInteractive () && ! $ email && PHP_OS_FAMILY === 'Windows ' ) {
731744 return $ this ->makeSuperUserInWindows ();
732745 }
733746
734- // Otherwise, delegate to the `make:user` command with interactivity and let core handle the finer details.
747+ $ command = ['make:user ' ];
748+
749+ if ($ email ) {
750+ $ command = [...$ command , $ email , '--password= ' .$ password ];
751+ }
752+
753+ $ command [] = '--super ' ;
754+
755+ if (! $ this ->input ->isInteractive ()) {
756+ $ command [] = '--no-interaction ' ;
757+ }
758+
759+ // Otherwise, delegate to the `make:user` command and let core handle the finer details.
735760 (new Please ($ this ->output ))
736761 ->cwd ($ this ->absolutePath )
737- ->run (' make:user ' , ' --super ' );
762+ ->run (... $ command );
738763
739764 return $ this ;
740765 }
@@ -753,28 +778,13 @@ protected function makeSuperUserInWindows()
753778 $ email = $ this ->askForBasicInput ('Email ' );
754779 }
755780
756- // Ask for name
757- $ name = $ this ->askForBasicInput ('Name ' );
758-
759781 // Ask for password
760782 while (! isset ($ password ) || ! $ this ->validatePassword ($ password )) {
761783 $ password = $ this ->askForBasicInput ('Password (Your input will be hidden) ' , true );
762784 }
763785
764786 // Create super user and update with captured input.
765- $ please ->run ('make:user ' , '--super ' , $ email );
766-
767- $ updateUser = '\Statamic\Facades\User::findByEmail( ' .escapeshellarg ($ email ).') '
768- .'->password( ' .escapeshellarg ($ password ).') '
769- .'->makeSuper() ' ;
770-
771- if ($ name ) {
772- $ updateUser .= '->set("name", ' .escapeshellarg ($ name ).') ' ;
773- }
774-
775- $ updateUser .= '->save(); ' ;
776-
777- $ please ->run ('tinker ' , '--execute ' , $ updateUser );
787+ $ please ->run ('make:user ' , $ email , '--password= ' .$ password , '--super ' );
778788
779789 return $ this ;
780790 }
0 commit comments