Skip to content
This repository has been archived by the owner on Jan 28, 2025. It is now read-only.

Commit

Permalink
Better sites:add error handling, and other fixes
Browse files Browse the repository at this point in the history
* Add better error output when RSD detection doesn't work.
* Add upgrade instructions to README.md
* Remove code coverage for now, and update PHPUnit configuration.
  • Loading branch information
samwilson authored Dec 12, 2024
1 parent 12dda08 commit 3d5f62d
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 24 deletions.
34 changes: 25 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,33 @@ or via commands such as `sites:add` and `sites:modify`.
## Installation

1. Clone the repository:

git clone https://github.com/samwilson/mwcli
```console
git clone https://github.com/samwilson/mwcli
```

2. Install dependencies:

cd mwcli
composer install --no-dev

3. Optionally add `mwcli` to your path:

echo 'export PATH=$PATH:'$(pwd)/bin >> ~/.profile
```console
cd mwcli
composer install --no-dev
```

3. Optionally add `mwcli` to your $PATH. For example, on Linux:
```console
echo 'export PATH=$PATH:'$(pwd)/bin >> ~/.profile
```

## Upgrading

1. Update the code:
```console
cd mwcli
git pull origin main
```

2. Update dependencies:
```console
composer install --no-dev
```

## Usage

Expand Down
26 changes: 15 additions & 11 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,26 @@

<!-- https://phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.5/phpunit.xsd"
backupGlobals="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.5/phpunit.xsd"
colors="true"
bootstrap="vendor/autoload.php"
testdox="true"
displayDetailsOnIncompleteTests="true"
displayDetailsOnSkippedTests="true"
displayDetailsOnPhpunitDeprecations="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true"
>
<testsuites>
<testsuite name="Project Test Suite">
<directory>tests</directory>
<directory>./tests/</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory>src</directory>
</whitelist>
</filter>
<logging>
<log type="coverage-clover" target="build/phpunit_clover.xml" />
</logging>
<source>
<include>
<directory suffix=".php">./src/</directory>
</include>
</source>
</phpunit>
12 changes: 9 additions & 3 deletions src/Command/SitesAddCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Addwiki\Mediawiki\Api\Client\Action\Request\ActionRequest;
use Addwiki\Mediawiki\Api\Client\MediaWiki;
use Addwiki\Mediawiki\Api\Client\RsdException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -23,8 +25,12 @@ public function execute( InputInterface $input, OutputInterface $output ) {
if ( !$url ) {
$url = $this->io->ask( $this->msg( 'sites-add-ask-url' ) );
}
/** @var Aci */
$api = MediaWiki::newFromPage( $url );
try {
$api = MediaWiki::newFromPage( $url );
} catch ( RsdException $e ) {
$this->io->error( $e->getMessage() );
return Command::FAILURE;
}
$siteinfoReq = ActionRequest::simpleGet( 'query', [ 'meta' => 'siteinfo' ] );
$siteInfo = $api->action()->request( $siteinfoReq );

Expand All @@ -36,6 +42,6 @@ public function execute( InputInterface $input, OutputInterface $output ) {
$this->setSite( $input, $siteInfo['query']['general']['wikiid'], $newSite );

$this->io->block( $this->msg( 'sites-add-added', [ $newSite['name'], $newSite['main_page_url'] ] ) );
return 0;
return Command::SUCCESS;
}
}
2 changes: 1 addition & 1 deletion tests/SitesAddCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function testAddSite( $configFilename ): void {
unlink( $configFile );
}

public function provideAddSite() {
public static function provideAddSite() {
return [
[ 'config.yml' ],
[ 'foobar.yaml' ]
Expand Down

0 comments on commit 3d5f62d

Please sign in to comment.