morph 0.1.0
Asynchronous bridge between GUI thread and business models
Loading...
Searching...
No Matches
args.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2#pragma once
3
4#include <expected>
5#include <optional>
6#include <string>
7#include <vector>
8
9/// @file
10/// @brief The generic client's command line: which source it opens and how it starts. Spec 4 §3.
11///
12/// Specified in `docs/spec/client/client.md`.
13
14namespace morph::client {
15
16/// @brief What the generic client reads from its command line.
17struct Args {
18 /// @brief `--server URL`: the server to fetch the screens from.
19 std::optional<std::string> server;
20 /// @brief `--app NAME`: the linked application to run in-process.
21 std::optional<std::string> app;
22 /// @brief `--db PATH`: the database a local application opens.
23 std::string db;
24 /// @brief `--user NAME`: the development principal a local application signs in.
25 std::string user;
26 /// @brief `--screen ID`: the screen mounted first; empty for the catalog's first.
27 std::string screen;
28 /// @brief `--exit-after-mount`: quit once the first screen mounted, with 0 when it mounted cleanly.
29 bool exitAfterMount = false;
30 /// @brief `--dev`, or `MORPH_UI_DEV=1`: development mode, which reloads the screens when the server's documents
31 /// change (spec 5 §12). A client built without the development tools ignores it.
32 bool dev = false;
33};
34
35/// @brief Reads the client's options from @p args and removes them, leaving the rest for the frontend.
36///
37/// Each value option is `--name value` or `--name=value`, and the last one given wins. `args[0]` is the program
38/// name, and nothing after a `--` is read.
39/// @param args The command line; what was read is removed.
40/// @return The options, or why they are refused: a value option without its value, or not exactly one of
41/// `--server` and `--app`. @p args is unchanged on a refusal.
42[[nodiscard]] std::expected<Args, std::string> readArgs(std::vector<std::string>& args);
43
44} // namespace morph::client
std::expected< Args, std::string > readArgs(std::vector< std::string > &args)
Reads the client's options from args and removes them, leaving the rest for the frontend.
What the generic client reads from its command line.
Definition args.hpp:17
std::string screen
--screen ID: the screen mounted first; empty for the catalog's first.
Definition args.hpp:27
bool exitAfterMount
--exit-after-mount: quit once the first screen mounted, with 0 when it mounted cleanly.
Definition args.hpp:29
std::optional< std::string > app
--app NAME: the linked application to run in-process.
Definition args.hpp:21
std::string user
--user NAME: the development principal a local application signs in.
Definition args.hpp:25
std::string db
--db PATH: the database a local application opens.
Definition args.hpp:23
std::optional< std::string > server
--server URL: the server to fetch the screens from.
Definition args.hpp:19
bool dev
--dev, or MORPH_UI_DEV=1: development mode, which reloads the screens when the server's documents cha...
Definition args.hpp:32