|
| 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 | +namespace Simps\MQTTCLI\Command; |
| 15 | + |
| 16 | +use Simps\MQTTCLI\Handler\SubscribeHandler; |
| 17 | +use Symfony\Component\Console\Command\Command; |
| 18 | +use Symfony\Component\Console\Input\InputDefinition; |
| 19 | +use Symfony\Component\Console\Input\InputInterface; |
| 20 | +use Symfony\Component\Console\Input\InputOption; |
| 21 | +use Symfony\Component\Console\Output\OutputInterface; |
| 22 | + |
| 23 | +class SubscribeCommand extends Command |
| 24 | +{ |
| 25 | + protected static $defaultName = 'subscribe'; |
| 26 | + |
| 27 | + protected function configure() |
| 28 | + { |
| 29 | + $this->setDescription('Subscribing to topics') |
| 30 | + ->setHelp('An MQTT version 3.1/3.1.1/5.0 client for subscribing to topics') |
| 31 | + ->setDefinition( |
| 32 | + new InputDefinition([ |
| 33 | + new InputOption('host', 'H', InputOption::VALUE_OPTIONAL, 'Specify the host to connect to', 'localhost'), |
| 34 | + new InputOption('port', 'P', InputOption::VALUE_OPTIONAL, 'Connect to the port specified', 1883), |
| 35 | + new InputOption('id', 'i', InputOption::VALUE_OPTIONAL, 'The id to use for this client', ''), |
| 36 | + new InputOption('qos', null, InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Specify the quality of service to use for the message, from 0, 1 and 2'), |
| 37 | + new InputOption('topic', 't', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'The MQTT topic to subscribe to'), |
| 38 | + new InputOption('username', 'u', InputOption::VALUE_OPTIONAL, 'Provide a username to be used for authenticating with the broker'), |
| 39 | + new InputOption('pw', 'p', InputOption::VALUE_OPTIONAL, 'Provide a password to be used for authenticating with the broker'), |
| 40 | + new InputOption('clean-session', 'c', InputOption::VALUE_OPTIONAL, "Setting the 'clean session' flag", true), |
| 41 | + new InputOption('level', 'l', InputOption::VALUE_REQUIRED, 'MQTT Protocol level', 4), |
| 42 | + new InputOption('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), |
| 43 | + new InputOption('will-topic', null, InputOption::VALUE_OPTIONAL, 'The topic on which to send a Will, in the event that the client disconnects unexpectedly'), |
| 44 | + new InputOption('will-message', null, InputOption::VALUE_OPTIONAL, 'Specify a message that will be stored by the broker and sent out if this client disconnects unexpectedly'), |
| 45 | + new InputOption('will-qos', null, InputOption::VALUE_OPTIONAL, 'The QoS to use for the Will', 0), |
| 46 | + new InputOption('will-retain', null, InputOption::VALUE_OPTIONAL, 'If given, if the client disconnects unexpectedly the message sent out will be treated as a retained message', 0), |
| 47 | + new InputOption('ssl', 'S', InputOption::VALUE_OPTIONAL, 'Enable SSL encryption', false), |
| 48 | + new InputOption('config-path', null, InputOption::VALUE_OPTIONAL, 'Setting the Swoole config file path'), |
| 49 | + new InputOption('properties-path', null, InputOption::VALUE_OPTIONAL, 'Setting the Properties config file path'), |
| 50 | + new InputOption('unsubscribe', 'U', InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'Topics that need to be unsubscribed'), |
| 51 | + ]) |
| 52 | + ); |
| 53 | + } |
| 54 | + |
| 55 | + protected function execute(InputInterface $input, OutputInterface $output) |
| 56 | + { |
| 57 | + return (new SubscribeHandler())->handle($input, $output); |
| 58 | + } |
| 59 | +} |
0 commit comments