@@ -35,6 +35,7 @@ protected function configure()
35
35
->setName ('server:status ' )
36
36
->setDefinition (array (
37
37
new InputOption ('pidfile ' , null , InputOption::VALUE_REQUIRED , 'PID file ' ),
38
+ new InputOption ('filter ' , null , InputOption::VALUE_REQUIRED , 'The value to display (one of port, host, or address) ' ),
38
39
))
39
40
->setDescription ('Outputs the status of the local web server for the given address ' )
40
41
;
@@ -47,10 +48,28 @@ protected function execute(InputInterface $input, OutputInterface $output)
47
48
{
48
49
$ io = new SymfonyStyle ($ input , $ output instanceof ConsoleOutputInterface ? $ output ->getErrorOutput () : $ output );
49
50
$ server = new WebServer ();
50
- if ($ server ->isRunning ($ input ->getOption ('pidfile ' ))) {
51
- $ io ->success (sprintf ('Web server still listening
8000
on http://%s ' , $ server ->getAddress ($ input ->getOption ('pidfile ' ))));
51
+ if ($ filter = $ input ->getOption ('filter ' )) {
52
+ if ($ server ->isRunning ($ input ->getOption ('pidfile ' ))) {
53
+ list ($ host , $ port ) = explode (': ' , $ address = $ server ->getAddress ($ input ->getOption ('pidfile ' )));
54
+ if ('address ' === $ filter ) {
55
+ $ output ->write ($ address );
56
+ } elseif ('host ' === $ filter ) {
57
+ $ output ->write ($ host );
58
+ } elseif ('port ' === $ filter ) {
59
+ $ output ->write ($ port );
60
+ } else {
61
+ throw new \InvalidArgumentException (sprintf ('"%s" is not a valid filter. ' , $ filter ));
62
+ }
63
+ } else {
64
+ return 1 ;
65
+ }
52
66
} else {
53
- $ io ->warning ('No web server is listening. ' );
67
+ if ($ server ->isRunning ($ input ->getOption ('pidfile ' ))) {
68
+ $ io ->success (sprintf ('Web server still listening on http://%s ' , $ server ->getAddress ($ input ->getOption ('pidfile ' ))));
69
+ } else {
70
+ $ io ->warning ('No web server is listening. ' );
71
+ return 1 ;
72
+ }
54
73
}
55
74
}
56
75
}
0 commit comments