2
0
mirror of https://github.com/meganz/MEGAcmd synced 2025-09-02 06:45:09 +00:00

Use runtime flags instead of preprocessor for the help command

Add the argument `--show-all-options` that shows all help output
regardless of platform. This command is used by the python script so all
help options are present in the doc files
This commit is contained in:
Diego Ximenez
2024-06-14 11:46:28 +02:00
parent 3f6c36ef6c
commit 00cdc516f5
13 changed files with 352 additions and 189 deletions

View File

@@ -34,7 +34,7 @@ done
In addition to running commands on request, MEGAcmd can also be configured to [synchronise](#synchronisation-configurations) folders between your local device and your MEGA account, or perform regular [backups](#backup-configurations) from your device to your MEGA account. In addition to running commands on request, MEGAcmd can also be configured to [synchronise](#synchronisation-configurations) folders between your local device and your MEGA account, or perform regular [backups](#backup-configurations) from your device to your MEGA account.
In order to enable synchronisation and backup features, and for efficiency running commands, MEGAcmd runs a server process in the background which the MEGAcmd shell or the script commands forward requests to. The server keeps running in the background until it is told to close with the [`quit`](#quit) command. If you want it to keep running when you quit the interactive shell (to keep sync and backup runnign for example), use `quit --only-shell`. In order to enable synchronisation and backup features, and for efficiency running commands, MEGAcmd runs a server process in the background which the MEGAcmd shell or the script commands forward requests to. The server keeps running in the background until it is told to close with the [`quit`](#quit) command. If you want it to keep running when you quit the interactive shell (to keep sync and backup running for example), use `quit --only-shell`.
Working with your MEGA account requires signing in with your email and password using the [`login`](#login) command, though you can download public links or upload to public folders without logging in. Logging in with your username and password starts a [Session](#session), and causes some of your account such as the folder structure to be downloaded to your [Local Cache](#local-cache). Working with your MEGA account requires signing in with your email and password using the [`login`](#login) command, though you can download public links or upload to public folders without logging in. Logging in with your username and password starts a [Session](#session), and causes some of your account such as the folder structure to be downloaded to your [Local Cache](#local-cache).
@@ -226,9 +226,11 @@ Verbosity: You can increase the amount of information given by any command by pa
* [`webdav`](docs/commands/webdav.md)`[-d (--all | remotepath ) ] [ remotepath [--port=PORT] [--public] [--tls --certificate=/path/to/certificate.pem --key=/path/to/certificate.key]] [--use-pcre]` Configures a WEBDAV server to serve a location in MEGA * [`webdav`](docs/commands/webdav.md)`[-d (--all | remotepath ) ] [ remotepath [--port=PORT] [--public] [--tls --certificate=/path/to/certificate.pem --key=/path/to/certificate.key]] [--use-pcre]` Configures a WEBDAV server to serve a location in MEGA
### Misc. ### Misc.
* [`autocomplete`](docs/commands/autocomplete.md)`[dos | unix]` Modifes how tab completion operates.
* [`cancel`](docs/commands/cancel.md) Cancels your MEGA account * [`cancel`](docs/commands/cancel.md) Cancels your MEGA account
* [`cat`](docs/commands/cat.md)`remotepath1 remotepath2 ...` Prints the contents of remote files * [`cat`](docs/commands/cat.md)`remotepath1 remotepath2 ...` Prints the contents of remote files
* [`clear`](docs/commands/clear.md) Clear screen * [`clear`](docs/commands/clear.md) Clear screen
* [`codepage`](docs/commands/codepage.md)`[N [M]]` Switches the codepage used to decide which characters show on-screen.
* [`confirmcancel`](docs/commands/confirmcancel.md)`link password` Confirms the cancellation of your MEGA account * [`confirmcancel`](docs/commands/confirmcancel.md)`link password` Confirms the cancellation of your MEGA account
* [`debug`](docs/commands/debug.md) Enters debugging mode (HIGHLY VERBOSE) * [`debug`](docs/commands/debug.md) Enters debugging mode (HIGHLY VERBOSE)
* [`deleteversions`](docs/commands/deleteversions.md)`[-f] (--all | remotepath1 remotepath2 ...) [--use-pcre]` Deletes previous versions. * [`deleteversions`](docs/commands/deleteversions.md)`[-f] (--all | remotepath1 remotepath2 ...) [--use-pcre]` Deletes previous versions.
@@ -237,7 +239,7 @@ Verbosity: You can increase the amount of information given by any command by pa
* [`exit`](docs/commands/exit.md)`[--only-shell]` Quits MEGAcmd * [`exit`](docs/commands/exit.md)`[--only-shell]` Quits MEGAcmd
* [`ftp`](docs/commands/ftp.md)`[-d ( --all | remotepath ) ] [ remotepath [--port=PORT] [--data-ports=BEGIN-END] [--public] [--tls --certificate=/path/to/certificate.pem --key=/path/to/certificate.key]] [--use-pcre]` Configures a FTP server to serve a location in MEGA * [`ftp`](docs/commands/ftp.md)`[-d ( --all | remotepath ) ] [ remotepath [--port=PORT] [--data-ports=BEGIN-END] [--public] [--tls --certificate=/path/to/certificate.pem --key=/path/to/certificate.key]] [--use-pcre]` Configures a FTP server to serve a location in MEGA
* [`graphics`](docs/commands/graphics.md)`[on|off]` Shows if special features related to images and videos are enabled. * [`graphics`](docs/commands/graphics.md)`[on|off]` Shows if special features related to images and videos are enabled.
* [`help`](docs/commands/help.md)`[-f|-ff|--non-interactive|--upgrade|--paths]` Prints list of commands * [`help`](docs/commands/help.md)`[-f|-ff|--non-interactive|--upgrade|--paths] [--show-all-options]` Prints list of commands
* [`https`](docs/commands/https.md)`[on|off]` Shows if HTTPS is used for transfers. Use "https on" to enable it. * [`https`](docs/commands/https.md)`[on|off]` Shows if HTTPS is used for transfers. Use "https on" to enable it.
* [`info`](docs/commands/info.md)`remotepath1 remotepath2 ...` Prints media info of remote files * [`info`](docs/commands/info.md)`remotepath1 remotepath2 ...` Prints media info of remote files
* [`log`](docs/commands/log.md)`[-sc] level` Prints/Modifies the current logs level * [`log`](docs/commands/log.md)`[-sc] level` Prints/Modifies the current logs level
@@ -247,6 +249,8 @@ Verbosity: You can increase the amount of information given by any command by pa
* [`quit`](docs/commands/quit.md)`[--only-shell]` Quits MEGAcmd * [`quit`](docs/commands/quit.md)`[--only-shell]` Quits MEGAcmd
* [`reload`](docs/commands/reload.md) Forces a reload of the remote files of the user * [`reload`](docs/commands/reload.md) Forces a reload of the remote files of the user
* [`tree`](docs/commands/tree.md)`[remotepath]` Lists files in a remote path in a nested tree decorated output * [`tree`](docs/commands/tree.md)`[remotepath]` Lists files in a remote path in a nested tree decorated output
* [`unicode`](docs/commands/unicode.md) Toggle unicode input enabled/disabled in interactive shell
* [`update`](docs/commands/update.md)`[--auto=on|off|query]` Updates MEGAcmd
* [`version`](docs/commands/version.md)`[-l][-c]` Prints MEGAcmd versioning and extra info * [`version`](docs/commands/version.md)`[-l][-c]` Prints MEGAcmd versioning and extra info
## Examples ## Examples

View File

@@ -0,0 +1,13 @@
### autocomplete
Modifes how tab completion operates.
Usage: `autocomplete [dos | unix]`
<pre>
The default is to operate like the native platform. However
you can switch it between mode 'dos' and 'unix' as you prefer.
Options:
dos Each press of tab places the next option into the command line
unix Options are listed in a table, or put in-line if there is only one
Note: this command is only available on some versions of Windows
</pre>

View File

@@ -2,3 +2,7 @@
Prints the contents of remote files Prints the contents of remote files
Usage: `cat remotepath1 remotepath2 ...` Usage: `cat remotepath1 remotepath2 ...`
<pre>
To avoid issues with encoding on Windows, if you want to cat the exact binary contents of a remote file into a local one,
use non-interactive mode with -o /path/to/file. See help "non-interactive"
</pre>

15
docs/commands/codepage.md Normal file
View File

@@ -0,0 +1,15 @@
### codepage
Switches the codepage used to decide which characters show on-screen.
Usage: `codepage [N [M]]`
<pre>
MEGAcmd supports unicode or specific code pages. For european countries you may need
to select a suitable codepage or secondary codepage for the character set you use.
Of course a font containing the glyphs you need must have been selected for the terminal first.
Options:
(no option) Outputs the selected code page and secondary codepage (if configured).
N Sets the main codepage to N. 65001 is Unicode.
M Sets the secondary codepage to M, which is used if the primary can't translate a character.
Note: this command is only available on some versions of Windows
</pre>

View File

@@ -20,5 +20,5 @@ Options:
*If you serve more than one location, these parameters will be ignored and used those of the first location served. *If you serve more than one location, these parameters will be ignored and used those of the first location served.
If you want to change those parameters, you need to stop serving all locations and configure them again. If you want to change those parameters, you need to stop serving all locations and configure them again.
Caveat: This functionality is in BETA state. If you experience any issue with this, please contact: support@mega.nz Caveat: This functionality is in BETA state. It might not be available on all platforms. If you experience any issue with this, please contact: support@mega.nz
</pre> </pre>

View File

@@ -1,7 +1,7 @@
### help ### help
Prints list of commands Prints list of commands
Usage: `help [-f|-ff|--non-interactive|--upgrade|--paths]` Usage: `help [-f|-ff|--non-interactive|--upgrade|--paths] [--show-all-options]`
<pre> <pre>
Options: Options:
-f Include a brief description of the commands -f Include a brief description of the commands
@@ -9,4 +9,5 @@ Options:
--non-interactive Display information on how to use MEGAcmd with scripts --non-interactive Display information on how to use MEGAcmd with scripts
--upgrade Display information on PRO plans --upgrade Display information on PRO plans
--paths Show caveats of local and remote paths --paths Show caveats of local and remote paths
--show-all-options Display all options regardless of platform
</pre> </pre>

View File

@@ -14,5 +14,5 @@ Options:
Notice that permissions of already existing files/folders will not change. Notice that permissions of already existing files/folders will not change.
Notice that permissions of already existing files/folders will not change. Notice that permissions of already existing files/folders will not change.
Notice: this permissions will be saved for the next time you execute MEGAcmd server. They will be removed if you logout. Note: permissions will be saved for the next time you execute MEGAcmd server. They will be removed if you logout. Permissions are not available on Windows.
</pre> </pre>

12
docs/commands/unicode.md Normal file
View File

@@ -0,0 +1,12 @@
### unicode
Toggle unicode input enabled/disabled in interactive shell
Usage: `unicode`
<pre>
Unicode mode is experimental, you might experience
some issues interacting with the console
(e.g. history navigation fails).
Type "help --unicode" for further info
Note: this command is only available on some versions of Windows
</pre>

16
docs/commands/update.md Normal file
View File

@@ -0,0 +1,16 @@
### update
Updates MEGAcmd
Usage: `update [--auto=on|off|query]`
<pre>
Looks for updates and applies if available.
This command can also be used to enable/disable automatic updates.
Options:
--auto=ON|OFF|query Enables/disables/queries status of auto updates.
If auto updates are enabled it will be checked while MEGAcmd server is running.
If there is an update available, it will be downloaded and applied.
This will cause MEGAcmd to be restarted whenever the updates are applied.
Further info at https://github.com/meganz/megacmd#megacmd-updatesNote: this command is not available on Linux
</pre>

View File

@@ -19,5 +19,5 @@ Options:
*If you serve more than one location, these parameters will be ignored and use those of the first location served. *If you serve more than one location, these parameters will be ignored and use those of the first location served.
If you want to change those parameters, you need to stop serving all locations and configure them again. If you want to change those parameters, you need to stop serving all locations and configure them again.
Caveat: This functionality is in BETA state. If you experience any issue with this, please contact: support@mega.nz Caveat: This functionality is in BETA state. It might not be available on all platforms. If you experience any issue with this, please contact: support@mega.nz
</pre> </pre>

View File

@@ -5,7 +5,7 @@ import subprocess
def get_help_output(detail): def get_help_output(detail):
det = '-ff' if detail else '-f' det = '-ff' if detail else '-f'
return subprocess.run(['mega-exec', 'help', det], capture_output=True, text=True).stdout return subprocess.run(['mega-exec', 'help', det, '--show-all-options'], capture_output=True, text=True).stdout
class CommandSummary: class CommandSummary:
def __init__(self, name, args, description): def __init__(self, name, args, description):

View File

@@ -481,6 +481,7 @@ void insertValidParamsPerCommand(set<string> *validParams, string thecommand, se
validParams->insert("non-interactive"); validParams->insert("non-interactive");
validParams->insert("upgrade"); validParams->insert("upgrade");
validParams->insert("paths"); validParams->insert("paths");
validParams->insert("show-all-options");
#ifdef _WIN32 #ifdef _WIN32
validParams->insert("unicode"); validParams->insert("unicode");
#endif #endif
@@ -1491,7 +1492,7 @@ void freeApiFolder(MegaApi *apiFolder)
mutexapiFolders.unlock(); mutexapiFolders.unlock();
} }
const char * getUsageStr(const char *command) const char * getUsageStr(const char *command, const HelpFlags& flags)
{ {
if (!strcmp(command, "login")) if (!strcmp(command, "login"))
{ {
@@ -1569,19 +1570,20 @@ const char * getUsageStr(const char *command)
{ {
return "mount"; return "mount";
} }
#if defined(_WIN32) && !defined(NO_READLINE) if (((flags.win && !flags.readline) || flags.showAll) && !strcmp(command, "unicode"))
if (!strcmp(command, "unicode"))
{ {
return "unicode"; return "unicode";
} }
#endif
if (!strcmp(command, "ls")) if (!strcmp(command, "ls"))
{ {
return "ls [-halRr] [--show-handles] [--tree] [--versions] [remotepath]" if (flags.usePcre || flags.showAll)
#ifdef USE_PCRE {
" [--use-pcre]" return "ls [-halRr] [--show-handles] [--tree] [--versions] [remotepath] [--use-pcre] [--show-creation-time] [--time-format=FORMAT]";
#endif }
" [--show-creation-time] [--time-format=FORMAT]"; else
{
return "ls [-halRr] [--show-handles] [--tree] [--versions] [remotepath] [--show-creation-time] [--time-format=FORMAT]";
}
} }
if (!strcmp(command, "tree")) if (!strcmp(command, "tree"))
{ {
@@ -1597,11 +1599,14 @@ const char * getUsageStr(const char *command)
} }
if (!strcmp(command, "du")) if (!strcmp(command, "du"))
{ {
#ifdef USE_PCRE if (flags.usePcre || flags.showAll)
{
return "du [-h] [--versions] [remotepath remotepath2 remotepath3 ... ] [--use-pcre]"; return "du [-h] [--versions] [remotepath remotepath2 remotepath3 ... ] [--use-pcre]";
#else }
else
{
return "du [-h] [--versions] [remotepath remotepath2 remotepath3 ... ]"; return "du [-h] [--versions] [remotepath remotepath2 remotepath3 ... ]";
#endif }
} }
if (!strcmp(command, "pwd")) if (!strcmp(command, "pwd"))
{ {
@@ -1629,11 +1634,14 @@ const char * getUsageStr(const char *command)
} }
if (!strcmp(command, "get")) if (!strcmp(command, "get"))
{ {
#ifdef USE_PCRE if (flags.usePcre || flags.showAll)
{
return "get [-m] [-q] [--ignore-quota-warn] [--use-pcre] [--password=PASSWORD] exportedlink|remotepath [localpath]"; return "get [-m] [-q] [--ignore-quota-warn] [--use-pcre] [--password=PASSWORD] exportedlink|remotepath [localpath]";
#else }
else
{
return "get [-m] [-q] [--ignore-quota-warn] [--password=PASSWORD] exportedlink|remotepath [localpath]"; return "get [-m] [-q] [--ignore-quota-warn] [--password=PASSWORD] exportedlink|remotepath [localpath]";
#endif }
} }
if (!strcmp(command, "getq")) if (!strcmp(command, "getq"))
{ {
@@ -1657,59 +1665,74 @@ const char * getUsageStr(const char *command)
} }
if (!strcmp(command, "rm")) if (!strcmp(command, "rm"))
{ {
#ifdef USE_PCRE if (flags.usePcre || flags.showAll)
{
return "rm [-r] [-f] [--use-pcre] remotepath"; return "rm [-r] [-f] [--use-pcre] remotepath";
#else }
else
{
return "rm [-r] [-f] remotepath"; return "rm [-r] [-f] remotepath";
#endif }
} }
if (!strcmp(command, "mv")) if (!strcmp(command, "mv"))
{ {
#ifdef USE_PCRE if (flags.usePcre || flags.showAll)
{
return "mv srcremotepath [--use-pcre] [srcremotepath2 srcremotepath3 ..] dstremotepath"; return "mv srcremotepath [--use-pcre] [srcremotepath2 srcremotepath3 ..] dstremotepath";
#else }
else
{
return "mv srcremotepath [srcremotepath2 srcremotepath3 ..] dstremotepath"; return "mv srcremotepath [srcremotepath2 srcremotepath3 ..] dstremotepath";
#endif }
} }
if (!strcmp(command, "cp")) if (!strcmp(command, "cp"))
{ {
#ifdef USE_PCRE if (flags.usePcre || flags.showAll)
{
return "cp [--use-pcre] srcremotepath [srcremotepath2 srcremotepath3 ..] dstremotepath|dstemail:"; return "cp [--use-pcre] srcremotepath [srcremotepath2 srcremotepath3 ..] dstremotepath|dstemail:";
#else }
else
{
return "cp srcremotepath [srcremotepath2 srcremotepath3 ..] dstremotepath|dstemail:"; return "cp srcremotepath [srcremotepath2 srcremotepath3 ..] dstremotepath|dstemail:";
#endif }
} }
if (!strcmp(command, "deleteversions")) if (!strcmp(command, "deleteversions"))
{ {
#ifdef USE_PCRE if (flags.usePcre || flags.showAll)
{
return "deleteversions [-f] (--all | remotepath1 remotepath2 ...) [--use-pcre]"; return "deleteversions [-f] (--all | remotepath1 remotepath2 ...) [--use-pcre]";
#else }
else
{
return "deleteversions [-f] (--all | remotepath1 remotepath2 ...)"; return "deleteversions [-f] (--all | remotepath1 remotepath2 ...)";
#endif }
} }
if (!strcmp(command, "exclude")) if (!strcmp(command, "exclude"))
{ {
return "exclude [(-a|-d) pattern1 pattern2 pattern3]"; return "exclude [(-a|-d) pattern1 pattern2 pattern3]";
} }
#ifdef HAVE_LIBUV if ((flags.haveLibuv || flags.showAll) && !strcmp(command, "webdav"))
if (!strcmp(command, "webdav")) {
if (flags.usePcre || flags.showAll)
{ {
#ifdef USE_PCRE
return "webdav [-d (--all | remotepath ) ] [ remotepath [--port=PORT] [--public] [--tls --certificate=/path/to/certificate.pem --key=/path/to/certificate.key]] [--use-pcre]"; return "webdav [-d (--all | remotepath ) ] [ remotepath [--port=PORT] [--public] [--tls --certificate=/path/to/certificate.pem --key=/path/to/certificate.key]] [--use-pcre]";
#else
return "webdav [-d (--all | remotepath ) ] [ remotepath [--port=PORT] [--public] [--tls --certificate=/path/to/certificate.pem --key=/path/to/certificate.key]]";
#endif
} }
if (!strcmp(command, "ftp")) else
{ {
#ifdef USE_PCRE return "webdav [-d (--all | remotepath ) ] [ remotepath [--port=PORT] [--public] [--tls --certificate=/path/to/certificate.pem --key=/path/to/certificate.key]]";
return "ftp [-d ( --all | remotepath ) ] [ remotepath [--port=PORT] [--data-ports=BEGIN-END] [--public] [--tls --certificate=/path/to/certificate.pem --key=/path/to/certificate.key]] [--use-pcre]"; }
#else }
return "ftp [-d ( --all | remotepath ) ] [ remotepath [--port=PORT] [--data-ports=BEGIN-END] [--public] [--tls --certificate=/path/to/certificate.pem --key=/path/to/certificate.key]]"; if ((flags.haveLibuv || flags.showAll) && !strcmp(command, "ftp"))
#endif {
if (flags.usePcre || flags.showAll)
{
return "ftp [-d ( --all | remotepath ) ] [ remotepath [--port=PORT] [--data-ports=BEGIN-END] [--public] [--tls --certificate=/path/to/certificate.pem --key=/path/to/certificate.key]] [--use-pcre]";
}
else
{
return "ftp [-d ( --all | remotepath ) ] [ remotepath [--port=PORT] [--data-ports=BEGIN-END] [--public] [--tls --certificate=/path/to/certificate.pem --key=/path/to/certificate.key]]";
}
} }
#endif
if (!strcmp(command, "sync")) if (!strcmp(command, "sync"))
{ {
return "sync [localpath dstremotepath| [-dsr] [ID|localpath]"; return "sync [localpath dstremotepath| [-dsr] [ID|localpath]";
@@ -1722,12 +1745,10 @@ const char * getUsageStr(const char *command)
{ {
return "https [on|off]"; return "https [on|off]";
} }
#ifndef _WIN32 if ((!flags.win || flags.showAll) && !strcmp(command, "permissions"))
if (!strcmp(command, "permissions"))
{ {
return "permissions [(--files|--folders) [-s XXX]]"; return "permissions [(--files|--folders) [-s XXX]]";
} }
#endif
if (!strcmp(command, "export")) if (!strcmp(command, "export"))
{ {
return "export [-d|-a" return "export [-d|-a"
@@ -1741,11 +1762,14 @@ const char * getUsageStr(const char *command)
} }
if (!strcmp(command, "share")) if (!strcmp(command, "share"))
{ {
#ifdef USE_PCRE if (flags.usePcre || flags.showAll)
{
return "share [-p] [-d|-a --with=user@email.com [--level=LEVEL]] [remotepath] [--use-pcre] [--time-format=FORMAT]"; return "share [-p] [-d|-a --with=user@email.com [--level=LEVEL]] [remotepath] [--use-pcre] [--time-format=FORMAT]";
#else }
else
{
return "share [-p] [-d|-a --with=user@email.com [--level=LEVEL]] [remotepath] [--time-format=FORMAT]"; return "share [-p] [-d|-a --with=user@email.com [--level=LEVEL]] [remotepath] [--time-format=FORMAT]";
#endif }
} }
if (!strcmp(command, "invite")) if (!strcmp(command, "invite"))
{ {
@@ -1892,15 +1916,18 @@ const char * getUsageStr(const char *command)
} }
if (!strcmp(command, "find")) if (!strcmp(command, "find"))
{ {
return "find [remotepath] [-l] [--pattern=PATTERN] [--type=d|f] [--mtime=TIMECONSTRAIN] [--size=SIZECONSTRAIN] " if (flags.usePcre || flags.showAll)
#ifdef USE_PCRE {
"[--use-pcre] " return "find [remotepath] [-l] [--pattern=PATTERN] [--type=d|f] [--mtime=TIMECONSTRAIN] [--size=SIZECONSTRAIN] [--use-pcre] [--time-format=FORMAT] [--show-handles|--print-only-handles]";
#endif }
"[--time-format=FORMAT] [--show-handles|--print-only-handles]"; else
{
return "find [remotepath] [-l] [--pattern=PATTERN] [--type=d|f] [--mtime=TIMECONSTRAIN] [--size=SIZECONSTRAIN] [--time-format=FORMAT] [--show-handles|--print-only-handles]";
}
} }
if (!strcmp(command, "help")) if (!strcmp(command, "help"))
{ {
return "help [-f|-ff|--non-interactive|--upgrade|--paths]"; return "help [-f|-ff|--non-interactive|--upgrade|--paths] [--show-all-options]";
} }
if (!strcmp(command, "clear")) if (!strcmp(command, "clear"))
{ {
@@ -1916,8 +1943,7 @@ const char * getUsageStr(const char *command)
return "downloads [--purge|--enable-clean-slate|--disable-clean-slate|--enable-tracking|--disable-tracking|query-enabled|report-all| [id_1 id_2 ... id_n]] [SHOWOPTIONS]"; return "downloads [--purge|--enable-clean-slate|--disable-clean-slate|--enable-tracking|--disable-tracking|query-enabled|report-all| [id_1 id_2 ... id_n]] [SHOWOPTIONS]";
} }
#endif #endif
#if defined(_WIN32) && defined(NO_READLINE) if (((flags.win && !flags.readline) || flags.showAll) && !strcmp(command, "autocomplete"))
if (!strcmp(command, "autocomplete"))
{ {
return "autocomplete [dos | unix]"; return "autocomplete [dos | unix]";
} }
@@ -1925,13 +1951,10 @@ const char * getUsageStr(const char *command)
{ {
return "codepage [N [M]]"; return "codepage [N [M]]";
} }
#endif if ((flags.win || flags.apple || flags.showAll) && !strcmp(command, "update"))
#if defined(_WIN32) || defined(__APPLE__)
if (!strcmp(command, "update"))
{ {
return "update [--auto=on|off|query]"; return "update [--auto=on|off|query]";
} }
#endif
return "command not found: "; return "command not found: ";
} }
@@ -1970,12 +1993,11 @@ void printColumnDisplayerHelp(ostringstream &os)
os << " --output-cols=COLUMN_NAME_1,COLUMN_NAME2,..." << "\t" << "You can select which columns to show (and their order) with this option" << endl; os << " --output-cols=COLUMN_NAME_1,COLUMN_NAME2,..." << "\t" << "You can select which columns to show (and their order) with this option" << endl;
} }
string getHelpStr(const char *command, const HelpFlags& flags = {})
string getHelpStr(const char *command)
{ {
ostringstream os; ostringstream os;
os << "Usage: " << getUsageStr(command) << endl; os << "Usage: " << getUsageStr(command, flags) << endl;
if (!strcmp(command, "login")) if (!strcmp(command, "login"))
{ {
os << "Logs into a MEGA account" << endl; os << "Logs into a MEGA account" << endl;
@@ -2067,6 +2089,7 @@ string getHelpStr(const char *command)
os << " --non-interactive" << " " << "Display information on how to use MEGAcmd with scripts" << endl; os << " --non-interactive" << " " << "Display information on how to use MEGAcmd with scripts" << endl;
os << " --upgrade" << " " << "Display information on PRO plans" << endl; os << " --upgrade" << " " << "Display information on PRO plans" << endl;
os << " --paths" << " " << "Show caveats of local and remote paths" << endl; os << " --paths" << " " << "Show caveats of local and remote paths" << endl;
os << " --show-all-options" << " " << "Display all options regardless of platform" << endl;
} }
else if (!strcmp(command, "history")) else if (!strcmp(command, "history"))
{ {
@@ -2090,17 +2113,17 @@ string getHelpStr(const char *command)
os << "This includes the root node in your cloud drive, Inbox, Rubbish Bin" << endl; os << "This includes the root node in your cloud drive, Inbox, Rubbish Bin" << endl;
os << "and all the in-shares (nodes shares to you from other users)" << endl; os << "and all the in-shares (nodes shares to you from other users)" << endl;
} }
#if defined(_WIN32) && !defined(NO_READLINE) else if (((flags.win && flags.readline) || flags.showAll) && !strcmp(command, "unicode"))
else if (!strcmp(command, "unicode"))
{ {
os << "Toggle unicode input enabled/disabled in interactive shell" << endl; os << "Toggle unicode input enabled/disabled in interactive shell" << endl;
os << endl; os << endl;
os << " Unicode mode is experimental, you might experience" << endl; os << " Unicode mode is experimental, you might experience" << endl;
os << " some issues interacting with the console" << endl; os << " some issues interacting with the console" << endl;
os << " (e.g. history navigation fails)." << endl; os << " (e.g. history navigation fails)." << endl;
os << endl;
os << "Type \"help --unicode\" for further info" << endl; os << "Type \"help --unicode\" for further info" << endl;
os << "Note: this command is only available on some versions of Windows" << endl;
} }
#endif
else if (!strcmp(command, "ls")) else if (!strcmp(command, "ls"))
{ {
os << "Lists files in a remote path" << endl; os << "Lists files in a remote path" << endl;
@@ -2132,9 +2155,10 @@ string getHelpStr(const char *command)
os << " --show-creation-time" << "\t" << "show creation time instead of modification time for files" << endl; os << " --show-creation-time" << "\t" << "show creation time instead of modification time for files" << endl;
printTimeFormatHelp(os); printTimeFormatHelp(os);
#ifdef USE_PCRE if (flags.usePcre || flags.showAll)
{
os << " --use-pcre" << "\t" << "use PCRE expressions" << endl; os << " --use-pcre" << "\t" << "use PCRE expressions" << endl;
#endif }
} }
else if (!strcmp(command, "tree")) else if (!strcmp(command, "tree"))
{ {
@@ -2142,8 +2166,7 @@ string getHelpStr(const char *command)
os << endl; os << endl;
os << "This is similar to \"ls --tree\"" << endl; os << "This is similar to \"ls --tree\"" << endl;
} }
#if defined(_WIN32) || defined(__APPLE__) else if ((flags.win || flags.apple || flags.showAll) && !strcmp(command, "update"))
else if (!strcmp(command, "update"))
{ {
os << "Updates MEGAcmd" << endl; os << "Updates MEGAcmd" << endl;
os << endl; os << endl;
@@ -2158,8 +2181,8 @@ string getHelpStr(const char *command)
os << " This will cause MEGAcmd to be restarted whenever the updates are applied." << endl; os << " This will cause MEGAcmd to be restarted whenever the updates are applied." << endl;
os << endl; os << endl;
os << "Further info at https://github.com/meganz/megacmd#megacmd-updates"; os << "Further info at https://github.com/meganz/megacmd#megacmd-updates";
os << "Note: this command is not available on Linux" << endl;
} }
#endif
else if (!strcmp(command, "cd")) else if (!strcmp(command, "cd"))
{ {
os << "Changes the current remote folder" << endl; os << "Changes the current remote folder" << endl;
@@ -2194,9 +2217,10 @@ string getHelpStr(const char *command)
os << " " << "\t" << "You can remove all versions with \"deleteversions\" and list them with \"ls --versions\"" << endl; os << " " << "\t" << "You can remove all versions with \"deleteversions\" and list them with \"ls --versions\"" << endl;
os << " --path-display-size=N" << "\t" << "Use a fixed size of N characters for paths" << endl; os << " --path-display-size=N" << "\t" << "Use a fixed size of N characters for paths" << endl;
#ifdef USE_PCRE if (flags.usePcre || flags.showAll)
{
os << " --use-pcre" << "\t" << "use PCRE expressions" << endl; os << " --use-pcre" << "\t" << "use PCRE expressions" << endl;
#endif }
} }
else if (!strcmp(command, "pwd")) else if (!strcmp(command, "pwd"))
{ {
@@ -2276,10 +2300,11 @@ string getHelpStr(const char *command)
os << " --ignore-quota-warn" << "\t" << "ignore quota surpassing warning." << endl; os << " --ignore-quota-warn" << "\t" << "ignore quota surpassing warning." << endl;
os << " " << "\t" << " The download will be attempted anyway." << endl; os << " " << "\t" << " The download will be attempted anyway." << endl;
os << " --password=PASSWORD" << "\t" << "Password to decrypt the password-protected link. Please, avoid using passwords containing \" or '" << endl; os << " --password=PASSWORD" << "\t" << "Password to decrypt the password-protected link. Please, avoid using passwords containing \" or '" << endl;
#ifdef USE_PCRE
os << " --use-pcre" << "\t" << "use PCRE expressions" << endl;
#endif
if (flags.usePcre || flags.showAll)
{
os << " --use-pcre" << "\t" << "use PCRE expressions" << endl;
}
} }
if (!strcmp(command, "attr")) if (!strcmp(command, "attr"))
{ {
@@ -2316,9 +2341,11 @@ string getHelpStr(const char *command)
os << "Options:" << endl; os << "Options:" << endl;
os << " -r" << "\t" << "Delete recursively (for folders)" << endl; os << " -r" << "\t" << "Delete recursively (for folders)" << endl;
os << " -f" << "\t" << "Force (no asking)" << endl; os << " -f" << "\t" << "Force (no asking)" << endl;
#ifdef USE_PCRE
if (flags.usePcre || flags.showAll)
{
os << " --use-pcre" << "\t" << "use PCRE expressions" << endl; os << " --use-pcre" << "\t" << "use PCRE expressions" << endl;
#endif }
} }
else if (!strcmp(command, "mv")) else if (!strcmp(command, "mv"))
{ {
@@ -2326,10 +2353,12 @@ string getHelpStr(const char *command)
os << endl; os << endl;
os << "If the location exists and is a folder, the source will be moved there" << endl; os << "If the location exists and is a folder, the source will be moved there" << endl;
os << "If the location doesn't exist, the source will be renamed to the destination name given" << endl; os << "If the location doesn't exist, the source will be renamed to the destination name given" << endl;
#ifdef USE_PCRE
if (flags.usePcre || flags.showAll)
{
os << "Options:" << endl; os << "Options:" << endl;
os << " --use-pcre" << "\t" << "use PCRE expressions" << endl; os << " --use-pcre" << "\t" << "use PCRE expressions" << endl;
#endif }
} }
else if (!strcmp(command, "cp")) else if (!strcmp(command, "cp"))
{ {
@@ -2342,13 +2371,14 @@ string getHelpStr(const char *command)
os << "If \"dstemail:\" provided, the file/folder will be sent to that user's inbox (//in)" << endl; os << "If \"dstemail:\" provided, the file/folder will be sent to that user's inbox (//in)" << endl;
os << " e.g: cp /path/to/file user@doma.in:" << endl; os << " e.g: cp /path/to/file user@doma.in:" << endl;
os << " Remember the trailing \":\", otherwise a file with the name of that user (\"user@doma.in\") will be created" << endl; os << " Remember the trailing \":\", otherwise a file with the name of that user (\"user@doma.in\") will be created" << endl;
#ifdef USE_PCRE
if (flags.usePcre || flags.showAll)
{
os << "Options:" << endl; os << "Options:" << endl;
os << " --use-pcre" << "\t" << "use PCRE expressions" << endl; os << " --use-pcre" << "\t" << "use PCRE expressions" << endl;
#endif
} }
#ifndef _WIN32 }
else if (!strcmp(command, "permissions")) else if ((!flags.win || flags.showAll) && !strcmp(command, "permissions"))
{ {
os << "Shows/Establish default permissions for files and folders created by MEGAcmd." << endl; os << "Shows/Establish default permissions for files and folders created by MEGAcmd." << endl;
os << endl; os << endl;
@@ -2363,10 +2393,9 @@ string getHelpStr(const char *command)
os << " " << "\t" << " Notice that permissions of already existing files/folders will not change." << endl; os << " " << "\t" << " Notice that permissions of already existing files/folders will not change." << endl;
os << " " << "\t" << " Notice that permissions of already existing files/folders will not change." << endl; os << " " << "\t" << " Notice that permissions of already existing files/folders will not change." << endl;
os << endl; os << endl;
os << "Notice: this permissions will be saved for the next time you execute MEGAcmd server. They will be removed if you logout." << endl; os << "Note: permissions will be saved for the next time you execute MEGAcmd server. They will be removed if you logout. Permissions are not available on Windows." << endl;
} }
#endif
else if (!strcmp(command, "https")) else if (!strcmp(command, "https"))
{ {
os << "Shows if HTTPS is used for transfers. Use \"https on\" to enable it." << endl; os << "Shows if HTTPS is used for transfers. Use \"https on\" to enable it." << endl;
@@ -2388,15 +2417,17 @@ string getHelpStr(const char *command)
os << "Options:" << endl; os << "Options:" << endl;
os << " -f " << "\t" << "Force (no asking)" << endl; os << " -f " << "\t" << "Force (no asking)" << endl;
os << " --all" << "\t" << "Delete versions of all nodes. This will delete the version histories of all files (not current files)." << endl; os << " --all" << "\t" << "Delete versions of all nodes. This will delete the version histories of all files (not current files)." << endl;
#ifdef USE_PCRE
if (flags.usePcre || flags.showAll)
{
os << " --use-pcre" << "\t" << "use PCRE expressions" << endl; os << " --use-pcre" << "\t" << "use PCRE expressions" << endl;
#endif }
os << endl; os << endl;
os << "To see versions of a file use \"ls --versions\"." << endl; os << "To see versions of a file use \"ls --versions\"." << endl;
os << "To see space occupied by file versions use \"du --versions\"." << endl; os << "To see space occupied by file versions use \"du --versions\"." << endl;
} }
#ifdef HAVE_LIBUV else if ((flags.haveLibuv || flags.showAll) && !strcmp(command, "webdav"))
else if (!strcmp(command, "webdav"))
{ {
os << "Configures a WEBDAV server to serve a location in MEGA" << endl; os << "Configures a WEBDAV server to serve a location in MEGA" << endl;
os << endl; os << endl;
@@ -2411,17 +2442,20 @@ string getHelpStr(const char *command)
os << " --tls " << "\t" << "*Serve with TLS (HTTPS)" << endl; os << " --tls " << "\t" << "*Serve with TLS (HTTPS)" << endl;
os << " --certificate=/path/to/certificate.pem" << "\t" << "*Path to PEM formated certificate" << endl; os << " --certificate=/path/to/certificate.pem" << "\t" << "*Path to PEM formated certificate" << endl;
os << " --key=/path/to/certificate.key" << "\t" << "*Path to PEM formated key" << endl; os << " --key=/path/to/certificate.key" << "\t" << "*Path to PEM formated key" << endl;
#ifdef USE_PCRE
if (flags.usePcre || flags.showAll)
{
os << " --use-pcre" << "\t" << "use PCRE expressions" << endl; os << " --use-pcre" << "\t" << "use PCRE expressions" << endl;
#endif }
os << endl; os << endl;
os << "*If you serve more than one location, these parameters will be ignored and use those of the first location served." << endl; os << "*If you serve more than one location, these parameters will be ignored and use those of the first location served." << endl;
os << " If you want to change those parameters, you need to stop serving all locations and configure them again." << endl; os << " If you want to change those parameters, you need to stop serving all locations and configure them again." << endl;
os << endl; os << endl;
os << "Caveat: This functionality is in BETA state. If you experience any issue with this, please contact: support@mega.nz" << endl; os << "Caveat: This functionality is in BETA state. It might not be available on all platforms. If you experience any issue with this, please contact: support@mega.nz" << endl;
os << endl; os << endl;
} }
else if (!strcmp(command, "ftp")) else if ((flags.haveLibuv || flags.showAll) && !strcmp(command, "ftp"))
{ {
os << "Configures a FTP server to serve a location in MEGA" << endl; os << "Configures a FTP server to serve a location in MEGA" << endl;
os << endl; os << endl;
@@ -2437,17 +2471,19 @@ string getHelpStr(const char *command)
os << " --tls " << "\t" << "*Serve with TLS (FTPs)" << endl; os << " --tls " << "\t" << "*Serve with TLS (FTPs)" << endl;
os << " --certificate=/path/to/certificate.pem" << "\t" << "*Path to PEM formated certificate" << endl; os << " --certificate=/path/to/certificate.pem" << "\t" << "*Path to PEM formated certificate" << endl;
os << " --key=/path/to/certificate.key" << "\t" << "*Path to PEM formated key" << endl; os << " --key=/path/to/certificate.key" << "\t" << "*Path to PEM formated key" << endl;
#ifdef USE_PCRE
if (flags.usePcre || flags.showAll)
{
os << " --use-pcre" << "\t" << "use PCRE expressions" << endl; os << " --use-pcre" << "\t" << "use PCRE expressions" << endl;
#endif }
os << endl; os << endl;
os << "*If you serve more than one location, these parameters will be ignored and used those of the first location served." << endl; os << "*If you serve more than one location, these parameters will be ignored and used those of the first location served." << endl;
os << " If you want to change those parameters, you need to stop serving all locations and configure them again." << endl; os << " If you want to change those parameters, you need to stop serving all locations and configure them again." << endl;
os << endl; os << endl;
os << "Caveat: This functionality is in BETA state. If you experience any issue with this, please contact: support@mega.nz" << endl; os << "Caveat: This functionality is in BETA state. It might not be available on all platforms. If you experience any issue with this, please contact: support@mega.nz" << endl;
os << endl; os << endl;
} }
#endif
else if (!strcmp(command, "exclude")) else if (!strcmp(command, "exclude"))
{ {
os << "Manages exclusions in syncs." << endl; os << "Manages exclusions in syncs." << endl;
@@ -2579,9 +2615,12 @@ string getHelpStr(const char *command)
os << "Prints/Modifies the status of current exports" << endl; os << "Prints/Modifies the status of current exports" << endl;
os << endl; os << endl;
os << "Options:" << endl; os << "Options:" << endl;
#ifdef USE_PCRE
if (flags.usePcre || flags.showAll)
{
os << " --use-pcre" << "\t" << "The provided path will use Perl Compatible Regular Expressions (PCRE)" << endl; os << " --use-pcre" << "\t" << "The provided path will use Perl Compatible Regular Expressions (PCRE)" << endl;
#endif }
os << " -a" << "\t" << "Adds an export." << endl; os << " -a" << "\t" << "Adds an export." << endl;
os << " " << "\t" << "Returns an error if the export already exists." << endl; os << " " << "\t" << "Returns an error if the export already exists." << endl;
os << " " << "\t" << "To modify an existing export (e.g., to change expiration time, password, etc.), it must be deleted and then re-added." << endl; os << " " << "\t" << "To modify an existing export (e.g., to change expiration time, password, etc.), it must be deleted and then re-added." << endl;
@@ -2617,9 +2656,12 @@ string getHelpStr(const char *command)
os << "Prints/Modifies the status of current shares" << endl; os << "Prints/Modifies the status of current shares" << endl;
os << endl; os << endl;
os << "Options:" << endl; os << "Options:" << endl;
#ifdef USE_PCRE
if (flags.usePcre || flags.showAll)
{
os << " --use-pcre" << "\t" << "use PCRE expressions" << endl; os << " --use-pcre" << "\t" << "use PCRE expressions" << endl;
#endif }
os << " -p" << "\t" << "Show pending shares too" << endl; os << " -p" << "\t" << "Show pending shares too" << endl;
os << " --with=email" << "\t" << "Determines the email of the user to [no longer] share with" << endl; os << " --with=email" << "\t" << "Determines the email of the user to [no longer] share with" << endl;
os << " -d" << "\t" << "Stop sharing with the selected user" << endl; os << " -d" << "\t" << "Stop sharing with the selected user" << endl;
@@ -2777,10 +2819,12 @@ string getHelpStr(const char *command)
{ {
os << "Prints the contents of remote files" << endl; os << "Prints the contents of remote files" << endl;
os << endl; os << endl;
#ifdef _WIN32
os << "To avoid issues with encoding, if you want to cat the exact binary contents of a remote file into a local one, " << endl; if (flags.win || flags.showAll)
{
os << "To avoid issues with encoding on Windows, if you want to cat the exact binary contents of a remote file into a local one," << endl;
os << "use non-interactive mode with -o /path/to/file. See help \"non-interactive\"" << endl; os << "use non-interactive mode with -o /path/to/file. See help \"non-interactive\"" << endl;
#endif }
} }
else if (!strcmp(command, "mediainfo")) else if (!strcmp(command, "mediainfo"))
{ {
@@ -2855,9 +2899,12 @@ string getHelpStr(const char *command)
os << " " << "\t" << " \"-4M+100K\" shows files smaller than 4 Mbytes and bigger than 100 Kbytes" << endl; os << " " << "\t" << " \"-4M+100K\" shows files smaller than 4 Mbytes and bigger than 100 Kbytes" << endl;
os << " --show-handles" << "\t" << "Prints files/folders handles (H:XXXXXXXX). You can address a file/folder by its handle" << endl; os << " --show-handles" << "\t" << "Prints files/folders handles (H:XXXXXXXX). You can address a file/folder by its handle" << endl;
os << " --print-only-handles" << "\t" << "Prints only files/folders handles (H:XXXXXXXX). You can address a file/folder by its handle" << endl; os << " --print-only-handles" << "\t" << "Prints only files/folders handles (H:XXXXXXXX). You can address a file/folder by its handle" << endl;
#ifdef USE_PCRE
if (flags.usePcre || flags.showAll)
{
os << " --use-pcre" << "\t" << "use PCRE expressions" << endl; os << " --use-pcre" << "\t" << "use PCRE expressions" << endl;
#endif }
os << " -l" << "\t" << "Prints file info" << endl; os << " -l" << "\t" << "Prints file info" << endl;
printTimeFormatHelp(os); printTimeFormatHelp(os);
} }
@@ -3004,9 +3051,7 @@ string getHelpStr(const char *command)
os << " " << cB <<" = \t" << "Backup transfer. The transfer is done in the context of a backup" << endl; os << " " << cB <<" = \t" << "Backup transfer. The transfer is done in the context of a backup" << endl;
} }
else if (((flags.win && !flags.readline) || flags.showAll) && !strcmp(command, "autocomplete"))
#if defined(_WIN32) && defined(NO_READLINE)
else if (!strcmp(command, "autocomplete"))
{ {
os << "Modifes how tab completion operates." << endl; os << "Modifes how tab completion operates." << endl;
os << endl; os << endl;
@@ -3015,8 +3060,10 @@ string getHelpStr(const char *command)
os << "Options:" << endl; os << "Options:" << endl;
os << " dos" << "\t" << "Each press of tab places the next option into the command line" << endl; os << " dos" << "\t" << "Each press of tab places the next option into the command line" << endl;
os << " unix" << "\t" << "Options are listed in a table, or put in-line if there is only one" << endl; os << " unix" << "\t" << "Options are listed in a table, or put in-line if there is only one" << endl;
os << endl;
os << "Note: this command is only available on some versions of Windows" << endl;
} }
else if (!strcmp(command, "codepage")) else if (((flags.win && !flags.readline) || flags.showAll) && !strcmp(command, "codepage"))
{ {
os << "Switches the codepage used to decide which characters show on-screen." << endl; os << "Switches the codepage used to decide which characters show on-screen." << endl;
os << endl; os << endl;
@@ -3027,65 +3074,86 @@ string getHelpStr(const char *command)
os << " (no option)" << "\t" << "Outputs the selected code page and secondary codepage (if configured)." << endl; os << " (no option)" << "\t" << "Outputs the selected code page and secondary codepage (if configured)." << endl;
os << " N" << "\t" << "Sets the main codepage to N. 65001 is Unicode." << endl; os << " N" << "\t" << "Sets the main codepage to N. 65001 is Unicode." << endl;
os << " M" << "\t" << "Sets the secondary codepage to M, which is used if the primary can't translate a character." << endl; os << " M" << "\t" << "Sets the secondary codepage to M, which is used if the primary can't translate a character." << endl;
os << endl;
os << "Note: this command is only available on some versions of Windows" << endl;
} }
#endif
return os.str(); return os.str();
} }
#define SSTR( x ) static_cast< const std::ostringstream & >( \ #define SSTR( x ) static_cast< const std::ostringstream & >( \
( std::ostringstream() << std::dec << x ) ).str() ( std::ostringstream() << std::dec << x ) ).str()
void printAvailableCommands(int extensive = 0) void printAvailableCommands(int extensive = 0, bool showAllOptions = false)
{ {
vector<string> validCommandsOrdered = validCommands; std::set<string> validCommandSet(validCommands.begin(), validCommands.end());
sort(validCommandsOrdered.begin(), validCommandsOrdered.end()); if (showAllOptions)
{
validCommandSet.emplace("webdav");
validCommandSet.emplace("ftp");
validCommandSet.emplace("autocomplete");
validCommandSet.emplace("codepage");
validCommandSet.emplace("unicode");
validCommandSet.emplace("permissions");
validCommandSet.emplace("update");
}
if (!extensive) if (!extensive)
{ {
size_t i = 0; const size_t size = validCommandSet.size();
size_t j = (validCommandsOrdered.size()/3)+((validCommandsOrdered.size()%3>0)?1:0); const size_t third = (size / 3) + ((size % 3 > 0) ? 1 : 0);
size_t k = 2*(validCommandsOrdered.size()/3)+validCommandsOrdered.size()%3; const size_t twoThirds = 2 * (size / 3) + size % 3;
for (i = 0; i < validCommandsOrdered.size() && j < validCommandsOrdered.size() && k < validCommandsOrdered.size(); i++, j++, k++)
auto it = validCommandSet.begin();
auto it2 = std::next(it, third);
auto it3 = std::next(it, twoThirds);
for (; it != validCommandSet.end() && it2 != validCommandSet.end() && it3 != validCommandSet.end(); ++it, ++it2, ++it3)
{ {
OUTSTREAM << " " << getLeftAlignedStr(validCommandsOrdered.at(i), 20) << getLeftAlignedStr(validCommandsOrdered.at(j), 20) << " " << validCommandsOrdered.at(k) << endl; OUTSTREAM << " " << getLeftAlignedStr(*it, 20) << getLeftAlignedStr(*it2, 20) << " " << *it3 << endl;
} }
if (validCommandsOrdered.size()%3)
if (size % 3)
{ {
OUTSTREAM << " " << getLeftAlignedStr(validCommandsOrdered.at(i), 20) ; OUTSTREAM << " " << getLeftAlignedStr(*it, 20);
if (validCommandsOrdered.size()%3 > 1 ) if (size % 3 > 1 )
{ {
OUTSTREAM << getLeftAlignedStr(validCommandsOrdered.at(j), 20) ; OUTSTREAM << getLeftAlignedStr(*it2, 20);
} }
OUTSTREAM << endl; OUTSTREAM << endl;
} }
return;
} }
else
HelpFlags helpFlags(showAllOptions);
for (const string& command : validCommandSet)
{ {
for (size_t i = 0; i < validCommandsOrdered.size(); i++) if (command == "completion")
{
if (validCommandsOrdered.at(i)!="completion")
{ {
continue;
}
if (extensive > 1) if (extensive > 1)
{ {
unsigned int width = getNumberOfCols(); OUTSTREAM << "<" << command << ">" << endl;
OUTSTREAM << getHelpStr(command.c_str(), helpFlags);
OUTSTREAM << "<" << validCommandsOrdered.at(i) << ">" << endl; unsigned int width = getNumberOfCols();
OUTSTREAM << getHelpStr(validCommandsOrdered.at(i).c_str());
for (unsigned int j = 0; j < width; j++) OUTSTREAM << "-"; for (unsigned int j = 0; j < width; j++) OUTSTREAM << "-";
OUTSTREAM << endl; OUTSTREAM << endl;
} }
else else
{ {
OUTSTREAM << " " << getUsageStr(validCommandsOrdered.at(i).c_str()); OUTSTREAM << " " << getUsageStr(command.c_str(), helpFlags);
string helpstr = getHelpStr(validCommandsOrdered.at(i).c_str());
string helpstr = getHelpStr(command.c_str(), helpFlags);
helpstr = string(helpstr, helpstr.find_first_of("\n") + 1); helpstr = string(helpstr, helpstr.find_first_of("\n") + 1);
OUTSTREAM << ": " << string(helpstr, 0, helpstr.find_first_of("\n")); OUTSTREAM << ": " << string(helpstr, 0, helpstr.find_first_of("\n"));
OUTSTREAM << endl; OUTSTREAM << endl;
} }
} }
} }
}
}
void checkBlockStatus(bool waitcompletion = true) void checkBlockStatus(bool waitcompletion = true)
{ {
@@ -3371,7 +3439,7 @@ void executecommand(char* ptr)
OUTSTREAM << endl << "Commands:" << endl; OUTSTREAM << endl << "Commands:" << endl;
printAvailableCommands(getFlag(&clflags,"f")); printAvailableCommands(getFlag(&clflags, "f"), getFlag(&clflags, "show-all-options"));
OUTSTREAM << endl << "Verbosity: You can increase the amount of information given by any command by passing \"-v\" (\"-vv\", \"-vvv\", ...)" << endl; OUTSTREAM << endl << "Verbosity: You can increase the amount of information given by any command by passing \"-v\" (\"-vv\", \"-vvv\", ...)" << endl;
if (getBlocked()) if (getBlocked())

View File

@@ -158,7 +158,37 @@ public:
mega::MegaApi* getFreeApiFolder(); mega::MegaApi* getFreeApiFolder();
void freeApiFolder(mega::MegaApi *apiFolder); void freeApiFolder(mega::MegaApi *apiFolder);
const char * getUsageStr(const char *command); struct HelpFlags
{
bool win = false;
bool apple = false;
bool usePcre = false;
bool haveLibuv = false;
bool readline = true;
bool showAll = false;
HelpFlags(bool showAll = false) :
showAll(showAll)
{
#ifdef USE_PCRE
usePcre = true;
#endif
#ifdef _WIN32
win = true;
#endif
#ifdef __APPLE__
apple = true;
#endif
#ifdef HAVE_LIBUV
haveLibuv = true;
#endif
#ifdef NO_READLINE
readline = false;
#endif
}
};
const char * getUsageStr(const char *command, const HelpFlags& flags = {});
void unescapeifRequired(std::string &what); void unescapeifRequired(std::string &what);