@@ -38,6 +38,7 @@ public function configure()
3838 )
3939 ->addOption ('service ' , true , 'Service to manage ' )
4040 ->addOption ('method ' , true , 'Method to run on the service manager. <restart> ' , 'restart ' )
41+ ->addOption ('sudo ' , true , 'Run as sudo? ' , false )
4142 ->addOption ('dry_run ' , true , 'If set, will not run command ' , false );
4243 }
4344
@@ -51,21 +52,32 @@ public function run()
5152 ->addOption ('arguments ' , true );
5253
5354 $ arguments = [];
54- $ manager = $ this ->getOption ('manager ' );
55+ $ sudo = $ this ->getOption ('sudo ' );
56+ $ manager = $ this ->getOption ('manager ' );
5557 switch ($ manager ) {
5658 case 'service ' :
57- $ executable = 'sudo ' ;
58- $ arguments [] = $ manager ;
59+ $ executable = $ manager ;
60+ if ($ sudo ) {
61+ $ executable = 'sudo ' ;
62+ $ arguments [] = $ manager ;
63+ }
5964 $ arguments [] = $ this ->getOption ('service ' );
6065 $ arguments [] = $ this ->getOption ('method ' );
6166 break ;
6267 case 'init.d ' :
63- $ executable = 'sudo ' ;
64- $ arguments [] = '/etc/init.d/ ' .$ this ->getOption ('service ' );
68+ $ executable = '/etc/init.d/ ' .$ this ->getOption ('service ' );
69+ if ($ sudo ) {
70+ $ executable = 'sudo ' ;
71+ $ arguments [] = $ manager ;
72+ }
6573 $ arguments [] = $ this ->getOption ('method ' );
6674 break ;
6775 case 'launchctl ' :
68- $ executable = $ manager ;
76+ $ executable = $ manager ;
77+ if ($ sudo ) {
78+ $ executable = 'sudo ' ;
79+ $ arguments [] = $ manager ;
80+ }
6981 $ arguments [] = $ this ->getOption ('method ' );
7082 $ arguments [] = $ this ->getOption ('service ' );
7183 break ;
0 commit comments