|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * This file is part of Simps |
| 4 | + * |
| 5 | + * @link https://github.com/simps/mqtt |
| 6 | + * @contact Lu Fei <lufei@simps.io> |
| 7 | + * |
| 8 | + * For the full copyright and license information, |
| 9 | + * please view the LICENSE file that was distributed with this source code |
| 10 | + */ |
| 11 | + |
| 12 | +declare(strict_types=1); |
| 13 | + |
| 14 | +namespaceSimps\MQTTCLI\Command; |
| 15 | + |
| 16 | +useSymfony\Component\Console\Command\Command; |
| 17 | +useSymfony\Component\Console\Input\InputDefinition; |
| 18 | +useSymfony\Component\Console\Input\InputInterface; |
| 19 | +useSymfony\Component\Console\Input\InputOption; |
| 20 | +useSymfony\Component\Console\Output\OutputInterface; |
| 21 | + |
| 22 | +class PublishCommandextends Command |
| 23 | +{ |
| 24 | +protectedstatic$defaultName ='publish'; |
| 25 | + |
| 26 | +protectedfunctionconfigure() |
| 27 | + { |
| 28 | +$this->setDescription('Publishing simple messages') |
| 29 | + ->setHelp('An MQTT version 3.1/3.1.1/5.0 client for publishing simple messages') |
| 30 | + ->setDefinition( |
| 31 | +newInputDefinition([ |
| 32 | +newInputOption('host','H', InputOption::VALUE_OPTIONAL,'Specify the host to connect to','localhost'), |
| 33 | +newInputOption('port','P', InputOption::VALUE_OPTIONAL,'Connect to the port specified',1883), |
| 34 | +newInputOption('topic','t', InputOption::VALUE_REQUIRED,'The MQTT topic on which to publish the message'), |
| 35 | +newInputOption('message','m', InputOption::VALUE_REQUIRED,'Send a single message from the command line'), |
| 36 | +newInputOption('id','i', InputOption::VALUE_OPTIONAL,'The id to use for this client'), |
| 37 | +newInputOption('qos',null, InputOption::VALUE_OPTIONAL,'Specify the quality of service to use for the message, from 0, 1 and 2',0), |
| 38 | +newInputOption('dup',null, InputOption::VALUE_OPTIONAL,'',0), |
| 39 | +newInputOption('retain','r', InputOption::VALUE_OPTIONAL,'',0), |
| 40 | +newInputOption('username','u', InputOption::VALUE_OPTIONAL,'Provide a username to be used for authenticating with the broker'), |
| 41 | +newInputOption('pw','p', InputOption::VALUE_OPTIONAL,'Provide a password to be used for authenticating with the broker'), |
| 42 | +newInputOption('disable-clean-session','c', InputOption::VALUE_OPTIONAL,"Disable the 'clean session' flag",false), |
| 43 | +newInputOption('level','l', InputOption::VALUE_REQUIRED,'MQTT Protocol level',3), |
| 44 | +newInputOption('keepalive','k', InputOption::VALUE_OPTIONAL,'The number of seconds between sending PING commands to the broker for the purposes of informing it we are still connected and functioning',0), |
| 45 | +newInputOption('will-topic','wt', InputOption::VALUE_OPTIONAL,'The topic on which to send a Will, in the event that the client disconnects unexpectedly'), |
| 46 | +newInputOption('will-message','wm', InputOption::VALUE_OPTIONAL,'Specify a message that will be stored by the broker and sent out if this client disconnects unexpectedly'), |
| 47 | +newInputOption('will-qos','wq', InputOption::VALUE_OPTIONAL,'The QoS to use for the Will',0), |
| 48 | +newInputOption('will-retain','wr', InputOption::VALUE_OPTIONAL,'If given, if the client disconnects unexpectedly the message sent out will be treated as a retained message',0), |
| 49 | + ]) |
| 50 | + ); |
| 51 | + } |
| 52 | + |
| 53 | +protectedfunctionexecute(InputInterface$input,OutputInterface$output) |
| 54 | + { |
| 55 | +return Command::SUCCESS; |
| 56 | + } |
| 57 | +} |