Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Command] Added better support for custom default command#16901

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed
lyrixx wants to merge1 commit intosymfony:masterfromlyrixx:console-one-app

Conversation

@lyrixx
Copy link
Member

QA
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets-
LicenseMIT

Hello;

I write many CLI application, and "single command" in cli application is not so easy to write.
This is why I propose this patch. IMHO, this PR could replaces#9609.

See it in application:

#!/usr/bin/env php<?phprequire__DIR__.'/vendor/autoload.php';useSymfony\Component\Console\Application;useSymfony\Component\Console\Input\InputArgument;useSymfony\Component\Console\Input\InputInterface;useSymfony\Component\Console\Input\InputOption;useSymfony\Component\Console\Output\OutputInterface;(newApplication('echo','1.0.0'))    ->register('echo')        ->addArgument('foo', InputArgument::OPTIONAL,'The directory','foo')        ->addOption('bar',null, InputOption::VALUE_REQUIRED,'Foobar','bar')        ->setCode(function(InputInterface$input,OutputInterface$output) {$output->writeln('start');$output->writeln($input->getArgument('foo'));$output->writeln($input->getOption('bar'));        })    ->getApplication()    ->setUniqueCommand('echo')    ->run();

Some usage:

>(3)[{..}eg/dev/github.com/symfony/symfony](console-one-app) php test.php startfoobar
>(3)[{..}eg/dev/github.com/symfony/symfony](console-one-app) php test.php  "first argument"startfirst argumentbar
>(3)[{..}eg/dev/github.com/symfony/symfony](console-one-app) php test.php  "first argument" --bar="first option"startfirst argumentfirst option
>(3)[{..}eg/dev/github.com/symfony/symfony](console-one-app) php test.php  "first argument" --bar="first option" --helpUsage:  echo [options] [--] [<foo>]Arguments:  foo                   The directory [default: "foo"]Options:      --bar=BAR         Foobar [default: "bar"]  -h, --help            Display this help message  -q, --quiet           Do not output any message  -V, --version         Display this application version      --ansi            Force ANSI output      --no-ansi         Disable ANSI output  -n, --no-interaction  Do not ask any interactive question  -v|vv|vvv, --verbose  Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

@lyrixx
Copy link
MemberAuthor

Hm, actually, It does not work when using extra option/argument.
Sorry.

@lyrixxlyrixx closed thisDec 8, 2015
@lyrixxlyrixx deleted the console-one-app branchDecember 8, 2015 12:33
@lyrixx
Copy link
MemberAuthor

I find another approach for one single command app. So I-reuse the same PR
What do you think?

@lyrixx
Copy link
MemberAuthor

Github don't let me re-open the PR :(

@lyrixxlyrixx changed the title[Command] Added better for custom default command[Command] Added better support for custom default commandAug 29, 2016
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@lyrixx@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp