127 lines
4.3 KiB
C
127 lines
4.3 KiB
C
/*
|
|
* cli.h — command-line flag parsing for sovereign_browser
|
|
*
|
|
* Parses argv before gtk_init() so GTK doesn't abort on our flags.
|
|
* Recognized flags are stripped from argv/argc so gtk_init() only sees
|
|
* positional URLs. CLI flags override settings.conf for this run only
|
|
* (nothing is written to disk).
|
|
*
|
|
* Login flags build a cJSON params object and call agent_login(),
|
|
* reusing the same code path as the MCP 'login' tool. On success the
|
|
* GTK login dialog is skipped entirely.
|
|
*/
|
|
|
|
#ifndef CLI_H
|
|
#define CLI_H
|
|
|
|
#include <glib.h>
|
|
#include <stdio.h> /* FILE */
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/* Tri-state for boolean overrides. */
|
|
typedef enum {
|
|
CLI_TRISTATE_UNSET = 0,
|
|
CLI_TRISTATE_TRUE,
|
|
CLI_TRISTATE_FALSE
|
|
} cli_tristate_t;
|
|
|
|
/* Parsed command-line arguments. Zero-initialized by cli_parse().
|
|
* Strings are heap-allocated and owned by the cli_args_t — free with
|
|
* cli_args_free(). */
|
|
typedef struct {
|
|
/* Startup URLs: --url flags + positional args, in order. */
|
|
char **urls;
|
|
int url_count;
|
|
|
|
/* Browser overrides (NULL / 0 = not set). */
|
|
char *new_tab_url; /* --new-tab-url */
|
|
int max_tabs; /* --max-tabs (0 = unset) */
|
|
cli_tristate_t session_restore; /* --session-restore / --no-session-restore */
|
|
|
|
/* Agent server overrides. */
|
|
int agent_port; /* --port (0 = unset) */
|
|
cli_tristate_t agent_enabled; /* --agent / --no-agent */
|
|
char **agent_origins; /* --agent-origin (repeatable) */
|
|
int agent_origin_count;
|
|
|
|
/* Login. login_method == NULL means "show GTK dialog".
|
|
* no_login == TRUE means skip login entirely (browse without identity). */
|
|
gboolean no_login; /* --no-login */
|
|
char *login_method; /* --login-method */
|
|
char *nsec; /* --nsec */
|
|
char *privkey; /* --privkey */
|
|
char *mnemonic; /* --mnemonic */
|
|
int account; /* --account (-1 = unset, defaults to 0) */
|
|
char *npub; /* --npub */
|
|
char *pubkey; /* --pubkey */
|
|
char *bunker; /* --bunker */
|
|
char *nsigner_transport; /* --nsigner-transport */
|
|
char *nsigner_device; /* --nsigner-device */
|
|
char *nsigner_service; /* --nsigner-service */
|
|
int nsigner_index; /* --nsigner-index (-1 = unset) */
|
|
int login_timeout_ms; /* --login-timeout (0 = unset) */
|
|
|
|
/* Diagnostics. */
|
|
int verbose; /* --verbose / -v (repeatable count) */
|
|
gboolean quiet; /* --quiet / -q */
|
|
|
|
/* Offline site download (test/diagnostic hook — triggers
|
|
* site_downloader_start shortly after startup). */
|
|
char *download_url; /* --download-url <url> */
|
|
|
|
/* Exit-request flags set by --help / --version. */
|
|
gboolean want_help;
|
|
gboolean want_version;
|
|
} cli_args_t;
|
|
|
|
/*
|
|
* Parse command-line arguments.
|
|
*
|
|
* On entry, *argc / *argv are the raw values from main(). On return,
|
|
* recognized flags are removed from *argv / *argc (repacked via
|
|
* getopt_long's optind) so the remaining vector is safe to pass to
|
|
* gtk_init(). Positional URL arguments are preserved.
|
|
*
|
|
* Returns:
|
|
* 0 — parse OK (or --help / --version requested; check args.want_*).
|
|
* -1 — parse error (message printed to stderr).
|
|
*
|
|
* On error or when want_help/want_version is true, the caller should
|
|
* exit without calling gtk_init().
|
|
*/
|
|
int cli_parse(int *argc, char ***argv, cli_args_t *out);
|
|
|
|
/*
|
|
* Free heap-allocated fields in a cli_args_t. Safe to call on a
|
|
* zero-initialized struct.
|
|
*/
|
|
void cli_args_free(cli_args_t *args);
|
|
|
|
/*
|
|
* Print usage text to the given stream.
|
|
*/
|
|
void cli_print_usage(FILE *fp);
|
|
|
|
/*
|
|
* Perform CLI login by building a cJSON params object from args and
|
|
* calling agent_login(). Requires nostr_init() to have been called
|
|
* already (agent_login() handles re-init internally).
|
|
*
|
|
* Returns:
|
|
* 0 — login succeeded (global app state is now set).
|
|
* -1 — login failed (error message printed to stderr).
|
|
*
|
|
* If args->no_save_identity is FALSE, the identity is persisted to
|
|
* ~/.sovereign_browser/identity.json via key_store_save() on success.
|
|
*/
|
|
int cli_login(const cli_args_t *args);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* CLI_H */
|