Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single Command Applications #30

Closed
tqmz opened this issue Sep 22, 2016 · 4 comments
Closed

Single Command Applications #30

tqmz opened this issue Sep 22, 2016 · 4 comments

Comments

@tqmz
Copy link

tqmz commented Sep 22, 2016

I'd find it generally useful to let Silly support Single Command Applications out of the box.

A simple way of providing this might be offering a Silly\SingleCommandApplication.
Respectively, Silly\Edition\PhpDi\SingleCommandApplication for PHP-DI.

What do you think?

@mnapoli
Copy link
Owner

mnapoli commented Sep 22, 2016

Why not, but how would the single command be defined? It sounds a bit vague for now.

@tqmz
Copy link
Author

tqmz commented Sep 27, 2016

Please check #31 for an approach.

@mnapoli
Copy link
Owner

mnapoli commented Dec 25, 2016

Actually Symfony already provides support for that. I've needed that so I had a look, it's as simple as doing this:

$app->command('run', /* ... */);
$app->setDefaultCommand('run');

I've added it to the documentation.

@aubreypwd
Copy link

aubreypwd commented Jan 14, 2023

If you want to use ->setDefaultCommand() and pass parameters then you need to pass the 2nd parameter to setDefaultCommand:

use Symfony\Component\Console\Output\OutputInterface;

$app = new Silly\Application();

$app->command( 'greet [name] [--yell]', function ( $name, $yell, OutputInterface $output ) {

	if ( ! $yell ) {
		return false;
	}

		$output->writeln( $name );
} );

$app->setDefaultCommand( 'greet', true ); // 2nd Parameter: bool $isSingleCommand = false

$app->run();

But then running the sub-command greet requires --:

iTerm2 - -zsh — UsersaubreypwdReposgithub comaubreypwdphp-cli-silly on January 13 2023 at 0550 PM@2x

...so you can't really have sub-commands (and them operate normally) when you make a single command (default) re-direct to a sub-command.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants