adrian7's avatar

Custom command does not register arguments or options

I started a project using lumen and went over to register some custom commands.

For example I have written this one: http://hastebin.com/jabobadeke.php

And then register it via app\Console\Kernel.php http://hastebin.com/yefurepaja.php

However when I run php artisan help api-client:get all I get is http://hastebin.com/raw/axijoyedid

0 likes
6 replies
tuneless's avatar

Hello @adrian7 ,

are you in the right namespace with Commands\AppClientGetCommand::class, ??

For me this would be right:

protected $commands = [
        \App\Console\Commands\AppClientGetCommand::class,
        \App\Console\Commands\KeyGenerateCommand::class,
        \App\Console\Commands\InspireCommand::class
    ];

I thought of the Laravel 5.1 aspect. Is Lumen different in Namespaces?

adrian7's avatar

Tried with your namespace suggestion, but still same output...

tuneless's avatar

Hm, try the new signature functionality:

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;


class AppClientGetCommand extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'api-client:get {id} {--example}';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Get api client details';

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {
        $id = $this->argument('id');

        dd($id);
    }
}
1 like
adrian7's avatar
adrian7
OP
Best Answer
Level 1

Ah yes spotted the mistake: instead of

protected $signature = 'api-client:get';

should have used

protected $name = 'api-client:get';

That way works.

Cheers guys.

1 like
jeffdavis's avatar

If you put $signature, but not name, you get an error in Lumen. I am having the hardest time getting arguments and options to work. If I try the above code, I get the 'too many arguments' error or the 'example option doesn't exist.'. I am going to move on for now. It seems like Lumen should have a strong console interface, since you are less likely to want to set up a login to a web interface to do stuff.

But on to other projects...

hybrid1969's avatar

Did anyone ever solve this as I do not seem able to pass any arguments to jobs.

The command gets the argument ok -

'$this->region = $this->argument('region'); customLogging::Console('arg value = '.$this->region);'

And seems to work when i queue the job -

'Queue::pushOn('region', new Add($this->region));'

But the job fails with an error -

lumen.ERROR: Symfony\Component\Debug\Exception\FatalThrowableError: Call to a member function getArgument() on null in /var/www/html/core-director/vendor/illuminate/console/Command.php:256

'protected $region;

public function __construct($region)
{
    if(isset($region)){
        $this->region = $region;
    }else{
        Log::info('Region add - missing region');
    }
}'

Been search google for days.

Please or to participate in this conversation.