mirror of
https://github.com/nextcloud/desktop.git
synced 2025-10-26 11:17:43 +00:00
Options parsing added.
This commit is contained in:
parent
68ba99b7f0
commit
e63fc184a5
@ -17,6 +17,7 @@
|
||||
#include <qcoreapplication.h>
|
||||
#include <QStringList>
|
||||
#include <QUrl>
|
||||
#include <QFile>
|
||||
#include <qdebug.h>
|
||||
|
||||
#include "csyncthread.h"
|
||||
@ -34,12 +35,6 @@ int getauth(const char* prompt, char* buf, size_t len, int echo, int verify, voi
|
||||
return 0;
|
||||
}
|
||||
|
||||
void help() {
|
||||
std::cout << "Usage: owncloudcmd [OPTION...] LOCAL REMOTE\n";
|
||||
// " --dry-run This runs only update detection and reconcilation.\n"
|
||||
// " --proxy=<host:port> Use an http proxy (ownCloud module only)\n"
|
||||
}
|
||||
|
||||
struct ProxyInfo {
|
||||
const char *proxyType;
|
||||
const char *proxyHost;
|
||||
@ -56,40 +51,70 @@ struct ProxyInfo {
|
||||
}
|
||||
};
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
QCoreApplication app(argc, argv);
|
||||
struct CmdOptions {
|
||||
QString source_dir;
|
||||
QString target_url;
|
||||
QString config_directory;
|
||||
};
|
||||
|
||||
void help()
|
||||
{
|
||||
std::cout << "owncloudcmd - command line ownCloud client tool." << std::endl;
|
||||
std::cout << "" << std::endl;
|
||||
std::cout << "Call owncloudcmd sourcedir owncloudurl" << std::endl;
|
||||
std::cout << "" << std::endl;
|
||||
std::cout << "Options:" << std::endl;
|
||||
std::cout << " --confdir = configdir: Read config from there." << std::endl;
|
||||
std::cout << "" << std::endl;
|
||||
exit(1);
|
||||
|
||||
const char *source_dir = 0;
|
||||
const char *target_url = 0;
|
||||
const char *config_directory = 0;
|
||||
}
|
||||
|
||||
ProxyInfo proxyInfo;
|
||||
void parseOptions( const QStringList& app_args, CmdOptions *options )
|
||||
{
|
||||
QStringList args(app_args);
|
||||
|
||||
for (int i = 1; i < argc; ++i) {
|
||||
if (argv[i][0] == '-') {
|
||||
//TODO: parse arguments
|
||||
std::cerr << "Argument not impemented " << argv[i] << std::endl;
|
||||
} else if (!source_dir) {
|
||||
source_dir = argv[i];
|
||||
} else if (!target_url) {
|
||||
target_url = argv[i];
|
||||
} else if (!config_directory) {
|
||||
config_directory = argv[i];
|
||||
if( args.count() < 3 ) {
|
||||
help();
|
||||
}
|
||||
|
||||
options->target_url = args.takeLast();
|
||||
options->source_dir = args.takeLast();
|
||||
if( !QFile::exists( options->source_dir )) {
|
||||
std::cerr << "Source dir does not exists.";
|
||||
exit(1);
|
||||
}
|
||||
|
||||
QStringListIterator it(args);
|
||||
// skip file name;
|
||||
if (it.hasNext()) it.next();
|
||||
|
||||
while(it.hasNext()) {
|
||||
const QString option = it.next();
|
||||
|
||||
if( option == "--confdir" && !it.peekNext().startsWith("-") ) {
|
||||
options->config_directory = it.next();
|
||||
} else {
|
||||
std::cerr << "Too many arguments" << std::endl;
|
||||
return 1;
|
||||
help();
|
||||
}
|
||||
}
|
||||
|
||||
if (!source_dir || !target_url) {
|
||||
std::cerr << "Too few arguments" << std::endl;
|
||||
return 1;
|
||||
if( options->target_url.isEmpty() || options->source_dir.isEmpty() ) {
|
||||
help();
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
QCoreApplication app(argc, argv);
|
||||
|
||||
ProxyInfo proxyInfo;
|
||||
CmdOptions options;
|
||||
|
||||
parseOptions( app.arguments(), &options );
|
||||
|
||||
CSYNC *_csync_ctx;
|
||||
if( csync_create( &_csync_ctx, source_dir, target_url) < 0 ) {
|
||||
if( csync_create( &_csync_ctx, options.source_dir.toUtf8(),
|
||||
options.target_url.toUtf8()) < 0 ) {
|
||||
qFatal("Unable to create csync-context!");
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
@ -97,7 +122,6 @@ int main(int argc, char **argv) {
|
||||
csync_set_log_level(11);
|
||||
csync_enable_conflictcopys(_csync_ctx);
|
||||
|
||||
|
||||
csync_set_auth_callback( _csync_ctx, getauth );
|
||||
|
||||
if( csync_init( _csync_ctx ) < 0 ) {
|
||||
@ -108,10 +132,8 @@ int main(int argc, char **argv) {
|
||||
|
||||
csync_set_module_property(_csync_ctx, "csync_context", _csync_ctx);
|
||||
|
||||
|
||||
QString sourceDir = QString::fromLocal8Bit(source_dir);
|
||||
SyncJournalDb db(sourceDir);
|
||||
CSyncThread csyncthread(_csync_ctx, sourceDir, QUrl(target_url).path(), &db);
|
||||
SyncJournalDb db(options.source_dir);
|
||||
CSyncThread csyncthread(_csync_ctx, options.source_dir, QUrl(options.target_url).path(), &db);
|
||||
QObject::connect(&csyncthread, SIGNAL(finished()), &app, SLOT(quit()));
|
||||
csyncthread.startSync();
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user