@@ -47,6 +47,12 @@ function (ConsoleCommandEvent $event) {
4747
4848Upgrader::onEveryRun ();
4949
50+ $ share_tools = [
51+ 'cloudflared ' ,
52+ 'expose ' ,
53+ 'ngrok '
54+ ];
55+
5056/**
5157 * Install Valet and any required services.
5258 */
@@ -378,83 +384,60 @@ function (ConsoleCommandEvent $event) {
378384 /**
379385 * Echo the currently tunneled URL.
380386 */
381- $ app ->command ('fetch-share-url [domain] ' , function ($ domain = null ) {
387+ $ app ->command ('fetch-share-url [domain] ' , function ($ domain = null ) use ( $ share_tools ) {
382388 $ tool = Configuration::read ()['share-tool ' ] ?? null ;
383389
384- switch ($ tool ) {
385- case 'expose ' :
386- if ($ url = Expose::currentTunnelUrl ($ domain ?: Site::host (getcwd ()))) {
387- output ($ url );
388- }
389- break ;
390- case 'ngrok ' :
391- try {
392- output (Ngrok::currentTunnelUrl (Site::domain ($ domain )));
393- } catch (\Throwable $ e ) {
394- warning ($ e ->getMessage ());
395- }
396- break ;
397- default :
398- info ('Please set your share tool with `valet share-tool expose` or `valet share-tool ngrok`. ' );
390+ if ($ tool && in_array ($ tool , $ share_tools ) && class_exists ($ tool )) {
391+ try {
392+ output ($ tool ::currentTunnelUrl (Site::domain ($ domain )));
393+ } catch (\Throwable $ e ) {
394+ warning ($ e ->getMessage ());
395+ }
396+ } else {
397+ info ('Please set your share tool with `valet share-tool`. ' );
399398
400- return Command::FAILURE ;
399+ return Command::FAILURE ;
401400 }
402- })->descriptions ('Get the URL to the current share tunnel (for Expose or ngrok) ' );
401+ })->descriptions ('Get the URL to the current share tunnel ' );
403402
404403 /**
405404 * Echo or set the name of the currently-selected share tool (either "ngrok" or "expose").
406405 */
407- $ app ->command ('share-tool [tool] ' , function (InputInterface $ input , OutputInterface $ output , $ tool = null ) {
406+ $ app ->command ('share-tool [tool] ' , function (InputInterface $ input , OutputInterface $ output , $ tool = null )
407+ use ($ share_tools ) {
408408 if ($ tool === null ) {
409409 return output (Configuration::read ()['share-tool ' ] ?? '(not set) ' );
410410 }
411411
412- if ($ tool !== 'expose ' && $ tool !== 'ngrok ' ) {
413- warning ($ tool .' is not a valid share tool. Please use `ngrok` or `expose`. ' );
412+ $ share_tools_list = preg_replace ('/,\s([^,]+)$/ ' , ' or $1 ' ,
413+ join (', ' , array_map (fn ($ t ) => "` $ t` " , $ share_tools )));
414+
415+ if (! in_array ($ tool , $ share_tools ) || ! class_exists ($ tool )) {
416+ warning ("$ tool is not a valid share tool. Please use $ share_tools_list. " );
414417
415418 return Command::FAILURE ;
416419 }
417420
418421 Configuration::updateKey ('share-tool ' , $ tool );
419- info ('Share tool set to ' .$ tool .'. ' );
420-
421- if ($ tool === 'expose ' ) {
422- if (Expose::installed ()) {
423- // @todo: Check it's the right version (has /api/tunnels/)
424- // E.g. if (Expose::installedVersion)
425- // if (version_compare(Expose::installedVersion(), $minimumExposeVersion) < 0) {
426- // prompt them to upgrade
427- return ;
428- }
422+ info ("Share tool set to $ tool. " );
429423
424+ if (! $ tool ::installed ()) {
430425 $ helper = $ this ->getHelperSet ()->get ('question ' );
431- $ question = new ConfirmationQuestion ('Would you like to install Expose now? [y/N] ' , false );
426+ $ question = new ConfirmationQuestion (
427+ 'Would you like to install ' .ucfirst ($ tool ).' now? [y/N] ' ,
428+ false );
432429
433430 if ($ helper ->ask ($ input , $ output , $ question ) === false ) {
434- info ('Proceeding without installing Expose . ' );
431+ info ('Proceeding without installing ' . ucfirst ( $ tool ). ' . ' );
435432
436433 return ;
437434 }
438435
439- Expose::ensureInstalled ();
440-
441- return ;
436+ $ tool ::ensureInstalled ();
442437 }
443438
444- if (! Ngrok::installed ()) {
445- info ("\nIn order to share with ngrok, you'll need a version \nof ngrok installed and managed by Homebrew. " );
446- $ helper = $ this ->getHelperSet ()->get ('question ' );
447- $ question = new ConfirmationQuestion ('Would you like to install ngrok via Homebrew now? [y/N] ' , false );
448-
449- if ($ helper ->ask ($ input , $ output , $ question ) === false ) {
450- info ('Proceeding without installing ngrok. ' );
451-
452- return ;
453- }
454-
455- Ngrok::ensureInstalled ();
456- }
457- })->descriptions ('Get the name of the current share tool (Expose or ngrok). ' );
439+ return Command::SUCCESS ;
440+ })->descriptions ('Get the name of the current share tool. ' );
458441
459442 /**
460443 * Set the ngrok auth token.
0 commit comments