private function publishCommands($register)
    {
        // read all plugin commands from folder
        $commandPath = $this->path . '/src/Commands';
        if (!file_exists($commandPath)) {
            return;
        }
        $classes = [];
        list_classes($classes, $commandPath, $this->namespace . 'Commands');

        // read existing command list
        $manifest = $this->getManifest('commands');
        /** @noinspection PhpIncludeInspection */
        $list = file_exists($manifest) ? include $manifest : [];

        // merge plugin commands to the list (plugin overrides commands if exist)
        foreach ($classes as $class) {
            /** @var CommandContract $command */
            $command = new $class;
            $name = $command->name();
            if ($register) {
                $description = trim($command->description() ?: '');
                $list[$name] = compact('class', 'name', 'description');
            }
            else {
                unset($list[$name]);
            }
        }

        // save the new command list
        ksort($list);
        $this->saveArray($manifest, $list);
    }