Skip to content

Commit 2fd994d

Browse files
committed
Merge branch 'feature/improved-console-support' into develop
2 parents f06415d + 4bf9b97 commit 2fd994d

File tree

3 files changed

+102
-13
lines changed

3 files changed

+102
-13
lines changed

PHPCtags.class.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ class PHPCtags
33
{
44
private $mFile;
55

6+
private $mFiles;
7+
68
private static $mKinds = array(
79
'c' => 'class',
810
'm' => 'method',
@@ -48,6 +50,18 @@ public static function getMKinds()
4850
return self::$mKinds;
4951
}
5052

53+
public function addFile($file)
54+
{
55+
$this->mFiles[realpath($file)] = 1;
56+
}
57+
58+
public function addFiles($files)
59+
{
60+
foreach ($files as $file) {
61+
$this->addFile($file);
62+
}
63+
}
64+
5165
private function getNodeAccess($node)
5266
{
5367
if ($node->isPrivate()) return 'private';
@@ -294,7 +308,20 @@ private function render()
294308
return $str;
295309
}
296310

297-
public function export($file)
311+
public function export()
312+
{
313+
if (empty($this->mFiles)) {
314+
throw new PHPCtagsException('No File specified.');
315+
}
316+
317+
foreach (array_keys($this->mFiles) as $file) {
318+
$this->process($file);
319+
}
320+
321+
return $this->render();
322+
}
323+
324+
private function process($file)
298325
{
299326
if (is_dir($file) && isset($this->mOptions['R'])) {
300327
$iterator = new RecursiveIteratorIterator(
@@ -329,7 +356,6 @@ public function export($file)
329356
$this->struct($this->mParser->parse(file_get_contents($this->mFile)), TRUE)
330357
);
331358
}
332-
return $this->render();
333359
}
334360
}
335361

phpctags

Lines changed: 72 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,80 @@ if (file_exists($autoload = __DIR__ . '/vendor/autoload.php')) {
1212
);
1313
}
1414

15+
$version = <<<'EOF'
16+
Version: 0.2
17+
18+
Exuberant Ctags compatiable PHP enhancement, Copyright (C) 2012 Techlive Zheng
19+
Addresses: <techlivezheng@gmail.com>, https://github.com/techlivezheng/phpctags
20+
EOF;
21+
1522
$options = getopt('af:Nno:RuV', array(
1623
'append::',
1724
'debug',
1825
'exclude:',
1926
'excmd::',
2027
'fields::',
2128
'format::',
29+
'help',
2230
'recurse::',
2331
'sort::',
2432
'version',
2533
'memory::',
2634
));
2735

36+
$options_info = <<<'EOF'
37+
phpctags currently only supports a subset of the original ctags' options.
38+
39+
Usage: phpctags [options] [file(s)]
40+
41+
-a Append the tags to an existing tag file.
42+
-f <name>
43+
Write tags to specified file. Value of "-" writes tags to stdout
44+
["tags"].
45+
-n Equivalent to --excmd=number.
46+
-N Equivalent to --excmd=pattern.
47+
-o Alternative for -f.
48+
-R Equivalent to --recurse.
49+
-u Equivalent to --sort=no.
50+
-V Equivalent to --verbose.
51+
--append=[yes|no]
52+
Should tags should be appended to existing tag file [no]?
53+
--debug
54+
phpctags only
55+
Repect PHP's error level configuration.
56+
--exclude=pattern
57+
Exclude files and directories matching 'pattern'.
58+
--excmd=number|pattern|mix
59+
Uses the specified type of EX command to locate tags [mix].
60+
--fields=[+|-]flags
61+
Include selected extension fields (flags: "afmikKlnsStz") [fks].
62+
--format=level
63+
Force output of specified tag file format [2].
64+
--help
65+
Print this option summary.
66+
--memory=[-1|bytes|KMG]
67+
phpctags only
68+
Set how many memories phpctags could use.
69+
--recurse=[yes|no]
70+
Recurse into directories supplied on command line [no].
71+
--sort=[yes|no|foldcase]
72+
Should tags be sorted (optionally ignoring case) [yes]?.
73+
--version
74+
Print version identifier to standard output.
75+
EOF;
76+
77+
// prune options and its value from the $argv array
78+
$argv_ = array();
79+
foreach ($options as $option => $value) {
80+
foreach ($argv as $key => $chunk) {
81+
$regex = '/^'. (isset($option[1]) ? '--' : '-') . $option . '/';
82+
if ($chunk == $value && $argv[$key-1][0] == '-' || preg_match($regex, $chunk)) {
83+
array_push($argv_, $key);
84+
}
85+
}
86+
}
87+
while ($key = array_pop($argv_)) unset($argv[$key]);
88+
2889
// option -V is an alternative to --version
2990
if (isset($options['V'])) {
3091
$options['version'] = FALSE;
@@ -34,21 +95,21 @@ if (!isset($options['debug'])) {
3495
error_reporting(0);
3596
}
3697

37-
if (isset($options['version'])) {
38-
echo <<<'EOF'
39-
Version: 0.2
40-
41-
Exuberant Ctags compatiable PHP enhancement, Copyright (C) 2012 Techlive Zheng
42-
Addresses: <techlivezheng@gmail.com>, https://github.com/techlivezheng/phpctags
98+
if (isset($options['help'])) {
99+
echo $version;
100+
echo PHP_EOL;
101+
echo PHP_EOL;
102+
echo $options_info;
103+
exit;
104+
}
43105

44-
EOF;
106+
if (isset($options['version'])) {
107+
echo $version;
45108
exit;
46109
}
47110

48111
array_shift($argv);
49112

50-
$file = array_pop($argv);
51-
52113
// option -o is an alternative to -f
53114
if (isset($options['o']) && !isset($options['f'])) {
54115
$options['f'] = $options['o'];
@@ -133,7 +194,8 @@ if (isset($options['recurse'])) {
133194

134195
try {
135196
$ctags = new PHPCtags($options);
136-
$result = $ctags->export($file);
197+
$ctags->addFiles($argv);
198+
$result = $ctags->export();
137199
} catch (Exception $e) {
138200
die("phpctags: {$e->getMessage()}");
139201
}

tests/PHPCtagsTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,10 @@ public function testExport($testcase)
5959
$phpctags_object = new PHPCtags(
6060
$testcase_object->getOptions()
6161
);
62-
$testcase_result = $phpctags_object->export(
62+
$phpctags_object->addFile(
6363
$testcase_object->getExample()
6464
);
65+
$testcase_result = $phpctags_object->export();
6566

6667
$expected_result = __DIR__ . '/' . $testcase_id . '.testcase.expect';
6768
$acctural_result = __DIR__ . '/' . $testcase_id . '.testcase.result';

0 commit comments

Comments
 (0)