Skip to content

Commit

Permalink
Get rid of extended usage, make usage pretty
Browse files Browse the repository at this point in the history
  • Loading branch information
austinhyde committed Jan 16, 2016
1 parent 95ac6cc commit e9b73a7
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 87 deletions.
12 changes: 1 addition & 11 deletions bin/dbsteward
Expand Up @@ -24,18 +24,8 @@ try {
require_once 'DBSteward/dbsteward.php';
}

if (isset($argv[1]) && strcasecmp($argv[1], '--help') == 0) {
echo dbsteward::usage_extended();
exit(0);
}

if (!isset($argv[1]) || strlen($argv[1]) == 0) {
echo dbsteward::usage();
exit(0);
}

$dbg = new dbsteward();
$dbg->arg_parse();
$dbg->arg_parse($argv);
}
catch (exception $e) {
if (dbsteward::$DEBUG) {
Expand Down
93 changes: 17 additions & 76 deletions lib/DBSteward/dbsteward.php
Expand Up @@ -166,84 +166,14 @@ function __construct() {
}

public static function usage() {
$s = "DBSteward Version " . self::VERSION . "
Usage:
Global Switches and Flags
--sqlformat=<pgsql8|mssql10|mysql5>
--requireslonyid require tables and sequences to specify a valid slonyId
--requireslonysetid require slonyIds to be associated with a slonySetId
--generateslonik generate slonik scripts to subscribe to or upgrade slony replicated db
--quoteschemanames quote schema names in SQL output
--quotetablenames quote table names in SQL output
--quotecolumnnames quote column names in SQL output
--quoteallnames quote ALL identifiers in SQL output
--quoteillegalnames quote illegal identifiers and treat as a warning, rather than an error.
--quotereservednames quote reserved identifiers and treat as a warning, rather than an error.
-v[v[v]] see more detail (verbose). -vvv is not advised for normal use.
-q[q] see less detail (quiet).
--debug display extended information about errors. Automatically implies -vv.
Generating SQL DDL / DML / DCL
--xml=<database.xml> ...
--pgdataxml=<pgdata.xml> ... postgresql SELECT database_to_xml() result to overlay in composite definition
Generating SQL DDL / DML / DCL difference statements to upgrade an 'old' database to the 'new' XML definition
--oldxml=<database.xml> ...
--newxml=<newdatabase.xml> ...
--onlyschemasql
--onlydatasql
--onlytable=<schema.table> ...
--singlestageupgrade combine upgrade stages into one file
--maxstatementsperfile how many DDL / DML / DCL statements per upgrade file segment
--ignoreoldnames ignore oldSchemaName oldTableName oldColumnName attributes when differencing
--ignorecustomroles ignore grants for custom roles
--ignoreprimarykeyerrors ignore primary key errors when diffing two definitions
XML utilities
--xmlsort=<database.xml> ...
--xmlconvert=<database.xml> ...
--xmldatainsert=<tabledata.xml>
--xmlcollectdataaddendums=N collect the last N xml files specified during a build into an aggregate file
Output options
--outputdir directory to write all output files
default is location of --xml or --newxml file
--outputfileprefix output file prefix to use for artifact files
default is first XML file basename
";
return $s;
}

public static function usage_extended() {
$s = dbsteward::usage();
$s .= "DBSteward Conversion and Comparison tools:
SQL diffing
--oldsql=<old.sql> ...
--newsql=<old.sql> ...
--outputfile=<outputfile.ext>
Slony utils
--slonikconvert=<slonyconfig.slonik>
--slonycompare=<database.xml> ... generate table SELECT statements for database health comparison between replicas
--slonydiffold=<olddatabase.xml> ... compare table slonyId assignment between two versions of a database definition
--slonydiffnew=<newdatabase.xml> ...
--slonyidin=<database.xml> read this file's definition
--slonyidout=<compositeoutput.xml> output it here with slonyids specified, based on requireslonyid and requireslonysetid
--slonyidstartvalue=1 start slony IDs at this number
--slonyidsetvalue=1 use this slony set ID for any unspecified slonySetId attributes
Database definition extraction utilities
--dbschemadump
--dbdatadiff=<againstdatabase.xml> ...
--dbhost=<hostname>
--dbport=<TCP-port>
--dbname=<database_name> for mysql5, specify a comma-separated list of databases. e.g. --dbname=one,two,three
--dbuser=<username>
--dbpassword=<password>
Format-specific options
--useautoincrementoptions mysql5: Apply AUTO_INCREMENT tableOptions. By default these are ignored.
--useschemaprefix mysql5: Instead of merging schemas together (mysql5 default behavior),
prefix each database object with the schema name.
";
return $s;
$VERSION = self::VERSION;
ob_start();
include __DIR__ . '/usage.php';
return ob_get_clean();
}

public function arg_parse() {
$short_opts = 'vq';
public function arg_parse($argv) {
$short_opts = 'hvq';
$long_opts = array(
"sqlformat::",
"xml::",
Expand Down Expand Up @@ -298,6 +228,17 @@ public function arg_parse() {
$options = getopt($short_opts, $long_opts);
self::set_verbosity($options);

if (count($argv) == 1 || isset($options['help']) || isset($options['h'])) {
$c = new Colors\Color();
$c->setTheme(array(
'header' => array('underline', 'dark_gray'),
'keyword' => array('green'),
'value' => array('yellow')
));
echo $c->colorize(self::usage()) . PHP_EOL;
exit(1);
}

$files = array(
'old' => array(),
'new' => array(),
Expand Down
88 changes: 88 additions & 0 deletions lib/DBSteward/usage.php
@@ -0,0 +1,88 @@
<?php /*
Header generated by `figlet -f chunky dbsteward`
Color scheme located in dbsteward::arg_parse()
*/ ?>
__ __ __ __
.--| | |--.-----.| |_.-----.--.--.--.---.-.----.--| |
| _ | _ |__ --|| _| -__| | | | _ | _| _ |
|_____|_____|_____||____|_____|________|___._|__| |_____|

<keyword>DBSteward</keyword> version <value><?php echo $VERSION ?></value>

<header>Global Switches and Flags</header>
<keyword>--sqlformat=</keyword><value><pgsql8|mssql10|mysql5></value> change the SQL dialect to operate in. If not specified or cannot be derived
from input, pgsql8 will be used by default.
<keyword>-v[v[v]]</keyword> see more detail (verbose). -vvv is not advised for normal use.
<keyword>-q[q]</keyword> see less detail (quiet).
<keyword>--debug</keyword> display extended information about errors. Automatically implies -vv.
<keyword>-h, --help</keyword> show this usage information

<keyword>--quoteschemanames</keyword> quote schema names in SQL output
<keyword>--quotetablenames</keyword> quote table names in SQL output
<keyword>--quotecolumnnames</keyword> quote column names in SQL output
<keyword>--quoteallnames</keyword> quote ALL identifiers in SQL output
<keyword>--quoteillegalnames</keyword> quote illegal identifiers and treat as a warning, rather than an error.
<keyword>--quotereservednames</keyword> quote reserved identifiers and treat as a warning, rather than an error.

<header>Generating SQL DDL / DML / DCL</header>
<keyword>--xml=</keyword><value><database.xml></value><keyword> ...</keyword> adds an XML file to be processed. Can be specified more than once, and
subsequent files will be overlayed on top of previous files.
<keyword>--pgdataxml=</keyword><value><pgdata.xml></value><keyword> ...</keyword> pgsql8: overlay database_to_xml() formatted data. Multiples are overlayed.

<header>Generating SQL DDL / DML / DCL difference statements to upgrade an 'old' database to the 'new' XML definition</header>
<keyword>--oldxml=</keyword><value><database.xml></value><keyword> ...</keyword> adds an XML file to use for the old definition. Multiples are overlayed.
<keyword>--newxml=</keyword><value><newdatabase.xml></value><keyword> ...</keyword> adds an XML file to use for the new definition. Multiples are overlayed.
<keyword>--onlyschemasql</keyword> only upgrade schemas (DDL)
<keyword>--onlydatasql</keyword> only upgrade static data (DML)
<keyword>--onlytable=</keyword><value><schema.table></value><keyword> ...</keyword> only upgrade a single table
<keyword>--singlestageupgrade</keyword> combine upgrade stages into one file, instead of the normal 4 stages
<keyword>--maxstatementsperfile</keyword> how many DDL / DML / DCL statements per upgrade file segment
<keyword>--ignoreoldnames</keyword> ignore oldSchemaName oldTableName oldColumnName attributes when differencing
<keyword>--ignorecustomroles</keyword> ignore grants for custom roles
<keyword>--ignoreprimarykeyerrors</keyword> ignore primary key errors when diffing two definitions

<header>Database definition extraction utilities</header>
<keyword>--dbschemadump</keyword> operate in extraction mode - export a live database schema as DBSteward XML
<keyword>--dbdatadiff=</keyword><value><againstdatabase.xml></value><keyword> ...</keyword>
<keyword>--dbhost=</keyword><value><hostname></value> the database host to connect to
<keyword>--dbport=</keyword><value><port></value> the database port to connect to
<keyword>--dbname=</keyword><value><name></value> the database name to connect to
mysql5: a comma-separated list may be given, each will be extracted as its
own "schema" in the resulting XML
<keyword>--dbuser=</keyword><value><username></value> the database user to connect as
<keyword>--dbpassword[=</keyword><value><password></value><keyword>]</keyword> the password to authenticate with. If no value is given, the empty password
is used. If omitted entirely, you will be prompted for a password.

<header>XML utilities</header>
<keyword>--xmlsort=</keyword><value><database.xml></value><keyword> ...</keyword>
<keyword>--xmlconvert=</keyword><value><database.xml></value><keyword> ...</keyword>
<keyword>--xmldatainsert=</keyword><value><tabledata.xml></value>
<keyword>--xmlcollectdataaddendums=</keyword><value>N</value> collect the last N xml files specified during a build into an aggregate file.
this is useful for advanced deployment strategies and out-of-band processing.

<header>Output options</header>
<keyword>--outputdir</keyword> directory to write all output files. default is location of --xml or --newxml file
<keyword>--outputfileprefix</keyword> output file prefix to use for artifact files. default is first XML file basename

<header>SQL diffing</header>
<keyword>--oldsql=</keyword><value><old.sql></value><keyword> ...</keyword>
<keyword>--newsql=</keyword><value><old.sql></value><keyword> ...</keyword>
<keyword>--outputfile=</keyword><value><outputfile.ext></value>

<header>Slony utils</header>
<keyword>--requireslonyid</keyword> require tables and sequences to specify a valid slonyId
<keyword>--requireslonysetid</keyword> require slonyIds to be associated with a slonySetId
<keyword>--generateslonik</keyword> generate slonik scripts to subscribe to or upgrade slony replicated db
<keyword>--slonikconvert=</keyword><value><slonyconfig.slonik></value>
<keyword>--slonycompare=</keyword><value><database.xml></value><keyword> ...</keyword> generate table SELECT statements for database health comparison between replicas
<keyword>--slonydiffold=</keyword><value><olddatabase.xml></value><keyword> ...</keyword> compare table slonyId assignment between two versions of a database definition
<keyword>--slonydiffnew=</keyword><value><newdatabase.xml></value><keyword> ...</keyword>
<keyword>--slonyidin=</keyword><value><database.xml></value> read this file's definition
<keyword>--slonyidout=</keyword><value><compositeoutput.xml></value> output it here with slonyids specified, based on requireslonyid and requireslonysetid
<keyword>--slonyidstartvalue=</keyword><value>N</value> start slony IDs at this number
<keyword>--slonyidsetvalue=</keyword><value>N</value> use this slony set ID for any unspecified slonySetId attributes

<header>Format-specific options</header>
<keyword>--useautoincrementoptions</keyword> mysql5: Apply AUTO_INCREMENT tableOptions. By default these are ignored.
<keyword>--useschemaprefix</keyword> mysql5: Instead of merging schemas together (mysql5 default behavior),
prefix each database object with the schema name.

0 comments on commit e9b73a7

Please sign in to comment.