check 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. include('api.1984tech.php');
  3. $tech = new OrwellWorld();
  4. //need at least 1 command line argument
  5. if ($argc >= 2) {
  6. $allowedOptions = array(
  7. '--run' => 'run all checks for local and remote domains lists',
  8. '--unique' => 'check domains list specified in DOMAINS_LIST option, for domain duplicates',
  9. '--unique-local' => 'check local domains.txt for domain duplicates',
  10. '--validity' => 'check domains list for for validity',
  11. '--validity-local' => 'check local domains list for for validity',
  12. '--sync' => 'sync 1984 local domains base with another list format: --sync [domains list file path or HTTP URL]',
  13. '--help' => 'show small help'
  14. );
  15. $option = $argv[1];
  16. if (isset($allowedOptions[$option])) {
  17. switch ($option) {
  18. case '--run':
  19. print($tech->runAllChecks());
  20. break;
  21. case '--unique':
  22. print($tech->uniqueCheck());
  23. break;
  24. case '--unique-local':
  25. print($tech->uniqueCheck(true));
  26. break;
  27. case '--validity':
  28. print($tech->validityCheck());
  29. break;
  30. case '--validity-local':
  31. print($tech->validityCheck(true));
  32. break;
  33. case '--sync':
  34. $customUrl = '';
  35. if (isset($argv[2])) {
  36. $customUrl = $argv[2];
  37. }
  38. print($tech->sync($customUrl));
  39. break;
  40. case '--help':
  41. print('Usage: php cli/check --option' . PHP_EOL);
  42. print('Available options:' . PHP_EOL);
  43. if (!empty($allowedOptions)) {
  44. foreach ($allowedOptions as $optionName => $optionDesc) {
  45. print($optionName . ' - ' . $optionDesc . PHP_EOL);
  46. }
  47. }
  48. break;
  49. }
  50. } else {
  51. print('Unknown command line option: ' . $option . PHP_EOL);
  52. }
  53. } else {
  54. //option requirement notification
  55. print('At least one option required.' . PHP_EOL);
  56. print('Usage: php cli/check --option' . PHP_EOL);
  57. print('For example: php cli/check --help' . PHP_EOL);
  58. }