Check-in [46008704a6]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:add FCLI_RC_NO_CMD result code for fcli_dispatch_commands()

To help distinguish between invalid commands and propagated FSL_RC_NOT_FOUND errors returned from successfully dispatched commands.

ok stephan@

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 46008704a620cc770bce96cc4313b0bf96498390
User & Date: mark 2022-11-24 13:51:38
Context
2023-01-24
03:09
Update fsl__search_doc_touch() to be able to handle both FTS4 and FTS5 search indexes, now that the port to FTS5 has started at fossil:/timeline?r=search-fts5. This failure was found by trying to make the first checkin on that branch. check-in: 5764b7efa6 user: stephan tags: trunk
2022-11-24
13:51
add FCLI_RC_NO_CMD result code for fcli_dispatch_commands()

To help distinguish between invalid commands and propagated FSL_RC_NOT_FOUND errors returned from successfully dispatched commands.

ok stephan@ check-in: 46008704a6 user: mark tags: trunk

13:49
make fcli_cmd_aliascmp() return semantics match convention

Return 0 if a match is found as one would expect from a *_cmp() routine.

ok stephan@ check-in: 6e0d1fbc09 user: mark tags: trunk

Changes
Unified Diff Ignore Whitespace Patch
Changes to include/fossil-scm/cli.h.
94
95
96
97
98
99
100





101
102
103
104
105
106
107
*/
enum fcli_rc_e {
/**
   For use with fcli_flag_callback_f() implementations to indicate
   that the flag processor should check for that flag again.
*/
FCLI_RC_FLAG_AGAIN = FSL_RC_end + 1,





/**
   Returned from fcli_setup() if flag processing invokes the help
   system. This is an indication that the app should exit immediately
   with a 0 result code.
*/
FCLI_RC_HELP
};







>
>
>
>
>







94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
*/
enum fcli_rc_e {
/**
   For use with fcli_flag_callback_f() implementations to indicate
   that the flag processor should check for that flag again.
*/
FCLI_RC_FLAG_AGAIN = FSL_RC_end + 1,
/**
   Returned from fcli_dispatch_commands() when the string returned
   from fcli_next_arg() does not match any fcli_command in the list.
*/
FCLI_RC_NO_CMD,
/**
   Returned from fcli_setup() if flag processing invokes the help
   system. This is an indication that the app should exit immediately
   with a 0 result code.
*/
FCLI_RC_HELP
};
825
826
827
828
829
830
831
832
833
834
835
836




837
838
839
840
841
842
843
};

/**
   Expects an array of fcli_commands which contain a trailing
   sentry entry with a NULL name and callback. It searches the list
   for a command matching fcli_next_arg(). If found, it
   removes that argument from the list, calls the callback, and
   returns its result. If no command is found FSL_RC_NOT_FOUND is
   returned, the argument list is not modified, and the error state
   is updated with a description of the problem and a list of all
   command names in cmdList.





   If reportErrors is true then on error this function outputs
   the error result but it keeps the error state in place
   for the downstream use.

   As a special case: when a command matches the first argument and
   that object has a non-NULL flags member, this function checks the
   _next_ argument, and if it is "help" then this function passes







|




>
>
>
>







830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
};

/**
   Expects an array of fcli_commands which contain a trailing
   sentry entry with a NULL name and callback. It searches the list
   for a command matching fcli_next_arg(). If found, it
   removes that argument from the list, calls the callback, and
   returns its result. If no command is found FCLI_RC_NO_CMD is
   returned, the argument list is not modified, and the error state
   is updated with a description of the problem and a list of all
   command names in cmdList.

   The distinct FCLI return code aims to help clients distinguish
   between fcli_dispatch_commands() failure and failures propagated
   by successfully dispatched fcli_command fcli_command_f callbacks.

   If reportErrors is true then on error this function outputs
   the error result but it keeps the error state in place
   for the downstream use.

   As a special case: when a command matches the first argument and
   that object has a non-NULL flags member, this function checks the
   _next_ argument, and if it is "help" then this function passes
Changes to src/cli.c.
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
  }else if(!cmd->name){
    fsl_buffer msg = fsl_buffer_empty;
    int rc2;
    if(!arg){
      rc2 = FSL_RC_MISUSE;
      fsl_buffer_appendf(&msg, "No command provided.");
    }else{
      rc2 = FSL_RC_NOT_FOUND;
      fsl_buffer_appendf(&msg, "Command not found: %s.",arg);
    }
    fsl_buffer_appendf(&msg, " Available commands: ");
    cmd = orig;
    for( ; cmd && cmd->name; ++cmd ){
      fsl_buffer_appendf( &msg, "%s%s",
                          (cmd==orig) ? "" : ", ",







|







995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
  }else if(!cmd->name){
    fsl_buffer msg = fsl_buffer_empty;
    int rc2;
    if(!arg){
      rc2 = FSL_RC_MISUSE;
      fsl_buffer_appendf(&msg, "No command provided.");
    }else{
      rc2 = FCLI_RC_NO_CMD;
      fsl_buffer_appendf(&msg, "Command not found: %s.",arg);
    }
    fsl_buffer_appendf(&msg, " Available commands: ");
    cmd = orig;
    for( ; cmd && cmd->name; ++cmd ){
      fsl_buffer_appendf( &msg, "%s%s",
                          (cmd==orig) ? "" : ", ",