forked from gwen001/github-search
-
Notifications
You must be signed in to change notification settings - Fork 0
/
github-search.php
executable file
·122 lines (94 loc) · 1.9 KB
/
github-search.php
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
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/php
<?php
spl_autoload_register(function ( $c ) {
include( dirname(__FILE__).'/class.'.$c.'.php' );
});
set_time_limit( 0 );
// parse command line
{
$options = '';
$options .= 'c:';
$options .= 'd';
$options .= 'e:';
$options .= 'f:';
$options .= 'h';
$options .= 'l:';
$options .= 'm';
$options .= 'n';
$options .= 'p:';
$options .= 'o:';
$options .= 'r:';
$options .= 's:';
$options .= 't:';
$t_options = getopt( $options );
//var_dump( $t_options );
$gsearch = new GitHubSearch();
foreach( $t_options as $k=>$v )
{
switch( $k )
{
case 'c':
$gsearch->setCookie( $v );
break;
case 'd':
$gsearch->enableDownload();
break;
case 'e':
$gsearch->setExtension( $v );
break;
case 'f':
$gsearch->setFilename( $v );
break;
case 'h':
Utils::help();
break;
case 'l':
$gsearch->setLanguage( $v );
break;
case 'm':
$gsearch->searchCommit( true );
break;
case 'n':
$gsearch->setColorOutput( false );
break;
case 'o':
$gsearch->setOrganization( $v );
break;
case 'p':
$gsearch->setRepository( $v );
break;
case 'r':
$gsearch->setMaxResult( $v );
break;
case 's':
$gsearch->setString( $v );
break;
case 't':
$gsearch->setAuthToken( $v );
break;
default:
Utils::help( 'Unknown option: '.$k );
}
}
if( !$gsearch->getString() && !$gsearch->getFilename() ) {
Utils::help( 'Search param not found, provide at least a filename or a string' );
}
if( !$gsearch->getOrganization() && !$gsearch->getCookie() && !$gsearch->getAuthToken() ) {
Utils::help( 'You must provide cookie session to perform queries without organization name' );
}
}
// ---
// main loop
{
if( $gsearch->getAuthToken() ) {
$cnt_result = $gsearch->runApi();
} else {
$cnt_result = $gsearch->run();
}
if( $cnt_result ) {
$gsearch->printResult();
}
}
// ---
exit();
?>