2
0
mirror of https://github.com/meganz/MEGAcmd synced 2025-08-31 05:45:11 +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 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).
@@ -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
### Misc.
* [`autocomplete`](docs/commands/autocomplete.md)`[dos | unix]` Modifes how tab completion operates.
* [`cancel`](docs/commands/cancel.md) Cancels your MEGA account
* [`cat`](docs/commands/cat.md)`remotepath1 remotepath2 ...` Prints the contents of remote files
* [`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
* [`debug`](docs/commands/debug.md) Enters debugging mode (HIGHLY VERBOSE)
* [`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
* [`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.
* [`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.
* [`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
@@ -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
* [`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
* [`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
## 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
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 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>

View File

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

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 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>

View File

@@ -5,7 +5,7 @@ import subprocess
def get_help_output(detail):
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:
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("upgrade");
validParams->insert("paths");
validParams->insert("show-all-options");
#ifdef _WIN32
validParams->insert("unicode");
#endif
@@ -1491,7 +1492,7 @@ void freeApiFolder(MegaApi *apiFolder)
mutexapiFolders.unlock();
}
const char * getUsageStr(const char *command)
const char * getUsageStr(const char *command, const HelpFlags& flags)
{
if (!strcmp(command, "login"))
{
@@ -1569,19 +1570,20 @@ const char * getUsageStr(const char *command)
{
return "mount";
}
#if defined(_WIN32) && !defined(NO_READLINE)
if (!strcmp(command, "unicode"))
if (((flags.win && !flags.readline) || flags.showAll) && !strcmp(command, "unicode"))
{
return "unicode";
}
#endif
if (!strcmp(command, "ls"))
{
return "ls [-halRr] [--show-handles] [--tree] [--versions] [remotepath]"
#ifdef USE_PCRE
" [--use-pcre]"
#endif
" [--show-creation-time] [--time-format=FORMAT]";
if (flags.usePcre || flags.showAll)
{
return "ls [-halRr] [--show-handles] [--tree] [--versions] [remotepath] [--use-pcre] [--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"))
{
@@ -1597,11 +1599,14 @@ const char * getUsageStr(const char *command)
}
if (!strcmp(command, "du"))
{
#ifdef USE_PCRE
return "du [-h] [--versions] [remotepath remotepath2 remotepath3 ... ] [--use-pcre]";
#else
return "du [-h] [--versions] [remotepath remotepath2 remotepath3 ... ]";
#endif
if (flags.usePcre || flags.showAll)
{
return "du [-h] [--versions] [remotepath remotepath2 remotepath3 ... ] [--use-pcre]";
}
else
{
return "du [-h] [--versions] [remotepath remotepath2 remotepath3 ... ]";
}
}
if (!strcmp(command, "pwd"))
{
@@ -1629,11 +1634,14 @@ const char * getUsageStr(const char *command)
}
if (!strcmp(command, "get"))
{
#ifdef USE_PCRE
return "get [-m] [-q] [--ignore-quota-warn] [--use-pcre] [--password=PASSWORD] exportedlink|remotepath [localpath]";
#else
return "get [-m] [-q] [--ignore-quota-warn] [--password=PASSWORD] exportedlink|remotepath [localpath]";
#endif
if (flags.usePcre || flags.showAll)
{
return "get [-m] [-q] [--ignore-quota-warn] [--use-pcre] [--password=PASSWORD] exportedlink|remotepath [localpath]";
}
else
{
return "get [-m] [-q] [--ignore-quota-warn] [--password=PASSWORD] exportedlink|remotepath [localpath]";
}
}
if (!strcmp(command, "getq"))
{
@@ -1657,59 +1665,74 @@ const char * getUsageStr(const char *command)
}
if (!strcmp(command, "rm"))
{
#ifdef USE_PCRE
return "rm [-r] [-f] [--use-pcre] remotepath";
#else
return "rm [-r] [-f] remotepath";
#endif
if (flags.usePcre || flags.showAll)
{
return "rm [-r] [-f] [--use-pcre] remotepath";
}
else
{
return "rm [-r] [-f] remotepath";
}
}
if (!strcmp(command, "mv"))
{
#ifdef USE_PCRE
return "mv srcremotepath [--use-pcre] [srcremotepath2 srcremotepath3 ..] dstremotepath";
#else
return "mv srcremotepath [srcremotepath2 srcremotepath3 ..] dstremotepath";
#endif
if (flags.usePcre || flags.showAll)
{
return "mv srcremotepath [--use-pcre] [srcremotepath2 srcremotepath3 ..] dstremotepath";
}
else
{
return "mv srcremotepath [srcremotepath2 srcremotepath3 ..] dstremotepath";
}
}
if (!strcmp(command, "cp"))
{
#ifdef USE_PCRE
return "cp [--use-pcre] srcremotepath [srcremotepath2 srcremotepath3 ..] dstremotepath|dstemail:";
#else
return "cp srcremotepath [srcremotepath2 srcremotepath3 ..] dstremotepath|dstemail:";
#endif
if (flags.usePcre || flags.showAll)
{
return "cp [--use-pcre] srcremotepath [srcremotepath2 srcremotepath3 ..] dstremotepath|dstemail:";
}
else
{
return "cp srcremotepath [srcremotepath2 srcremotepath3 ..] dstremotepath|dstemail:";
}
}
if (!strcmp(command, "deleteversions"))
{
#ifdef USE_PCRE
return "deleteversions [-f] (--all | remotepath1 remotepath2 ...) [--use-pcre]";
#else
return "deleteversions [-f] (--all | remotepath1 remotepath2 ...)";
#endif
if (flags.usePcre || flags.showAll)
{
return "deleteversions [-f] (--all | remotepath1 remotepath2 ...) [--use-pcre]";
}
else
{
return "deleteversions [-f] (--all | remotepath1 remotepath2 ...)";
}
}
if (!strcmp(command, "exclude"))
{
return "exclude [(-a|-d) pattern1 pattern2 pattern3]";
}
#ifdef HAVE_LIBUV
if (!strcmp(command, "webdav"))
if ((flags.haveLibuv || flags.showAll) && !strcmp(command, "webdav"))
{
#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]";
#else
return "webdav [-d (--all | remotepath ) ] [ remotepath [--port=PORT] [--public] [--tls --certificate=/path/to/certificate.pem --key=/path/to/certificate.key]]";
#endif
if (flags.usePcre || flags.showAll)
{
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]]";
}
}
if (!strcmp(command, "ftp"))
if ((flags.haveLibuv || flags.showAll) && !strcmp(command, "ftp"))
{
#ifdef USE_PCRE
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 (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"))
{
return "sync [localpath dstremotepath| [-dsr] [ID|localpath]";
@@ -1722,12 +1745,10 @@ const char * getUsageStr(const char *command)
{
return "https [on|off]";
}
#ifndef _WIN32
if (!strcmp(command, "permissions"))
if ((!flags.win || flags.showAll) && !strcmp(command, "permissions"))
{
return "permissions [(--files|--folders) [-s XXX]]";
}
#endif
if (!strcmp(command, "export"))
{
return "export [-d|-a"
@@ -1741,11 +1762,14 @@ const char * getUsageStr(const char *command)
}
if (!strcmp(command, "share"))
{
#ifdef USE_PCRE
return "share [-p] [-d|-a --with=user@email.com [--level=LEVEL]] [remotepath] [--use-pcre] [--time-format=FORMAT]";
#else
return "share [-p] [-d|-a --with=user@email.com [--level=LEVEL]] [remotepath] [--time-format=FORMAT]";
#endif
if (flags.usePcre || flags.showAll)
{
return "share [-p] [-d|-a --with=user@email.com [--level=LEVEL]] [remotepath] [--use-pcre] [--time-format=FORMAT]";
}
else
{
return "share [-p] [-d|-a --with=user@email.com [--level=LEVEL]] [remotepath] [--time-format=FORMAT]";
}
}
if (!strcmp(command, "invite"))
{
@@ -1892,15 +1916,18 @@ const char * getUsageStr(const char *command)
}
if (!strcmp(command, "find"))
{
return "find [remotepath] [-l] [--pattern=PATTERN] [--type=d|f] [--mtime=TIMECONSTRAIN] [--size=SIZECONSTRAIN] "
#ifdef USE_PCRE
"[--use-pcre] "
#endif
"[--time-format=FORMAT] [--show-handles|--print-only-handles]";
if (flags.usePcre || flags.showAll)
{
return "find [remotepath] [-l] [--pattern=PATTERN] [--type=d|f] [--mtime=TIMECONSTRAIN] [--size=SIZECONSTRAIN] [--use-pcre] [--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"))
{
return "help [-f|-ff|--non-interactive|--upgrade|--paths]";
return "help [-f|-ff|--non-interactive|--upgrade|--paths] [--show-all-options]";
}
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]";
}
#endif
#if defined(_WIN32) && defined(NO_READLINE)
if (!strcmp(command, "autocomplete"))
if (((flags.win && !flags.readline) || flags.showAll) && !strcmp(command, "autocomplete"))
{
return "autocomplete [dos | unix]";
}
@@ -1925,13 +1951,10 @@ const char * getUsageStr(const char *command)
{
return "codepage [N [M]]";
}
#endif
#if defined(_WIN32) || defined(__APPLE__)
if (!strcmp(command, "update"))
if ((flags.win || flags.apple || flags.showAll) && !strcmp(command, "update"))
{
return "update [--auto=on|off|query]";
}
#endif
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;
}
string getHelpStr(const char *command)
string getHelpStr(const char *command, const HelpFlags& flags = {})
{
ostringstream os;
os << "Usage: " << getUsageStr(command) << endl;
os << "Usage: " << getUsageStr(command, flags) << endl;
if (!strcmp(command, "login"))
{
os << "Logs into a MEGA account" << endl;
@@ -2064,9 +2086,10 @@ string getHelpStr(const char *command)
os << "Options:" << endl;
os << " -f" << " \t" << "Include a brief description of the commands" << endl;
os << " -ff" << "\t" << "Get a complete description of all commands" << endl;
os << " --non-interactive" << " " << "Display information on how to use MEGAcmd with scripts" << endl;
os << " --upgrade" << " " << "Display information on PRO plans" << endl;
os << " --paths" << " " << "Show caveats of local and remote paths" << endl;
os << " --non-interactive" << " " << "Display information on how to use MEGAcmd with scripts" << endl;
os << " --upgrade" << " " << "Display information on PRO plans" << 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"))
{
@@ -2090,17 +2113,17 @@ string getHelpStr(const char *command)
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;
}
#if defined(_WIN32) && !defined(NO_READLINE)
else if (!strcmp(command, "unicode"))
else if (((flags.win && flags.readline) || flags.showAll) && !strcmp(command, "unicode"))
{
os << "Toggle unicode input enabled/disabled in interactive shell" << endl;
os << endl;
os << " Unicode mode is experimental, you might experience" << endl;
os << " some issues interacting with the console" << endl;
os << " (e.g. history navigation fails)." << endl;
os << 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"))
{
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;
printTimeFormatHelp(os);
#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;
}
}
else if (!strcmp(command, "tree"))
{
@@ -2142,8 +2166,7 @@ string getHelpStr(const char *command)
os << endl;
os << "This is similar to \"ls --tree\"" << endl;
}
#if defined(_WIN32) || defined(__APPLE__)
else if (!strcmp(command, "update"))
else if ((flags.win || flags.apple || flags.showAll) && !strcmp(command, "update"))
{
os << "Updates MEGAcmd" << endl;
os << endl;
@@ -2154,12 +2177,12 @@ string getHelpStr(const char *command)
os << " --auto=ON|OFF|query" << "\t" << "Enables/disables/queries status of auto updates." << endl;
os << endl;
os << "If auto updates are enabled it will be checked while MEGAcmd server is running." << endl;
os << " If there is an update available, it will be downloaded and applied. " << endl;
os << " If there is an update available, it will be downloaded and applied." << endl;
os << " This will cause MEGAcmd to be restarted whenever the updates are applied." << endl;
os << endl;
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"))
{
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 << " --path-display-size=N" << "\t" << "Use a fixed size of N characters for paths" << 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;
}
}
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 << " " << "\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;
#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"))
{
@@ -2316,9 +2341,11 @@ string getHelpStr(const char *command)
os << "Options:" << endl;
os << " -r" << "\t" << "Delete recursively (for folders)" << endl;
os << " -f" << "\t" << "Force (no asking)" << 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;
}
}
else if (!strcmp(command, "mv"))
{
@@ -2326,10 +2353,12 @@ string getHelpStr(const char *command)
os << 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;
#ifdef USE_PCRE
os << "Options:" << endl;
os << " --use-pcre" << "\t" << "use PCRE expressions" << endl;
#endif
if (flags.usePcre || flags.showAll)
{
os << "Options:" << endl;
os << " --use-pcre" << "\t" << "use PCRE expressions" << endl;
}
}
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 << " 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;
#ifdef USE_PCRE
os << "Options:" << endl;
os << " --use-pcre" << "\t" << "use PCRE expressions" << endl;
#endif
if (flags.usePcre || flags.showAll)
{
os << "Options:" << endl;
os << " --use-pcre" << "\t" << "use PCRE expressions" << endl;
}
}
#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 << 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 << 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"))
{
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 << " -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;
#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;
}
os << endl;
os << "To see versions of a file use \"ls --versions\"." << endl;
os << "To see space occupied by file versions use \"du --versions\"." << endl;
}
#ifdef HAVE_LIBUV
else if (!strcmp(command, "webdav"))
else if ((flags.haveLibuv || flags.showAll) && !strcmp(command, "webdav"))
{
os << "Configures a WEBDAV server to serve a location in MEGA" << endl;
os << endl;
@@ -2411,17 +2442,20 @@ string getHelpStr(const char *command)
os << " --tls " << "\t" << "*Serve with TLS (HTTPS)" << 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;
#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;
}
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 want to change those parameters, you need to stop serving all locations and configure them again." << 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;
}
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 << endl;
@@ -2437,17 +2471,19 @@ string getHelpStr(const char *command)
os << " --tls " << "\t" << "*Serve with TLS (FTPs)" << 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;
#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;
}
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 want to change those parameters, you need to stop serving all locations and configure them again." << 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;
}
#endif
else if (!strcmp(command, "exclude"))
{
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 << endl;
os << "Options:" << endl;
#ifdef USE_PCRE
os << " --use-pcre" << "\t" << "The provided path will use Perl Compatible Regular Expressions (PCRE)" << endl;
#endif
if (flags.usePcre || flags.showAll)
{
os << " --use-pcre" << "\t" << "The provided path will use Perl Compatible Regular Expressions (PCRE)" << endl;
}
os << " -a" << "\t" << "Adds an export." << 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;
@@ -2617,9 +2656,12 @@ string getHelpStr(const char *command)
os << "Prints/Modifies the status of current shares" << endl;
os << endl;
os << "Options:" << 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;
}
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 << " -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 << 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;
os << "use non-interactive mode with -o /path/to/file. See help \"non-interactive\"" << endl;
#endif
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;
}
}
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 << " --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;
#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;
}
os << " -l" << "\t" << "Prints file info" << endl;
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;
}
#if defined(_WIN32) && defined(NO_READLINE)
else if (!strcmp(command, "autocomplete"))
else if (((flags.win && !flags.readline) || flags.showAll) && !strcmp(command, "autocomplete"))
{
os << "Modifes how tab completion operates." << endl;
os << endl;
@@ -3015,8 +3060,10 @@ string getHelpStr(const char *command)
os << "Options:" << 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 << 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 << endl;
@@ -3027,62 +3074,83 @@ string getHelpStr(const char *command)
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 << " 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();
}
#define SSTR( x ) static_cast< const std::ostringstream & >( \
( std::ostringstream() << std::dec << x ) ).str()
void printAvailableCommands(int extensive = 0)
void printAvailableCommands(int extensive = 0, bool showAllOptions = false)
{
vector<string> validCommandsOrdered = validCommands;
sort(validCommandsOrdered.begin(), validCommandsOrdered.end());
std::set<string> validCommandSet(validCommands.begin(), validCommands.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)
{
size_t i = 0;
size_t j = (validCommandsOrdered.size()/3)+((validCommandsOrdered.size()%3>0)?1:0);
size_t k = 2*(validCommandsOrdered.size()/3)+validCommandsOrdered.size()%3;
for (i = 0; i < validCommandsOrdered.size() && j < validCommandsOrdered.size() && k < validCommandsOrdered.size(); i++, j++, k++)
const size_t size = validCommandSet.size();
const size_t third = (size / 3) + ((size % 3 > 0) ? 1 : 0);
const size_t twoThirds = 2 * (size / 3) + size % 3;
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) ;
if (validCommandsOrdered.size()%3 > 1 )
OUTSTREAM << " " << getLeftAlignedStr(*it, 20);
if (size % 3 > 1 )
{
OUTSTREAM << getLeftAlignedStr(validCommandsOrdered.at(j), 20) ;
OUTSTREAM << getLeftAlignedStr(*it2, 20);
}
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")
{
if (extensive > 1)
{
unsigned int width = getNumberOfCols();
continue;
}
OUTSTREAM << "<" << validCommandsOrdered.at(i) << ">" << endl;
OUTSTREAM << getHelpStr(validCommandsOrdered.at(i).c_str());
for (unsigned int j = 0; j< width; j++) OUTSTREAM << "-";
OUTSTREAM << endl;
}
else
{
OUTSTREAM << " " << getUsageStr(validCommandsOrdered.at(i).c_str());
string helpstr = getHelpStr(validCommandsOrdered.at(i).c_str());
helpstr=string(helpstr,helpstr.find_first_of("\n")+1);
OUTSTREAM << ": " << string(helpstr,0,helpstr.find_first_of("\n"));
if (extensive > 1)
{
OUTSTREAM << "<" << command << ">" << endl;
OUTSTREAM << getHelpStr(command.c_str(), helpFlags);
OUTSTREAM << endl;
}
}
unsigned int width = getNumberOfCols();
for (unsigned int j = 0; j < width; j++) OUTSTREAM << "-";
OUTSTREAM << endl;
}
else
{
OUTSTREAM << " " << getUsageStr(command.c_str(), helpFlags);
string helpstr = getHelpStr(command.c_str(), helpFlags);
helpstr = string(helpstr, helpstr.find_first_of("\n") + 1);
OUTSTREAM << ": " << string(helpstr, 0, helpstr.find_first_of("\n"));
OUTSTREAM << endl;
}
}
}
@@ -3371,7 +3439,7 @@ void executecommand(char* ptr)
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;
if (getBlocked())

View File

@@ -158,7 +158,37 @@ public:
mega::MegaApi* getFreeApiFolder();
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);