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

[NFR] Examples and docs about cli modules #411

Closed
alvassin opened this issue Feb 10, 2013 · 8 comments
Closed

[NFR] Examples and docs about cli modules #411

alvassin opened this issue Feb 10, 2013 · 8 comments

Comments

@alvassin
Copy link

I found that there are some CLI classes. Perhaps you could spend some time on tutorials about writing cli applications with such modules....

If writing cli applications would be simple as writing micro applications it would be unbeliveable.

Perhaps, i need to make cli application, that accepts parameters in the following way:
cli-app.php $command --param1=value1 --param2=value2

If it would be possible to handle such requests automatically and focus on business logic, it would ecomony many time :)

@alvassin
Copy link
Author

Another way i thought about:

./script.php robot/create --color=red --feature=weapon

and to get this inside my application with controllers, actions, etc in this way:

controller: robot
action: create
GET params: color=red,feature=weapon

@alvassin
Copy link
Author

We have four classes, that are prepared especially for CLI:

  • Phalcon\CLI\Console - analog of Phalcon\Mvc\Micro or Phalcon\Mvc\Application, main controller for all objects, everything
  • Phalcon\CLI\Router - router, same as router in usual web applications
  • Phalcon\CLI\Task - analog of usual controller
  • Phalcon\CLI\Dispatcher - same as Phalcon\Dispatcher

What i really can't get - is phalcon able to get and handle argv parameters manually, and those classes should work in group.

Perhaps you will find some little amount of time to describe this shortly. I believe that with Phalcon my CLI app will look much nicer then without it :)

Thanks in advance

@alvassin
Copy link
Author

@alvassin
Copy link
Author

One bad thing: cli/console is accepting all parameters as action names, for example:

./app.php test --param1=value1 --param2=value2

Will output:
PHP Fatal error: Uncaught exception 'Phalcon\CLI\Dispatcher\Exception' with message 'Action '--param1=value1' was not found on handler 'station'' in /var/www/source-api/cli/app.php:37
Stack trace:
#0 [internal function]: Phalcon\CLI\Dispatcher->_throwDispatchException('Action '--param...', 5)
#1 [internal function]: Phalcon\Dispatcher->dispatch()
#2 /var/www/source-api/cli/app.php(37): Phalcon\CLI\Console->handle(Array)
#3 {main}
thrown in /var/www/source-api/cli/app.php on line 37

How it is possible to get params for specified action?

@alvassin
Copy link
Author

It's also impossible to pass parameters as:

./script.php testtask?param=value
./script.php testtask -param

@alvassin
Copy link
Author

If i specity parameters following way:

./app.php test test --param=value

in test task i have following code:

    public function testAction()
    {
        var_dump($this->dispatcher->getParams());
    }

i will get following values:

array(1) {
  [0]=>
  string(13) "--param=value"
}

How to get array keys as param names and array values as param values?

@alvassin
Copy link
Author

If i specify parameters divided by a space, i will get them as separate params:

./app.php test test param value
array(2) {
  [0]=>
  string(7) "param"
  [1]=>
  string(5) "value"
}

How it is possible to get array as following?

array(1) {
  ['param']=> string(5) "value"
}

@alvassin
Copy link
Author

Was unable find the way for this in the end. Finally stopped at solution to define parameters in action methods, like this:

public function doSmth($param1, $param2)

This works fine.

Perhaps it's a good idea for NFR to implement param=value or --param=value, which will look more native in cli?

@alvassin alvassin closed this as completed May 6, 2013
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

1 participant