Skip to content

Commit ef9401e

Browse files
committed
Added a bat file for the console;
Renamed the "bin" folder to "scripts" (in accordance with PEAR2 requirements); Added replacement tasks for the console in packagexmlsetup.php and regenerated package.xml.
1 parent c2fa0ae commit ef9401e

File tree

4 files changed

+135
-20
lines changed

4 files changed

+135
-20
lines changed

package.xml

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
<email>[email protected]</email>
1212
<active>yes</active>
1313
</lead>
14-
<date>2013-08-15</date>
15-
<time>18:23:02</time>
14+
<date>2013-10-20</date>
15+
<time>05:01:52</time>
1616
<version>
1717
<release>1.0.0b4</release>
1818
<api>1.0.0</api>
@@ -39,6 +39,11 @@
3939
* Doc and CS fixes, and unit test reorganization.</notes>
4040
<contents>
4141
<dir name="/">
42+
<dir name="data" baseinstalldir="/">
43+
<file role="data" name="roscon.xml">
44+
<tasks:replace from="GIT: $Id$" to="version" type="package-info"/>
45+
</file>
46+
</dir>
4247
<dir name="docs" baseinstalldir="/">
4348
<file role="doc" name="apigen.neon">
4449
<tasks:replace from="../src" to="php_dir" type="pear-config"/>
@@ -59,6 +64,17 @@
5964
<file role="doc" name="sync-request-arguments.php"/>
6065
<file role="doc" name="sync-request-simple.php"/>
6166
</dir>
67+
<dir name="scripts" baseinstalldir="/">
68+
<file role="script" name="roscon.bat"/>
69+
<file role="script" name="roscon.php">
70+
<tasks:replace from="../src" to="php_dir" type="pear-config"/>
71+
<tasks:replace from="../../PEAR2_Net_Transmitter.git/src/" to="php_dir" type="pear-config"/>
72+
<tasks:replace from="../../PEAR2_Console_Color.git/src/" to="php_dir" type="pear-config"/>
73+
<tasks:replace from="@PEAR2_DATA_DIR@" to="data_dir" type="pear-config"/>
74+
<tasks:replace from="@PACKAGE_CHANNEL@" to="channel" type="package-info"/>
75+
<tasks:replace from="@PACKAGE_NAME@" to="name" type="package-info"/>
76+
</file>
77+
</dir>
6278
<dir name="src" baseinstalldir="/">
6379
<dir name="PEAR2">
6480
<dir name="Net">
@@ -173,8 +189,8 @@
173189
<file role="test" name="NonPersistent.php"/>
174190
<file role="test" name="Persistent.php"/>
175191
</dir>
176-
<file role="test" name="SafeTest.php"/>
177-
<file role="test" name="UnsafeTest.php"/>
192+
<file role="test" name="Safe.php"/>
193+
<file role="test" name="Unsafe.php"/>
178194
</dir>
179195
<dir name="Util">
180196
<dir name="Safe">
@@ -201,8 +217,8 @@
201217
<file role="test" name="NonPersistent.php"/>
202218
<file role="test" name="Persistent.php"/>
203219
</dir>
204-
<file role="test" name="SafeTest.php"/>
205-
<file role="test" name="UnsafeTest.php"/>
220+
<file role="test" name="Safe.php"/>
221+
<file role="test" name="Unsafe.php"/>
206222
</dir>
207223
<file role="test" name="bootstrap.php">
208224
<tasks:replace from="../src" to="php_dir" type="pear-config"/>
@@ -249,6 +265,7 @@
249265
</dependencies>
250266
<phprelease>
251267
<filelist>
268+
<install name="data/roscon.xml" as="roscon.xml"/>
252269
<install name="docs/apigen.neon" as="apigen.neon"/>
253270
<install name="docs/doxygen.ini" as="doxygen.ini"/>
254271
<install name="docs/phpdoc.dist.xml" as="phpdoc.dist.xml"/>
@@ -258,6 +275,8 @@
258275
<install name="examples/send-and-forget.php" as="examples/send-and-forget.php"/>
259276
<install name="examples/sync-request-arguments.php" as="examples/sync-request-arguments.php"/>
260277
<install name="examples/sync-request-simple.php" as="examples/sync-request-simple.php"/>
278+
<install name="scripts/roscon.bat" as="roscon.bat"/>
279+
<install name="scripts/roscon.php" as="roscon"/>
261280
<install name="src/PEAR2/Net/RouterOS/Client.php" as="PEAR2/Net/RouterOS/Client.php"/>
262281
<install name="src/PEAR2/Net/RouterOS/Communicator.php" as="PEAR2/Net/RouterOS/Communicator.php"/>
263282
<install name="src/PEAR2/Net/RouterOS/DataFlowException.php" as="PEAR2/Net/RouterOS/DataFlowException.php"/>
@@ -275,37 +294,37 @@
275294
<install name="src/PEAR2/Net/RouterOS/UnexpectedValueException.php" as="PEAR2/Net/RouterOS/UnexpectedValueException.php"/>
276295
<install name="src/PEAR2/Net/RouterOS/Util.php" as="PEAR2/Net/RouterOS/Util.php"/>
277296
<install name="tests/bootstrap.php" as="bootstrap.php"/>
297+
<install name="tests/Client/Safe.php" as="Client/Safe.php"/>
278298
<install name="tests/Client/Safe/NonPersistent.php" as="Client/Safe/NonPersistent.php"/>
279299
<install name="tests/Client/Safe/NonPersistent/EncryptedTest.php" as="Client/Safe/NonPersistent/EncryptedTest.php"/>
280300
<install name="tests/Client/Safe/NonPersistent/UnencryptedTest.php" as="Client/Safe/NonPersistent/UnencryptedTest.php"/>
281301
<install name="tests/Client/Safe/Persistent.php" as="Client/Safe/Persistent.php"/>
282302
<install name="tests/Client/Safe/Persistent/EncryptedTest.php" as="Client/Safe/Persistent/EncryptedTest.php"/>
283303
<install name="tests/Client/Safe/Persistent/UnencryptedTest.php" as="Client/Safe/Persistent/UnencryptedTest.php"/>
284-
<install name="tests/Client/SafeTest.php" as="Client/SafeTest.php"/>
304+
<install name="tests/Client/Unsafe.php" as="Client/Unsafe.php"/>
285305
<install name="tests/Client/Unsafe/NonPersistent.php" as="Client/Unsafe/NonPersistent.php"/>
286306
<install name="tests/Client/Unsafe/NonPersistent/EncryptedTest.php" as="Client/Unsafe/NonPersistent/EncryptedTest.php"/>
287307
<install name="tests/Client/Unsafe/NonPersistent/UnencryptedTest.php" as="Client/Unsafe/NonPersistent/UnencryptedTest.php"/>
288308
<install name="tests/Client/Unsafe/Persistent.php" as="Client/Unsafe/Persistent.php"/>
289309
<install name="tests/Client/Unsafe/Persistent/EncryptedTest.php" as="Client/Unsafe/Persistent/EncryptedTest.php"/>
290310
<install name="tests/Client/Unsafe/Persistent/UnencryptedTest.php" as="Client/Unsafe/Persistent/UnencryptedTest.php"/>
291-
<install name="tests/Client/UnsafeTest.php" as="Client/UnsafeTest.php"/>
292311
<install name="tests/ConnectionTest.php" as="ConnectionTest.php"/>
293312
<install name="tests/HandlingTest.php" as="HandlingTest.php"/>
294313
<install name="tests/phpunit.xml" as="phpunit.xml"/>
314+
<install name="tests/Util/Safe.php" as="Util/Safe.php"/>
295315
<install name="tests/Util/Safe/NonPersistent/EncryptedTest.php" as="Util/Safe/NonPersistent/EncryptedTest.php"/>
296316
<install name="tests/Util/Safe/NonPersistent/UnencryptedTest.php" as="Util/Safe/NonPersistent/UnencryptedTest.php"/>
297317
<install name="tests/Util/Safe/NonPersistentTest.php" as="Util/Safe/NonPersistentTest.php"/>
298318
<install name="tests/Util/Safe/Persistent/EncryptedTest.php" as="Util/Safe/Persistent/EncryptedTest.php"/>
299319
<install name="tests/Util/Safe/Persistent/UnencryptedTest.php" as="Util/Safe/Persistent/UnencryptedTest.php"/>
300320
<install name="tests/Util/Safe/PersistentTest.php" as="Util/Safe/PersistentTest.php"/>
301-
<install name="tests/Util/SafeTest.php" as="Util/SafeTest.php"/>
321+
<install name="tests/Util/Unsafe.php" as="Util/Unsafe.php"/>
302322
<install name="tests/Util/Unsafe/NonPersistent.php" as="Util/Unsafe/NonPersistent.php"/>
303323
<install name="tests/Util/Unsafe/NonPersistent/EncryptedTest.php" as="Util/Unsafe/NonPersistent/EncryptedTest.php"/>
304324
<install name="tests/Util/Unsafe/NonPersistent/UnencryptedTest.php" as="Util/Unsafe/NonPersistent/UnencryptedTest.php"/>
305325
<install name="tests/Util/Unsafe/Persistent.php" as="Util/Unsafe/Persistent.php"/>
306326
<install name="tests/Util/Unsafe/Persistent/EncryptedTest.php" as="Util/Unsafe/Persistent/EncryptedTest.php"/>
307327
<install name="tests/Util/Unsafe/Persistent/UnencryptedTest.php" as="Util/Unsafe/Persistent/UnencryptedTest.php"/>
308-
<install name="tests/Util/UnsafeTest.php" as="Util/UnsafeTest.php"/>
309328
</filelist>
310329
</phprelease>
311330
</package>

packagexmlsetup.php

Lines changed: 64 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@
3838
'tasks:replace' => array(
3939
array(
4040
'attribs' => array(
41-
'from' => '../../PEAR2_Net_Transmitter.git/src/',
42-
'to' => 'php_dir',
43-
'type' => 'pear-config'
41+
'from' => 'GIT: $Id$',
42+
'to' => 'version',
43+
'type' => 'package-info'
4444
)
4545
)
4646
)
@@ -102,6 +102,50 @@
102102
$verTask
103103
);
104104

105+
$package->files['scripts/roscon.php'] = array_merge_recursive(
106+
$package->files['scripts/roscon.php']->getArrayCopy(),
107+
$srcDirTask,
108+
array(
109+
'tasks:replace' => array(
110+
array(
111+
'attribs' => array(
112+
'from' => '../../PEAR2_Net_Transmitter.git/src/',
113+
'to' => 'php_dir',
114+
'type' => 'pear-config'
115+
)
116+
),
117+
array(
118+
'attribs' => array(
119+
'from' => '../../PEAR2_Console_Color.git/src/',
120+
'to' => 'php_dir',
121+
'type' => 'pear-config'
122+
)
123+
),
124+
array(
125+
'attribs' => array(
126+
'from' => '@PEAR2_DATA_DIR@',
127+
'to' => 'data_dir',
128+
'type' => 'pear-config'
129+
)
130+
),
131+
array(
132+
'attribs' => array(
133+
'from' => '@PACKAGE_CHANNEL@',
134+
'to' => 'channel',
135+
'type' => 'package-info'
136+
)
137+
),
138+
array(
139+
'attribs' => array(
140+
'from' => '@PACKAGE_NAME@',
141+
'to' => 'name',
142+
'type' => 'package-info'
143+
)
144+
),
145+
)
146+
)
147+
);
148+
105149
$hasCompatible = null !== $compatible;
106150
if ($hasCompatible) {
107151
$compatible->license = $package->license;
@@ -181,9 +225,25 @@
181225
$filename = substr($path->getPathname(), 2);
182226

183227
if (isset($package->files[$filename])) {
184-
$as = (strpos($filename, 'examples') === 0)
228+
$as = (strpos($filename, 'examples/') === 0)
185229
? $filename
186230
: substr($filename, strpos($filename, '/') + 1);
231+
if (strpos($filename, 'scripts/') === 0) {
232+
$parsedFilename = pathinfo($filename);
233+
if (isset($parsedFilename['extension'])
234+
&& 'php' === $parsedFilename['extension']
235+
&& !is_file(
236+
$parsedFilename['dirname'] . '/' .
237+
$parsedFilename['filename']
238+
)
239+
&& is_file(
240+
$parsedFilename['dirname'] . '/' .
241+
$parsedFilename['filename'] . '.bat'
242+
)
243+
) {
244+
$as = substr($as, 0, -4);
245+
}
246+
}
187247
$package->getReleaseToInstall('php')->installAs($filename, $as);
188248
}
189249
}

scripts/roscon.bat

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
@echo off
2+
:: Prefer PHP binary in the following order:
3+
:: 1. Whatever %PHPBIN% points to.
4+
:: 2. "php" from %cd% with one of %pathext% extensions.
5+
:: 3. "php" from a %path% path with one of %pathext% extensions.
6+
:: 4. Whatever %PHP_PEAR_PHP_BIN% points to.
7+
::
8+
:: Once a binary is found, a file with the same name as this one
9+
:: will be ran. Prefered extensions are no extension and ".php"
10+
:: in this order.
11+
::
12+
if "%PHPBIN%" == "" set PHPBIN=php
13+
if exist "%PHPBIN%" goto SET_FILE
14+
if "%PHP_PEAR_PHP_BIN%" neq "" goto USE_PEAR_BIN
15+
goto PHP_ERR
16+
:USE_PEAR_BIN
17+
set PHPBIN=%PHP_PEAR_PHP_BIN%
18+
if exist "%PHP_PEAR_PHP_BIN%" goto SET_FILE
19+
goto PHP_ERR
20+
:SET_FILE
21+
if "%PHPFILE%" == "" set PHPFILE=%~d0%~p0%~n0
22+
if exist "%PHPFILE%" goto RUN
23+
set PHPFILE=%~d0%~p0%~n0.php
24+
if exist "%PHPFILE%" goto RUN
25+
goto FILE_ERR
26+
:RUN
27+
"%PHPBIN%" "%PHPFILE%" %*
28+
goto DONE
29+
:PHP_ERR
30+
echo PHP interpreter not found. Please set the %%PHPBIN%% or %%PHP_PEAR_PHP_BIN%% environment variable to one, or add a PHP interpreter to your %%PATH%%.
31+
goto DONE
32+
:FILE_ERR
33+
echo The file to be ran was not found. It should be in the same folder, and either have a ".php" extension, or no extension at all.
34+
:DONE

bin/roscon.php renamed to scripts/roscon.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env php
12
<?php
23

34
/**
@@ -49,9 +50,10 @@
4950
//If there's no appropriate autoloader, add one
5051
if (!class_exists('PEAR2\Net\RouterOS\Communicator', true)) {
5152
include_once 'PEAR2/Autoload.php';
52-
Autoload::initialize(realpath(__DIR__ . '/../src'));
53-
Autoload::initialize(realpath(__DIR__ . '/../../Net_Transmitter.git/src'));
54-
Autoload::initialize(realpath(__DIR__ . '/../../Console_Color.git/src'));
53+
chdir(__DIR__);
54+
Autoload::initialize(realpath('../src'));
55+
Autoload::initialize(realpath('../../Net_Transmitter.git/src'));
56+
Autoload::initialize(realpath('../../Console_Color.git/src'));
5557
}
5658

5759
// Locate the data dir, in preference as:
@@ -85,15 +87,15 @@
8587
exit(11);
8688
}
8789

90+
$cmdParser = CommandLine::fromXmlFile($consoleDefFile);
8891
try {
89-
$cmdParser = CommandLine::fromXmlFile($consoleDefFile);
9092
$cmd = $cmdParser->parse();
9193
} catch (CommandLine\Exception $e) {
9294
fwrite(
9395
STDERR,
94-
'Error when parsing command line: ' . $e->getMessage()
96+
'Error when parsing command line: ' . $e->getMessage() . "\n"
9597
);
96-
exit(12);
98+
$cmdParser->displayUsage(12);
9799
}
98100

99101
$c_colors = array(

0 commit comments

Comments
 (0)