Skip to content

Commit

Permalink
Add internal flag for commands.
Browse files Browse the repository at this point in the history
Allow commands to be skipped by default in the command help but still work if help is requested for the command directly.  There may be other uses for the flag in the future.

Update help for ls now that it is exposed.
  • Loading branch information
dwsteele committed May 28, 2019
1 parent 20e5b92 commit 404284b
Show file tree
Hide file tree
Showing 10 changed files with 124 additions and 20 deletions.
1 change: 1 addition & 0 deletions build/lib/pgBackRestBuild/Config/Build.pm
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ sub buildConfig
" (\n" .
" CONFIG_COMMAND_NAME(${strCommandConst})\n" .
"\n" .
" CONFIG_COMMAND_INTERNAL(" . ($rhCommand->{&CFGDEF_INTERNAL} ? 'true' : 'false') . ")\n" .
" CONFIG_COMMAND_LOG_FILE(" . ($rhCommand->{&CFGDEF_LOG_FILE} ? 'true' : 'false') . ")\n" .
" CONFIG_COMMAND_LOG_LEVEL_DEFAULT(logLevel" . ucfirst(lc($rhCommand->{&CFGDEF_LOG_LEVEL_DEFAULT})) . ")\n" .
" CONFIG_COMMAND_LOG_LEVEL_STDERR_MAX(logLevel" .
Expand Down
11 changes: 11 additions & 0 deletions build/lib/pgBackRestBuild/Config/Data.pm
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,7 @@ my $rhCommandDefine =

&CFGCMD_ARCHIVE_GET_ASYNC =>
{
&CFGDEF_INTERNAL => true,
&CFGDEF_LOG_FILE => true,
&CFGDEF_LOCK_REQUIRED => true,
&CFGDEF_LOCK_TYPE => CFGDEF_LOCK_TYPE_ARCHIVE,
Expand All @@ -612,6 +613,7 @@ my $rhCommandDefine =

&CFGCMD_ARCHIVE_PUSH_ASYNC =>
{
&CFGDEF_INTERNAL => true,
&CFGDEF_LOG_FILE => true,
&CFGDEF_LOCK_REQUIRED => true,
&CFGDEF_LOCK_REMOTE_REQUIRED => true,
Expand Down Expand Up @@ -652,11 +654,13 @@ my $rhCommandDefine =

&CFGCMD_LOCAL =>
{
&CFGDEF_INTERNAL => true,
&CFGDEF_LOG_LEVEL_STDERR_MAX => ERROR,
},

&CFGCMD_REMOTE =>
{
&CFGDEF_INTERNAL => true,
&CFGDEF_LOG_LEVEL_STDERR_MAX => ERROR,
},

Expand Down Expand Up @@ -692,6 +696,7 @@ my $rhCommandDefine =

&CFGCMD_STORAGE_LIST =>
{
&CFGDEF_INTERNAL => true,
&CFGDEF_LOG_FILE => false,
&CFGDEF_LOG_LEVEL_DEFAULT => DEBUG,
&CFGDEF_PARAMETER_ALLOWED => true,
Expand Down Expand Up @@ -2575,6 +2580,12 @@ my %hConfigDefine =
####################################################################################################################################
foreach my $strCommand (sort(keys(%{$rhCommandDefine})))
{
# Commands are external by default
if (!defined($rhCommandDefine->{$strCommand}{&CFGDEF_INTERNAL}))
{
$rhCommandDefine->{$strCommand}{&CFGDEF_INTERNAL} = false;
}

# Log files are created by default
if (!defined($rhCommandDefine->{$strCommand}{&CFGDEF_LOG_FILE}))
{
Expand Down
2 changes: 1 addition & 1 deletion doc/lib/BackRestDoc/Common/DocConfig.pm
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ sub process
foreach my $strCommand (cfgDefineCommandList())
{
if ($strCommand eq CFGCMD_REMOTE || $strCommand eq CFGCMD_LOCAL || $strCommand eq CFGCMD_ARCHIVE_GET_ASYNC ||
$strCommand eq CFGCMD_ARCHIVE_PUSH_ASYNC || $strCommand eq CFGCMD_STORAGE_LIST)
$strCommand eq CFGCMD_ARCHIVE_PUSH_ASYNC)
{
next;
}
Expand Down
30 changes: 27 additions & 3 deletions doc/xml/reference.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1218,16 +1218,40 @@
</command-example-list>
</command>

<!-- OPERATION - STORAGE-LIST COMMAND -->
<command id="storage-list" name="Storage List">
<!-- OPERATION - LS COMMAND -->
<command id="ls" name="Storage List">
<summary>List paths/files in the repository.</summary>

<text>This is intended to be a general purpose list function, but for now it only works on the repository.</text>

<option-list>
<!-- OPERATION - LS COMMAND - FILTER OPTION -->
<option id="filter" name="Filter Output">
<summary>Filter output with a regular expression.</summary>

<text>The filter is applied against the file/path names before they are output.</text>

<example>(F|D|I)$</example>
</option>

<!-- OPERATION - LS COMMAND - SORT OPTION -->
<option id="sort" name="Sort Output">
<summary>Sort output ascending/descending.</summary>

<text>The following sort types are supported:
<ul>
<li><id>asc</id> - sort ascending.</li>
<li><id>desc</id> - sort descending.</li>
</ul></text>

<example>desc</example>
</option>
</option-list>

<command-example-list>
<command-example title="List all backups in a stanza">
<text><code-block title="">
{[backrest-exe]} storage-list backup/demo
{[backrest-exe]} ls backup/demo
</code-block>

List all backups in the demo stanza.</text>
Expand Down
26 changes: 10 additions & 16 deletions src/command/help/help.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,32 +165,26 @@ helpRender(void)

for (ConfigCommand commandId = 0; commandId < CFG_COMMAND_TOTAL; commandId++)
{
if (commandId == cfgCmdNone)
if (commandId == cfgCmdNone || cfgCommandInternal(commandId))
continue;

// Only check size if the command has a help summary so we know it is a documented command
if (cfgDefCommandHelpSummary(cfgCommandDefIdFromId(commandId)) != NULL &&
strlen(cfgCommandName(commandId)) > commandSizeMax)
{
if (strlen(cfgCommandName(commandId)) > commandSizeMax)
commandSizeMax = strlen(cfgCommandName(commandId));
}
}

// Output help for each command
for (ConfigCommand commandId = 0; commandId < CFG_COMMAND_TOTAL; commandId++)
{
if (commandId == cfgCmdNone)
if (commandId == cfgCmdNone || cfgCommandInternal(commandId))
continue;

const char *helpSummary = cfgDefCommandHelpSummary(cfgCommandDefIdFromId(commandId));

if (helpSummary != NULL)
{
strCatFmt(
result, " %s%*s%s\n", cfgCommandName(commandId),
(int)(commandSizeMax - strlen(cfgCommandName(commandId)) + 2), "",
strPtr(helpRenderText(STR(helpSummary), commandSizeMax + 6, false, CONSOLE_WIDTH)));
}
strCatFmt(
result, " %s%*s%s\n", cfgCommandName(commandId),
(int)(commandSizeMax - strlen(cfgCommandName(commandId)) + 2), "",
strPtr(
helpRenderText(
STR(cfgDefCommandHelpSummary(cfgCommandDefIdFromId(commandId))), commandSizeMax + 6, false,
CONSOLE_WIDTH)));
}

// Construct message for more help
Expand Down
19 changes: 19 additions & 0 deletions src/config/config.auto.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ static ConfigCommandData configCommandData[CFG_COMMAND_TOTAL] = CONFIG_COMMAND_L
(
CONFIG_COMMAND_NAME(CFGCMD_ARCHIVE_GET)

CONFIG_COMMAND_INTERNAL(false)
CONFIG_COMMAND_LOG_FILE(false)
CONFIG_COMMAND_LOG_LEVEL_DEFAULT(logLevelInfo)
CONFIG_COMMAND_LOG_LEVEL_STDERR_MAX(logLevelTrace)
Expand All @@ -49,6 +50,7 @@ static ConfigCommandData configCommandData[CFG_COMMAND_TOTAL] = CONFIG_COMMAND_L
(
CONFIG_COMMAND_NAME(CFGCMD_ARCHIVE_GET_ASYNC)

CONFIG_COMMAND_INTERNAL(true)
CONFIG_COMMAND_LOG_FILE(true)
CONFIG_COMMAND_LOG_LEVEL_DEFAULT(logLevelInfo)
CONFIG_COMMAND_LOG_LEVEL_STDERR_MAX(logLevelTrace)
Expand All @@ -62,6 +64,7 @@ static ConfigCommandData configCommandData[CFG_COMMAND_TOTAL] = CONFIG_COMMAND_L
(
CONFIG_COMMAND_NAME(CFGCMD_ARCHIVE_PUSH)

CONFIG_COMMAND_INTERNAL(false)
CONFIG_COMMAND_LOG_FILE(false)
CONFIG_COMMAND_LOG_LEVEL_DEFAULT(logLevelInfo)
CONFIG_COMMAND_LOG_LEVEL_STDERR_MAX(logLevelTrace)
Expand All @@ -75,6 +78,7 @@ static ConfigCommandData configCommandData[CFG_COMMAND_TOTAL] = CONFIG_COMMAND_L
(
CONFIG_COMMAND_NAME(CFGCMD_ARCHIVE_PUSH_ASYNC)

CONFIG_COMMAND_INTERNAL(true)
CONFIG_COMMAND_LOG_FILE(true)
CONFIG_COMMAND_LOG_LEVEL_DEFAULT(logLevelInfo)
CONFIG_COMMAND_LOG_LEVEL_STDERR_MAX(logLevelTrace)
Expand All @@ -88,6 +92,7 @@ static ConfigCommandData configCommandData[CFG_COMMAND_TOTAL] = CONFIG_COMMAND_L
(
CONFIG_COMMAND_NAME(CFGCMD_BACKUP)

CONFIG_COMMAND_INTERNAL(false)
CONFIG_COMMAND_LOG_FILE(true)
CONFIG_COMMAND_LOG_LEVEL_DEFAULT(logLevelInfo)
CONFIG_COMMAND_LOG_LEVEL_STDERR_MAX(logLevelTrace)
Expand All @@ -101,6 +106,7 @@ static ConfigCommandData configCommandData[CFG_COMMAND_TOTAL] = CONFIG_COMMAND_L
(
CONFIG_COMMAND_NAME(CFGCMD_CHECK)

CONFIG_COMMAND_INTERNAL(false)
CONFIG_COMMAND_LOG_FILE(false)
CONFIG_COMMAND_LOG_LEVEL_DEFAULT(logLevelInfo)
CONFIG_COMMAND_LOG_LEVEL_STDERR_MAX(logLevelTrace)
Expand All @@ -114,6 +120,7 @@ static ConfigCommandData configCommandData[CFG_COMMAND_TOTAL] = CONFIG_COMMAND_L
(
CONFIG_COMMAND_NAME(CFGCMD_EXPIRE)

CONFIG_COMMAND_INTERNAL(false)
CONFIG_COMMAND_LOG_FILE(true)
CONFIG_COMMAND_LOG_LEVEL_DEFAULT(logLevelInfo)
CONFIG_COMMAND_LOG_LEVEL_STDERR_MAX(logLevelTrace)
Expand All @@ -127,6 +134,7 @@ static ConfigCommandData configCommandData[CFG_COMMAND_TOTAL] = CONFIG_COMMAND_L
(
CONFIG_COMMAND_NAME(CFGCMD_HELP)

CONFIG_COMMAND_INTERNAL(false)
CONFIG_COMMAND_LOG_FILE(false)
CONFIG_COMMAND_LOG_LEVEL_DEFAULT(logLevelDebug)
CONFIG_COMMAND_LOG_LEVEL_STDERR_MAX(logLevelTrace)
Expand All @@ -140,6 +148,7 @@ static ConfigCommandData configCommandData[CFG_COMMAND_TOTAL] = CONFIG_COMMAND_L
(
CONFIG_COMMAND_NAME(CFGCMD_INFO)

CONFIG_COMMAND_INTERNAL(false)
CONFIG_COMMAND_LOG_FILE(false)
CONFIG_COMMAND_LOG_LEVEL_DEFAULT(logLevelDebug)
CONFIG_COMMAND_LOG_LEVEL_STDERR_MAX(logLevelTrace)
Expand All @@ -153,6 +162,7 @@ static ConfigCommandData configCommandData[CFG_COMMAND_TOTAL] = CONFIG_COMMAND_L
(
CONFIG_COMMAND_NAME(CFGCMD_LOCAL)

CONFIG_COMMAND_INTERNAL(true)
CONFIG_COMMAND_LOG_FILE(true)
CONFIG_COMMAND_LOG_LEVEL_DEFAULT(logLevelInfo)
CONFIG_COMMAND_LOG_LEVEL_STDERR_MAX(logLevelError)
Expand All @@ -166,6 +176,7 @@ static ConfigCommandData configCommandData[CFG_COMMAND_TOTAL] = CONFIG_COMMAND_L
(
CONFIG_COMMAND_NAME(CFGCMD_LS)

CONFIG_COMMAND_INTERNAL(true)
CONFIG_COMMAND_LOG_FILE(false)
CONFIG_COMMAND_LOG_LEVEL_DEFAULT(logLevelDebug)
CONFIG_COMMAND_LOG_LEVEL_STDERR_MAX(logLevelTrace)
Expand All @@ -179,6 +190,7 @@ static ConfigCommandData configCommandData[CFG_COMMAND_TOTAL] = CONFIG_COMMAND_L
(
CONFIG_COMMAND_NAME(CFGCMD_REMOTE)

CONFIG_COMMAND_INTERNAL(true)
CONFIG_COMMAND_LOG_FILE(true)
CONFIG_COMMAND_LOG_LEVEL_DEFAULT(logLevelInfo)
CONFIG_COMMAND_LOG_LEVEL_STDERR_MAX(logLevelError)
Expand All @@ -192,6 +204,7 @@ static ConfigCommandData configCommandData[CFG_COMMAND_TOTAL] = CONFIG_COMMAND_L
(
CONFIG_COMMAND_NAME(CFGCMD_RESTORE)

CONFIG_COMMAND_INTERNAL(false)
CONFIG_COMMAND_LOG_FILE(true)
CONFIG_COMMAND_LOG_LEVEL_DEFAULT(logLevelInfo)
CONFIG_COMMAND_LOG_LEVEL_STDERR_MAX(logLevelTrace)
Expand All @@ -205,6 +218,7 @@ static ConfigCommandData configCommandData[CFG_COMMAND_TOTAL] = CONFIG_COMMAND_L
(
CONFIG_COMMAND_NAME(CFGCMD_STANZA_CREATE)

CONFIG_COMMAND_INTERNAL(false)
CONFIG_COMMAND_LOG_FILE(true)
CONFIG_COMMAND_LOG_LEVEL_DEFAULT(logLevelInfo)
CONFIG_COMMAND_LOG_LEVEL_STDERR_MAX(logLevelTrace)
Expand All @@ -218,6 +232,7 @@ static ConfigCommandData configCommandData[CFG_COMMAND_TOTAL] = CONFIG_COMMAND_L
(
CONFIG_COMMAND_NAME(CFGCMD_STANZA_DELETE)

CONFIG_COMMAND_INTERNAL(false)
CONFIG_COMMAND_LOG_FILE(true)
CONFIG_COMMAND_LOG_LEVEL_DEFAULT(logLevelInfo)
CONFIG_COMMAND_LOG_LEVEL_STDERR_MAX(logLevelTrace)
Expand All @@ -231,6 +246,7 @@ static ConfigCommandData configCommandData[CFG_COMMAND_TOTAL] = CONFIG_COMMAND_L
(
CONFIG_COMMAND_NAME(CFGCMD_STANZA_UPGRADE)

CONFIG_COMMAND_INTERNAL(false)
CONFIG_COMMAND_LOG_FILE(true)
CONFIG_COMMAND_LOG_LEVEL_DEFAULT(logLevelInfo)
CONFIG_COMMAND_LOG_LEVEL_STDERR_MAX(logLevelTrace)
Expand All @@ -244,6 +260,7 @@ static ConfigCommandData configCommandData[CFG_COMMAND_TOTAL] = CONFIG_COMMAND_L
(
CONFIG_COMMAND_NAME(CFGCMD_START)

CONFIG_COMMAND_INTERNAL(false)
CONFIG_COMMAND_LOG_FILE(true)
CONFIG_COMMAND_LOG_LEVEL_DEFAULT(logLevelInfo)
CONFIG_COMMAND_LOG_LEVEL_STDERR_MAX(logLevelTrace)
Expand All @@ -257,6 +274,7 @@ static ConfigCommandData configCommandData[CFG_COMMAND_TOTAL] = CONFIG_COMMAND_L
(
CONFIG_COMMAND_NAME(CFGCMD_STOP)

CONFIG_COMMAND_INTERNAL(false)
CONFIG_COMMAND_LOG_FILE(true)
CONFIG_COMMAND_LOG_LEVEL_DEFAULT(logLevelInfo)
CONFIG_COMMAND_LOG_LEVEL_STDERR_MAX(logLevelTrace)
Expand All @@ -270,6 +288,7 @@ static ConfigCommandData configCommandData[CFG_COMMAND_TOTAL] = CONFIG_COMMAND_L
(
CONFIG_COMMAND_NAME(CFGCMD_VERSION)

CONFIG_COMMAND_INTERNAL(false)
CONFIG_COMMAND_LOG_FILE(false)
CONFIG_COMMAND_LOG_LEVEL_DEFAULT(logLevelDebug)
CONFIG_COMMAND_LOG_LEVEL_STDERR_MAX(logLevelTrace)
Expand Down
18 changes: 18 additions & 0 deletions src/config/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ typedef struct ConfigCommandData
{
const char *name;

bool internal:1;
bool lockRequired:1;
bool lockRemoteRequired:1;
unsigned int lockType:2;
Expand All @@ -34,6 +35,8 @@ typedef struct ConfigCommandData
#define CONFIG_COMMAND(...) \
{__VA_ARGS__},

#define CONFIG_COMMAND_INTERNAL(internalParam) \
.internal = internalParam,
#define CONFIG_COMMAND_LOCK_REQUIRED(lockRequiredParam) \
.lockRequired = lockRequiredParam,
#define CONFIG_COMMAND_LOCK_REMOTE_REQUIRED(lockRemoteRequiredParam) \
Expand Down Expand Up @@ -328,6 +331,21 @@ cfgExeSet(const String *exeParam)
FUNCTION_TEST_RETURN_VOID();
}

/***********************************************************************************************************************************
Is this command internal-only?
***********************************************************************************************************************************/
bool
cfgCommandInternal(ConfigCommand commandId)
{
FUNCTION_TEST_BEGIN();
FUNCTION_TEST_PARAM(ENUM, commandId);
FUNCTION_TEST_END();

ASSERT(commandId < cfgCmdNone);

FUNCTION_TEST_RETURN(configCommandData[commandId].internal);
}

/***********************************************************************************************************************************
Does this command require an immediate lock?
***********************************************************************************************************************************/
Expand Down
1 change: 1 addition & 0 deletions src/config/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Command Functions
Access the current command and command parameters.
***********************************************************************************************************************************/
ConfigCommand cfgCommand(void);
bool cfgCommandInternal(ConfigCommand commandId);
const char *cfgCommandName(ConfigCommand commandId);

bool cfgLockRequired(void);
Expand Down
Loading

0 comments on commit 404284b

Please sign in to comment.