Open maxandersen opened 4 days ago
One drawback of using command line arguments is that the password will be visible to anyone, at least on Unix-like systems where you can do ps -ef or similar. Another possibility would be to provide the connection info in a file, and then specify the filename on the command line; the app could delete the file once it's finished reading it. Or the info could be sent to standard input, on systems that support that.
The mechanics of opening the connection look straightforward. Create an instance of JDBCDatabase.LoginDialog.ConnectThread with the given driver class name, JDBC URL, username, and password, and then run it. It will require some surgery to do that without having an actual LoginDialog, and to make sure it runs after everything else has been initialized, but that's not rocket science.
sure - can add additional security efforts; or if password not specified prompt user for that piece.
my main usecase is to connect to local running dev databases anyway so less concerned about password being exposed this way.
I'm starting out with command line options; once I'm satisfied that's working well, I'll add the option to read connection configs from a file as well.
What I'm working on now are options like this: -driver=X, -url=X, -user=X, -pass=X, and -name=X. Only -driver and -url are required. If -user and/or -pass are omitted, they are set to "" (empty string); if -name is omitted, it is set to "cmdline.<n>". The name is what's shown as the window title for the connection.
It is possible to specify multiple connections, by adding ".<n>" to the options: -driver.2=Y, -url.2=Y, etc. If there is no number, it is assumed to be 1.
I've written most of the code, but it still needs some work, mostly better error reporting and testing. If you like, I'll upload a test version once the code is in a satisfactory state.
@thomasokken happy to look at PR and build/test from there
You can just check out master and build that. It supports the command-line options as I described before, and survived a few basic tests. I'll add error reporting, and support for config files, over the weekend.
checked it out but had to change 1.7 to 1.8 in build.xml.
I got it working, but a few comments:
1) should it not be --driver=...
instead of -driver=...
double dash instead of single?
2) it seems driver is required, normally jdbc figures out driver name from classpath when jdbc URL is available. could it be optional ?
3) username/password seems to be required too but should be optional as can be specified in some jdbc URLs thus should be optional
4) nothing is printed when things are bad/missing. Would be nice to get hint if something missing/parse error
5) would be great with a --help option.
It would be great if could pass connection info via command line.
So I could do: jbang --deps driverdeps jdbcnavjarurl.jar -u dummy -p secret --url jdbc://...
Could also add driverdeps as a command line arguments.