-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpeer_tools
executable file
·110 lines (97 loc) · 2.85 KB
/
peer_tools
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/php
<?php
define('APP_PATH', dirname(__FILE__));
require('includes/defines.php');
require('includes/utils.php');
require('includes/configuration.php');
require('includes/credentials.php');
require('includes/auth.php');
require('includes/parsing.php');
require('includes/cloning.php');
require('includes/cleaning.php');
require('includes/updates.php');
/**
* Main class, it all starts here.
*/
class App
{
private $configuration;
private $credentials;
private $cloning;
private $menu;
public function __construct()
{
$GLOBALS['verbose'] = false;
$GLOBALS['version'] = 3;
Utils::success('Peer Tools v' . $GLOBALS['version'] . ' - Hello !');
Utils::parse_options();
$this->configuration = new Configuration();
$this->configuration->init();
$this->credentials = new Credentials($this->configuration);
$this->credentials->init();
$this->cloning = new Cloning($this->credentials);
$this->menu = array(
'Clone remaining corrections' => [$this->cloning, 'clone_corrections'],
'Clean corrections folder (make fclean)' => ['Cleaning', 'fclean_corrections'],
'Remove .git folders' => ['Cleaning', 'remove_git_corrections'],
'Delete credentials' => [$this->credentials, 'delete_credentials'],
'Delete configuration file' => [$this->configuration, 'delete_configuration'],
'Check for updates' => ['Updates', 'check_updates'],
'Exit' => [$this, 'quit']
);
}
public function run()
{
$choice = 0;
Updates::check_updates(true);
while (42)
{
$choice = Utils::menu('Choose your option', array_keys($this->menu), 'Please enter your choice');
$choice = array_keys($this->menu)[$choice];
if (method_exists($this->menu[$choice][0], $this->menu[$choice][1]))
call_user_func(array($this->menu[$choice][0], $this->menu[$choice][1]));
else
Utils::error('This function doesn\'t exist.');
}
}
/**
* Exits the app.
*
* @param int $save 1 to quit with saving, 0 to quit without.
* @return Configuration array or false if an error occured.
*/
public function quit($save = 1)
{
if (!$save)
Utils::success("Bye bye !");
else
{
Utils::info('Saving configuration...');
if (!$this->configuration->save_configuration())
{
Utils::error("Error while saving configuration.");
exit(1);
}
else
{
Utils::info("Configuration successfully saved.");
Utils::success("Bye bye !");
}
}
exit(0);
}
/**
* Getters & Setters
*/
public function get_configuration()
{
return $this->configuration;
}
public function get_credentials()
{
return $this->credentials;
}
}
$app = new App();
$app->run();
?>