[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Fab-user] Have you considered using the plac syntax for command lin
From: |
TamTam Research |
Subject: |
Re: [Fab-user] Have you considered using the plac syntax for command line arguments? |
Date: |
Mon, 25 Feb 2013 00:12:23 +0100 |
Hi Mathew and fab-user listI have to second, that plac is great option to provide fully featured command line interface, in fact, this became standard in my work.
Fab is another one.
Sharing the concept would be great to me.
(saying that, I am aware, I have limited knowledge of all related implications to fab)
With best regards
Jan
2013/2/24 Matthew Honnibal
<address@hidden>
I noticed this in the "fab usage and options" docs:
"Additionally, since this process involves string parsing, all values
will end up as Python strings, so plan accordingly. (We hope to
improve upon this in future versions of Fabric, provided an intuitive
syntax can be found.)"
When I started using fabric, one thing I noticed was that I missed the
interfaces I was getting from the plac library:
http://plac.googlecode.com/hg/doc/plac.html
An example from the docs:
address@hidden(
db=plac.Annotation("Connection string", type=SqlSoup),
header=plac.Annotation("Header", 'flag', 'H'),
sqlcmd=plac.Annotation("SQL command", 'option', 'c', str, metavar="SQL"),
delimiter=plac.Annotation("Column separator", 'option', 'd'),
scripts=plac.Annotation("SQL scripts"),
)
def main(db, header, sqlcmd, delimiter="|", *scripts):
"A script to run queries and SQL scripts on a database"
yield 'Working on %s' % db.bind.url
if sqlcmd:
result = db.bind.execute(sqlcmd)
if header: # print the header
print delimiter.join(result.keys())
for row in result: # print the rows
print delimiter.join(map(str, row))
for script in scripts:
db.bind.execute(open(script).read())
print 'executed %s' % script
if __name__ == '__main__':
plac.call(main)
If run with no or invalid arguments, it automatically generates the
help message:
usage: dbcli.py [-h] [-H] [-c SQL] [-d |] db [scripts [scripts ...]]
A script to run queries and SQL scripts on a database
positional arguments:
db Connection string
scripts SQL scripts
optional arguments:
-h, --help show this help message and exit
-H, --header Header
-c SQL, --sqlcmd SQL SQL command
-d |, --delimiter | Column separator
Now, there's any number of reasons why this might not be the right
approach for fabric, or why other people might think it's actually
awful. But I find it very nice, so I just wanted to check you were
aware of it as a potential solution.
_______________________________________________
Fab-user mailing list
address@hidden
https://lists.nongnu.org/mailman/listinfo/fab-user