Skip to content

Commit 6e5efb6

Browse files
committed
v1.0.1: new fixes and improvements
1 parent 0432a5e commit 6e5efb6

30 files changed

+2507
-2250
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1+
.php-cs-fixer.cache
2+
composer.lock
13
vendor/
4+
src/Command/Custom/

.php-cs-fixer.php

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
$config = (new PhpCsFixer\Config())
4+
->setIndent(' ')
5+
->setRules([
6+
'multiline_whitespace_before_semicolons' => [
7+
'strategy' => 'no_multi_line',
8+
],
9+
'align_multiline_comment' => ['comment_type' => 'all_multiline'],
10+
'array_indentation' => true,
11+
'array_syntax' => ['syntax' => 'short'],
12+
'backtick_to_shell_exec' => true,
13+
'braces' => true,
14+
'indentation_type' => true,
15+
'binary_operator_spaces' => [
16+
'operators' => [
17+
'=>' => 'align',
18+
],
19+
'default' => null,
20+
],
21+
'method_chaining_indentation' => true,
22+
]);
23+
24+
return $config;

README.md

+23-7
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,33 @@ A simple [OVH API](https://api.ovh.com/console/) client for managing OVH infrast
1414
- Application management
1515

1616
**Dedicated Servers**
17-
- Search by name/reverse (using RegExps)
18-
- Retrieve information
19-
- Configure boot mode
20-
- Enable/disable OVH monitoring
21-
- Access KVM console (requires Java-WS)
17+
- Search (using regular expressions)
18+
- Retrieve server details
19+
- Manage boot mode (rescue, harddisk)
20+
- Manage OVH monitoring
21+
- Access KVM console (HTML5, JNLP supported)
2222
- Perform IPMI reset
2323
- Request hardware reboot
24+
- Manage service renewal
2425

2526
**vRack**
2627
- List associated servers
27-
- Assign servers to vRack
28+
- Manage vRack servers assignment
2829

2930
**DNS**
3031
- Reverse DNS management
31-
- Automatically resolve reverse hostname to OVH `nsXXX` hostname
32+
- Resolve reverse DNS to OVH `ns*` hostnames
3233

34+
**Tickets**
35+
- List open tickets
36+
- Open ticket
37+
- Reply to ticket
38+
- Close ticket
39+
40+
**IPs**
41+
- List failover IPs
42+
- Resolve from service name to reverse
43+
- Resolve from reverse to service name
3344

3445
## Requirements
3546

@@ -45,6 +56,11 @@ $ cd php-ovh-cli
4556
$ composer update
4657
```
4758

59+
Also works on PHP8, but with some workaround:
60+
```
61+
$ composer update --ignore-platform-reqs
62+
```
63+
4864
If you prefer to have a standalone executable, then create a PHAR package:
4965
```
5066
$ ./create-phar.php

cli.php

+46-45
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,94 @@
11
<?php
22

3-
use GetOpt\GetOpt;
4-
use GetOpt\Option;
5-
use GetOpt\Command;
63
use GetOpt\ArgumentException;
74
use GetOpt\ArgumentException\Missing;
5+
use GetOpt\Command;
6+
use GetOpt\GetOpt;
7+
use GetOpt\Option;
8+
use OvhCli\Cli;
9+
use OvhCli\Ovh;
810
use Phpfastcache\CacheManager;
911
use Phpfastcache\Config\Config as CacheConfig;
10-
use Phpfastcache\Core\phpFastCache;
11-
use OvhCli\Ovh;
12-
use OvhCli\Cli;
1312

14-
require_once __DIR__ . '/vendor/autoload.php';
13+
require_once __DIR__.'/vendor/autoload.php';
1514

1615
error_reporting(E_ALL ^ E_NOTICE);
17-
define('CONFIG_FILE', getenv("HOME").'/.ovh-cli.config.json');
18-
define('COMMAND_PATH', __DIR__ . '/src/Command');
16+
define('CONFIG_FILE', getenv('HOME').'/.ovh-cli.config.json');
17+
define('COMMAND_PATH', __DIR__.'/src/Command');
1918

2019
// set cache
2120
CacheManager::setDefaultConfig(new CacheConfig([
22-
"path" => sys_get_temp_dir(),
23-
"itemDetailedDate" => false
21+
'path' => sys_get_temp_dir(),
22+
'itemDetailedDate' => false,
2423
]));
2524

2625
$cacheManager = CacheManager::getInstance('files');
2726
Ovh::setCacheManager($cacheManager);
2827

2928
$getOpt = new GetOpt();
3029
$getOpt->addOptions([
31-
Option::create('?', 'help', GetOpt::NO_ARGUMENT)
32-
->setDescription('Show this help and quit'),
33-
Option::create('t', 'dry-run', GetOpt::NO_ARGUMENT)
34-
->setDescription('Will fake PUT/POST/DELETE requests'),
35-
Option::create('g', 'grep', GetOpt::NO_ARGUMENT)
36-
->setDescription('Greppable output'),
37-
Option::create('n', 'no-cache', GetOpt::NO_ARGUMENT)
38-
->setDescription('Disable cache')
30+
Option::create('?', 'help', GetOpt::NO_ARGUMENT)
31+
->setDescription('Show this help and quit'),
32+
Option::create('t', 'dry-run', GetOpt::NO_ARGUMENT)
33+
->setDescription('Will fake PUT/POST/DELETE requests'),
34+
Option::create('g', 'grep', GetOpt::NO_ARGUMENT)
35+
->setDescription('Grep-friendly output'),
36+
Option::create('n', 'no-cache', GetOpt::NO_ARGUMENT)
37+
->setDescription('Disable cache'),
3938
]);
4039

4140
$commands = [];
4241
// glob() doesn't work with PHAR, so use iterators
4342
$directory = new \RecursiveIteratorIterator(
44-
new \RecursiveDirectoryIterator(COMMAND_PATH)
43+
new \RecursiveDirectoryIterator(COMMAND_PATH)
4544
);
4645
// commands autoloading
47-
foreach($directory as $file) {
48-
if (!preg_match('/\.php$/', $file)) {
49-
continue;
50-
}
51-
$relativePath = substr($file, strlen(COMMAND_PATH) + 1);
52-
$classSuffix = str_replace(['.php',DIRECTORY_SEPARATOR], ['','\\'], $relativePath);
53-
$class = '\\OvhCli\\Command\\' . $classSuffix;
54-
$command = new $class;
55-
$name = $command->getName();
56-
$commands[$name] = $command;
46+
foreach ($directory as $file) {
47+
if (!preg_match('/\.php$/', $file)) {
48+
continue;
49+
}
50+
$relativePath = substr($file, strlen(COMMAND_PATH) + 1);
51+
$classSuffix = str_replace(['.php', DIRECTORY_SEPARATOR], ['', '\\'], $relativePath);
52+
$class = '\\OvhCli\\Command\\'.$classSuffix;
53+
$command = new $class();
54+
$name = $command->getName();
55+
$commands[$name] = $command;
5756
}
5857
// I like commands to be in alphabetical order :)
5958
ksort($commands);
6059
$getOpt->addCommands($commands);
6160

6261
try {
63-
try {
64-
$getOpt->process();
65-
} catch (Missing $exception) {
66-
if (!$getOpt->getOption('help')) {
67-
throw $exception;
68-
}
62+
try {
63+
$getOpt->process();
64+
} catch (Missing $exception) {
65+
if (!$getOpt->getOption('help')) {
66+
throw $exception;
6967
}
68+
}
7069
} catch (ArgumentException $exception) {
71-
file_put_contents('php://stderr', $exception->getMessage() . PHP_EOL);
72-
echo PHP_EOL . $getOpt->getHelpText();
73-
exit;
70+
file_put_contents('php://stderr', $exception->getMessage().PHP_EOL);
71+
echo PHP_EOL.$getOpt->getHelpText();
72+
73+
exit;
7474
}
7575

7676
// show help and quit
7777
$command = $getOpt->getCommand();
7878
if (!$command || $getOpt->getOption('help')) {
79-
echo $getOpt->getHelpText();
80-
exit;
79+
echo $getOpt->getHelpText();
80+
81+
exit;
8182
}
8283

8384
if ($getOpt->getOption('dry-run')) {
84-
Ovh::setDryRun(true);
85-
Cli::warning("running in DRY-RUN mode");
85+
Ovh::setDryRun(true);
86+
Cli::warning('running in DRY-RUN mode');
8687
}
8788

8889
if ($getOpt->getOption('no-cache')) {
89-
Ovh::disableCache();
90-
Cli::warning("cache is disabled");
90+
Ovh::disableCache();
91+
Cli::warning('cache is disabled');
9192
}
9293

9394
// call the requested command

0 commit comments

Comments
 (0)