Skip to content

Commit 0989c12

Browse files
committed
add better help'
1 parent 480d706 commit 0989c12

File tree

2 files changed

+50
-17
lines changed

2 files changed

+50
-17
lines changed

src/clientcommands.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,6 @@ void ClientCommands::info( bool isJsonFormat )
118118
throw QString( "no mergin project in the current directory" );
119119

120120
QTextStream out( stdout );
121-
122-
123121
if ( isJsonFormat )
124122
{
125123
QJsonObject jsonData

src/clientmain.cpp

Lines changed: 50 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <QCommandLineParser>
1212
#include <QProcessEnvironment>
1313
#include <QDir>
14+
#include <QTextStream>
1415

1516
#include "clientcommands.h"
1617
#include "coreutils.h"
@@ -25,7 +26,7 @@ struct Args
2526
QString projectNamespace;
2627
QString projectName;
2728
QString dataDir;
28-
QString logFile;
29+
bool isVerbose;
2930
bool isJsonFormat;
3031
int timeout = 10000;
3132
};
@@ -50,45 +51,78 @@ QString parseEnvArg( const QString &value, const QString &envKey, bool required
5051
return ret;
5152
}
5253

54+
QString appDescription()
55+
{
56+
QString ret =
57+
"Mergin Command Line Client\n"\
58+
"\n"\
59+
"Auth\n"\
60+
"----\n"\
61+
" - use URL, username, password from command line args - e.g. --url https://dev.mergin.io/ --user martin --password XYZ\n"\
62+
" - for any bits (URL / username / password) not specified as command line args, you may use env variables: MERGIN_URL, MERGIN_USER, MERGIN_PASSWORD\n"\
63+
" - if URL is omitted, we would use public.cloudmergin.com\n"\
64+
"\n"\
65+
"Commands\n"\
66+
"--------\n"\
67+
" 1. manage remote projects (create / remote)\n"\
68+
" mergin create martin/test-project\n"\
69+
" mergin remove martin/test-project\n"\
70+
"\n"\
71+
" 2. initial download\n"\
72+
" mergin download martin/test-project\n"\
73+
" - project is downloaded to current dir + 'test-project' subdir - like git does\n"\
74+
" 3. operations within the current working directory (error if .mergin subdir is missing in the current dir)\n"\
75+
" mergin sync\n"\
76+
" - both pulls remote changes and pushes local changes to server\n"\
77+
" mergin info [--json]\n"\
78+
" - shows project information";
79+
return ret;
80+
}
81+
5382
Args parseArgs()
5483
{
5584
Args args;
5685
QCommandLineParser parser;
57-
parser.setApplicationDescription( "Mergin Command Line Client" );
86+
parser.setApplicationDescription( appDescription() );
5887
QCommandLineOption helpOption = parser.addHelpOption();
5988
QCommandLineOption versionOption = parser.addVersionOption();
60-
QCommandLineOption logOption( "log", "log file (debug output)", "log" );
61-
parser.addOption( logOption );
62-
QCommandLineOption jsonOption( "json", "output as JSON format (e.g. in info format)", "json" );
89+
QCommandLineOption verboseOption( "verbose", "Verbose mode. Prints out more information." );
90+
parser.addOption( verboseOption );
91+
QCommandLineOption jsonOption( "json", "Output 'info' command output in JSON format" );
6392
parser.addOption( jsonOption );
64-
65-
parser.addPositionalArgument( "command", "create/remove/download/sync/info" );
66-
parser.addPositionalArgument( "project", "namespace/projectname [only for create/remove/download]" );
67-
6893
QCommandLineOption urlOption( "url", "or use env. var MERGIN_URL. defaults to https://public.cloudmergin.com/", "url" );
6994
parser.addOption( urlOption );
7095
QCommandLineOption userOption( "user", "or use env. var MERGIN_USER", "user" );
7196
parser.addOption( userOption );
7297
QCommandLineOption passwordOption( "password", "or use env. var MERGIN_PASSWORD", "password" );
7398
parser.addOption( passwordOption );
7499

100+
parser.addPositionalArgument( "command", "create/remove/download/sync/info" );
101+
parser.addPositionalArgument( "project", "namespace/projectname [only for create/remove/download]" );
102+
75103
parser.parse( QCoreApplication::arguments() );
76104

77105
const QStringList posArgs = parser.positionalArguments();
78106
if ( parser.isSet( helpOption ) || posArgs.isEmpty() )
79-
parser.showHelp(); // exits the ap
107+
parser.showHelp(); // exits the app
80108

81109
if ( parser.isSet( versionOption ) )
82110
parser.showVersion(); // exits the app
83111

84112
args.url = parseEnvArg( parser.value( urlOption ), "MERGIN_URL", false ); // MerginApi has public.cloudmergin.com as default
85113
args.user = parseEnvArg( parser.value( userOption ), "MERGIN_USER" );
86114
args.pass = parseEnvArg( parser.value( passwordOption ), "MERGIN_PASSWORD" );
87-
args.logFile = parser.value( logOption );
115+
args.isVerbose = parser.isSet( verboseOption );
88116
args.isJsonFormat = parser.isSet( jsonOption );
89117

90-
if ( !args.logFile.isEmpty() )
91-
CoreUtils::setLogFilename( args.logFile );
118+
if ( args.isVerbose )
119+
{
120+
CoreUtils::setLogFilename( CoreUtils::LOG_TO_STDOUT );
121+
}
122+
else
123+
{
124+
CoreUtils::setLogFilename( CoreUtils::LOG_TO_DEVNULL );
125+
}
92126

93127
args.command = posArgs.at( 0 );
94128
if ( args.command == "create" ||
@@ -102,7 +136,7 @@ Args parseArgs()
102136
}
103137

104138
if ( !MerginApi::extractProjectName( posArgs.at( 1 ), args.projectNamespace, args.projectName ) )
105-
throw QString( "Invalid project, must have format namaspace/projectname: " ) + posArgs.at( 1 );
139+
throw QString( "Invalid project, must have format namaspace/project: " ) + posArgs.at( 1 );
106140

107141
args.dataDir = QDir::currentPath();
108142

@@ -172,7 +206,8 @@ int main( int argc, char *argv[] )
172206
}
173207
catch ( const QString &s )
174208
{
175-
CoreUtils::log( "merginclient", s );
209+
QTextStream out( stderr );
210+
out << "Error: " << s;
176211
return EXIT_FAILURE;
177212
}
178213

0 commit comments

Comments
 (0)