3#if !defined(_ORG_FOSSIL_SCM_FCLI_H_INCLUDED_)
4#define _ORG_FOSSIL_SCM_FCLI_H_INCLUDED_
70#define FCLI_VN(N,pfexp) \
71 if(fcli.config.verbose>=(N)) do { \
72 fcli_printf("VERBOSE %d: ", (int)(N)); \
79#define FCLI_V2(pfexp) FCLI_VN(2,pfexp)
86#define FCLI_V(pfexp) FCLI_VN(1,pfexp)
88#if defined(__cplusplus)
254#define fcli_cliflag_empty_m {\
256 FCLI_FLAG_TYPE_INVALID,\
294#define FCLI_FLAG_BOOL(S,L,TGT,HELP) \
295 {S,L,FCLI_FLAG_TYPE_BOOL,TGT,NULL,NULL,HELP}
297#define FCLI_FLAG_BOOL_INVERT(S,L,TGT,HELP) \
298 {S,L,FCLI_FLAG_TYPE_BOOL_INVERT,TGT,NULL,NULL,HELP}
300#define FCLI_FLAG_BOOL_X(S,L,TGT,CALLBACK,HELP) \
301 {S,L,FCLI_FLAG_TYPE_BOOL,TGT,NULL,CALLBACK,HELP}
303#define FCLI_FLAG_BOOL_INVERT_X(S,L,TGT,CALLBACK,HELP) \
304 {S,L,FCLI_FLAG_TYPE_BOOL_INVERT,TGT,NULL,CALLBACK,HELP}
306#define FCLI_FLAG_CSTR(S,L,LBL,TGT,HELP) \
307 {S,L,FCLI_FLAG_TYPE_CSTR,TGT,LBL,NULL,HELP}
308#define FCLI_FLAG FCLI_FLAG_CSTR
310#define FCLI_FLAG_CSTR_X(S,L,LBL,TGT,CALLBACK,HELP) \
311 {S,L,FCLI_FLAG_TYPE_CSTR,TGT,LBL,CALLBACK,HELP}
312#define FCLI_FLAG_X FCLI_FLAG_CSTR_X
314#define FCLI_FLAG_I32(S,L,LBL,TGT,HELP) \
315 {S,L,FCLI_FLAG_TYPE_INT32,TGT,LBL,NULL,HELP}
317#define FCLI_FLAG_I32_X(S,L,LBL,TGT,CALLBACK,HELP) \
318 {S,L,FCLI_FLAG_TYPE_INT32,TGT,LBL,CALLBACK,HELP}
320#define FCLI_FLAG_I64(S,L,LBL,TGT,HELP) \
321 {S,L,FCLI_FLAG_TYPE_INT64,TGT,LBL,NULL,HELP}
323#define FCLI_FLAG_I64_X(S,L,LBL,TGT,CALLBACK,HELP) \
324 {S,L,FCLI_FLAG_TYPE_INT64,TGT,LBL,CALLBACK,HELP}
326#define FCLI_FLAG_ID(S,L,LBL,TGT,HELP) \
327 {S,L,FCLI_FLAG_TYPE_ID,TGT,LBL,NULL,HELP}
329#define FCLI_FLAG_ID_X(S,L,LBL,TGT,CALLBACK,HELP) \
330 {S,L,FCLI_FLAG_TYPE_ID,TGT,LBL,CALLBACK,HELP}
332#define FCLI_FLAG_DBL(S,L,LBL,TGT,HELP) \
333 {S,L,FCLI_FLAG_TYPE_DOUBLE,TGT,LBL,NULL,HELP}
335#define FCLI_FLAG_DBL_X(S,L,LBL,TGT,CALLBACK,HELP) \
336 {S,L,FCLI_FLAG_TYPE_DOUBLE,TGT,LBL,CALLBACK,HELP}
657 __attribute__ ((__format__ (__printf__, 1, 2)))
664#define f_out fcli_printf
718 const char ** value);
736 const char ** value);
789#define fcli_err_report(CLEAR) fcli_err_report2((CLEAR), __FILE__, __LINE__)
1094 bool changedFilesOnly);
1252#if defined(__cplusplus)
FSL_EXPORT void fcli_printf(char const *fmt,...)
Works like printf() but sends its output to fsl_outputf() using the fcli.f fossil conext (if set) or ...
FSL_EXPORT const char * fcli_next_arg(bool remove)
Peeks at or takes the next argument from the CLI args.
int(* fcli_command_f)(fcli_command const *)
Typedef for general-purpose fcli call-by-name commands.
fcli_sync_e
Flags for use with fcli_sync().
@ FCLI_SYNC_AUTO
Only perform one of the request operations if the fossil config setting "fcli.autosync" or "autosync"...
@ FCLI_SYNC_NO_OUTPUT
Works like FCLI_SYNC_NO_STDOUT, but also suppresses stderr.
@ FCLI_SYNC_FULLAUTO
Perform a full sync, but only if autosync is enabled.
@ FCLI_SYNC_PUSH
Perform a push (write-only) sync.
@ FCLI_SYNC_PULL
Perform a pull (read-only) sync.
@ FCLI_SYNC_NO_STDOUT
Redirect all stdout output from the fsl_system() to /dev/null.
@ FCLI_SYNC_FULL
Perform a full sync.
FSL_EXPORT fcli_t fcli
This fcli_t instance is intended to act as a singleton.
FSL_EXPORT bool fcli_flag_or_arg(char const *opt1, char const *opt2, const char **value)
Works similarly to fcli_flag2(), but if no flag is found and value is not NULL then *value is assigne...
FSL_EXPORT void fcli_command_help(fcli_command const *cmd, bool showUsage, bool onlyOne)
Requires that cmd be an array of fcli_command objects with a trailing entry which has a NULL name.
FSL_EXPORT void fcli_diff_colors(fsl_dibu_opt *const tgt, fcli_diff_colors_e theme)
Populates the given fsl_dibu_opt::ansiColors state with values dependend on the second argument.
FSL_EXPORT int fcli_setup_v2(int argc, char const *const *argv, fcli_cliflag const *const cliFlags, fcli_help_info const *const helpInfo)
Initializes fcli's state and CLI flags processing.
FSL_EXPORT int fcli_err_set(int code, char const *fmt,...)
Sets fcli.f's error state, analog to fsl_cx_err_set().
FSL_EXPORT char const * fcli_progname(void)
Returns the "tail" part of the argv[0] string which was passed to fcli_setup(), or NULL if neither of...
FSL_EXPORT void fcli_dump_stmt_cache(bool forceVerbose)
FSL_EXPORT int fcli_has_unused_args(bool outputError)
If fcli.argv contains any entries, returns FSL_RC_MISUSE and updates the error state with a message a...
FSL_EXPORT int fcli_dispatch_commands(fcli_command const *cmdList, bool reportErrors)
Expects an array of fcli_commands which contain a trailing sentry entry with a NULL name and callback...
FSL_EXPORT int fcli_err_report2(bool clear, char const *file, int line)
If fcli has any error state, this outputs it and returns the error code, else returns 0.
fcli_rc_e
Result codes specific to the fcli API.
@ FCLI_RC_NO_CMD
Returned from fcli_dispatch_commands() when the string returned from fcli_next_arg() does not match a...
@ FCLI_RC_HELP
Returned from fcli_setup() if flag processing invokes the help system.
@ FCLI_RC_FLAG_AGAIN
For use with fcli_flag_callback_f() implementations to indicate that the flag processor should check ...
FSL_EXPORT void fcli_help_show_aliases(char const *aliases)
Pretty print fcli_command->aliases like: " (aliases: cmd, com)".
FSL_EXPORT int fcli_end_of_main(int mainRc)
A minor helper function intended to be passed the pending result code of the main() routine.
FSL_EXPORT fsl_error * fcli_error(void)
Returns the internally-used fsl_error instance which is used for propagating errors.
FSL_EXPORT int fcli_sync(int ops)
Uses fcli_fossil_binary() to find the fossil(1) binary and run a sync operation, optionally either or...
FSL_EXPORT void fcli_err_reset(void)
Clears any error state in fcli.f.
FSL_EXPORT int fcli_fingerprint_check(bool reportImmediately)
Performs a "fingerprint check" on the current checkout/repo combination, as per fsl_ckout_fingerprint...
FSL_EXPORT void * fcli_fax(void *mem)
If mem is not NULL, this routine appends mem to a list of pointers which will be passed to fsl_free()...
FSL_EXPORT bool fcli_flag(char const *opt, const char **value)
Searches fcli.argv for the given flag (pass it without leading dashes).
fcli_cliflag_type_e
Types for use with the fcli_cliflag::flagType field.
@ FCLI_FLAG_TYPE_INVALID
Sentinel placeholder.
@ FCLI_FLAG_TYPE_BOOL_INVERT
Represents bool, but gets set to false if the flag is set.
@ FCLI_FLAG_TYPE_INT32
Represents int32_t.
@ FCLI_FLAG_TYPE_ID
Represents fsl_id_t, which might be either int32_t or int64_t.
@ FCLI_FLAG_TYPE_CSTR
Represents (char const *).
@ FCLI_FLAG_TYPE_BOOL
Represents bool.
@ FCLI_FLAG_TYPE_INT64
Represents int64_t.
@ FCLI_FLAG_TYPE_DOUBLE
Represents double.
FSL_EXPORT fsl_db * fcli_db_ckout(void)
If fcli has an opened checkout, that db handle is returned, else NULL is returned.
FSL_EXPORT fsl_db * fcli_needs_ckout(void)
If fcli has an opened checkout, that db handle is returned, else NULL is returned and fcli's error st...
FSL_EXPORT int fsl_msg_f_fcli(fsl_msg const *msg, void *state)
A fsl_msg_f() implementation intended for use with CLI apps.
FSL_EXPORT int fcli_cmd_aliascmp(fcli_command const *cmd, char const *arg)
Parse cmd->aliases for an alias (i.e., NUL-terminated string semantically equivalent to cmd->name) ma...
int(* fcli_flag_callback_f)(fcli_cliflag const *)
Callback handler for CLI flag handling.
FSL_EXPORT char const * fcli_fossil_binary(bool errIfNotFound, int reportPolicy)
Searches the $PATH for a binary named fossil or fossil.exe.
FSL_EXPORT unsigned short fcli_is_verbose(void)
Returns the verbosity level set via CLI args.
FSL_EXPORT int fcli_ckout_show_info(bool useUtc)
If fcli has a checkout opened, this dumps various info about it to its output channel.
FSL_EXPORT fsl_cx * fcli_cx(void)
Returns the libfossil context associated with the fcli API.
FSL_EXPORT void fcli_dump_cache_metrics(void)
FSL_EXPORT bool fcli_flag2(char const *opt1, char const *opt2, const char **value)
Works like fcli_flag() but tries two argument forms, in order.
FSL_EXPORT int fcli_args_to_vfile_ids(fsl_id_bag *const tgt, fsl_id_t vid, bool relativeToCwd, bool changedFilesOnly)
Processes all remaining CLI arguments as potential file or directory names, collects their vfile....
fcli_diff_colors_e
Color theme IDs for use with fcli_diff_colors.
@ FCLI_DIFF_COLORS_NONE
Tells fcli_diff_colors() to NULL out the ANSI color state of its target object.
@ FCLI_DIFF_COLORS_RG
Basic red (deletion) and green (insertion) diff colors.
@ FCLI_DIFF_COLORS_DEFAULT
FSL_EXPORT int fcli_process_flags(fcli_cliflag const *defs)
Requires an array of fcli_cliflag objects terminated with an instance with NULL values for the (flagS...
FSL_EXPORT fsl_db * fcli_needs_repo(void)
If fcli has an opened repository, that db handle is returned, else NULL is returned and fcli's error ...
FSL_EXPORT void fcli_list_ambiguous_artifacts(char const *label, char const *prefix)
Given a hash prefix, lists (via f_out()) all blob table entries which have this prefix.
FSL_EXPORT const fcli_cliflag fcli_cliflag_empty
Non-const-copyable counterpart of fcli_cliflag_empty_m.
FSL_EXPORT fsl_db * fcli_db_repo(void)
If fcli has an opened repository, that db handle is returned, else NULL is returned.
FSL_EXPORT void fcli_pre_setup(void)
The first time this is called, it swaps out libfossil's default allocator with a fail-fast one which ...
FSL_EXPORT int fcli_has_unused_flags(bool outputError)
If fcli.argv contains what looks like any flag arguments, this updates the fossil error state and ret...
FSL_EXPORT void fcli_cliflag_help(fcli_cliflag const *defs)
Requires an array of fcli_cliflag objects as described for fcli_process_flags().
int32_t fsl_id_t
fsl_id_t is a signed integer type used to store database record IDs.
This file declares the core SCM-related public APIs.
fsl_see_keytype_e
SQLite Encryption Extension (SEE) key types for use with fsl_see_key_f().
Models a single CLI flag.
fcli_flag_callback_f callback
Optional callback which gets passed the flag, if it is set, after fcli has assigned the flagValue ent...
enum fcli_cliflag_type_e flagType
Specifies how to interpret the data pointed to by this->flagValue.
void * flagValue
If not NULL, the member is the target of the flag's value.
const char * flagLong
"Long-form" for this flag, noting that there's no restriction on its length.
const char * flagValueLabel
Optional descriptive label to be used when rendering help text:
const char * flagShort
"Short-form" for this flag, noting that there's no restriction on its length.
const char * helpText
Help text for the flag.
Describes a named callback command.
fcli_command_f f
The callback for this command.
void(* usage)(void)
Optional usage callback for this command.
char const * briefDescription
Brief description, for use in generating help text.
char const * name
The name of the command.
fcli_cliflag const * flags
Must be NULL or an array compatible with fcli_process_flags().
char const * aliases
NUL-delimited string containing optional aliases of the above command name.
Structure for holding app-level –help info.
void(* callback)(void)
If not 0 then this is called after outputing any flags' help.
char const * briefDescription
Brief description of what the app does.
char const * briefUsage
Brief usage text.
The fcli_t type, accessed by clients via the fcli global instance, contains various data for managing...
fsl_msg_listener listener
Listener for fsl_msg-published messages.
fsl_pathfinder bins
Search object for binaries.
struct fcli_t::@202107064176066125066352360350102245112274252274 config
The flags in this struct are "public," meaning that client applications may query and safely manipula...
enum fsl_see_keytype_e type
Key type.
int traceSql
Whether or not to enable fossil's SQL tracing.
unsigned int nKey
Key len.
char const * checkoutDir
If not NULL then fcli_setup() will attempt to open the checkout for the given dir,...
const fcli_cliflag * cliFlags
May be set to an array of CLI flag objects, which fcli_setup() will use for parsing the CLI flags.
struct fcli_t::@266037043025206162025002275223140110232154337054 see
const char * userArg
User name from the –user CLI flag.
char const * appName
Application's name.
char ** argv
The current list of CLI arguments.
short helpRequested
Incremented if fcli_setup() detects -?
fcli_help_info const * appHelp
If not NULL, it must be a pointer to fcli_help_info holding help info for the app.
const char * key
Key passed to the –see-key CLI flag.
struct fcli_t::@223255154203053366060260163120160074261145270143 paths
Search paths.
struct fcli_t::@325172015216067022331121211371252330115153125361 transient
Transient settings and flags.
fsl_outputer outputer
This output channel is used when initializing the context object.
int argc
Current number of items in this->argv.
unsigned short verbose
A verbosity level counter.
bool versionRequested
True if the –lib-version CLI flag was used.
fsl_error err
For holding pre-this->f-init error state.
const char * repoDbArg
repo db name string from -R/–repo CLI flag.
fsl_cx * f
The shared fsl_cx instance.
The main Fossil "context" type.
An instance of this class is used to convey certain state to fsl_dibu objects.
A container for storing generic error state.
A container type for lists of db record IDs.
Client callback info for receiving various events during fossil sync processing.
A message object type for use with fsl_sc::status().
An interface which encapsulates data for managing an output destination, primarily intended for use w...
The "Path Finder" class is a utility class for searching the filesystem for files matching a set of c...