FlatImage
A configurable Linux containerization system
Loading...
Searching...
No Matches
help.hpp
Go to the documentation of this file.
1
8
9#pragma once
10
11#include <string>
12#include <vector>
13#include <algorithm>
14
23
32namespace ns_cmd::ns_help
33{
34
35class HelpEntry
36{
37 private:
38 std::string m_msg;
39 std::string m_name;
40 public:
41 HelpEntry(std::string const& name)
42 : m_msg("Flatimage - Portable Linux Applications\n")
43 , m_name(name)
44 {};
45 HelpEntry& with_usage(std::string_view usage)
46 {
47 m_msg.append("Usage: ").append(usage).append("\n");
48 return *this;
49 }
50 HelpEntry& with_example(std::string_view example)
51 {
52 m_msg.append("Example: ").append(example).append("\n");
53 return *this;
54 }
55 HelpEntry& with_note(std::string_view note)
56 {
57 m_msg.append("Note: ").append(note).append("\n");
58 return *this;
59 }
60 HelpEntry& with_description(std::string_view description)
61 {
62 m_msg.append(m_name).append(" : ").append(description).append("\n");
63 return *this;
64 }
65 HelpEntry& with_args(std::vector<std::pair<std::string,std::string>> args)
66 {
67 std::ranges::for_each(args, [&](auto&& e)
68 {
69 m_msg += std::string{" <"} + e.first + "> : " + e.second + '\n';
70 });
71 return *this;
72 }
73 std::string get()
74 {
75 return m_msg;
76 }
77};
78
79inline std::string help_usage()
80{
81 return HelpEntry{"fim-help"}
82 .with_description("See usage details for specified command")
83 .with_usage("fim-help <cmd>")
84 .with_args({
85 { "cmd", "Name of the command to display help details" },
86 })
87 .with_note("Available commands: fim-{bind,boot,casefold,desktop,env,exec,instance,layer,notify,overlay,perms,recipe,remote,root,unshare,version}")
88 .with_example(R"(fim-help bind)")
89 .get();
90}
91
92inline std::string bind_usage()
93{
94 return HelpEntry{"fim-bind"}
95 .with_description("Bind paths from the host to inside the container")
96 .with_usage("fim-bind <add> <type> <src> <dst>")
97 .with_args({
98 { "add", "Create a novel binding of type <type> from <src> to <dst>" },
99 { "type", "ro, rw, dev" },
100 { "src" , "A file, directory, or device" },
101 { "dst" , "A file, directory, or device" },
102 })
103 .with_usage("fim-bind <del> <index>")
104 .with_args({
105 { "del", "Deletes a binding with the specified index" },
106 { "index" , "Index of the binding to erase" },
107 })
108 .with_usage("fim-bind <list>")
109 .with_args({
110 { "list", "Lists current bindings"}
111 })
112 .get();
113}
114
115inline std::string boot_usage()
116{
117 return HelpEntry{"fim-boot"}
118 .with_description("Configure the default startup command")
119 .with_usage("fim-boot <set> <command> [args...]")
120 .with_args({
121 { "set", "Execute <command> with optional [args] when FlatImage is launched" },
122 { "command" , "Startup command" },
123 { "args..." , "Arguments for the startup command" },
124 })
125 .with_example(R"(fim-boot set echo test)")
126 .with_usage("fim-boot <show|clear>")
127 .with_args({
128 { "show" , "Displays the current startup command" },
129 { "clear" , "Clears the set startup command" },
130 })
131 .get();
132}
133
134inline std::string casefold_usage()
135{
136 return HelpEntry{"fim-casefold"}
137 .with_description("Enables casefold for the filesystem (ignore case)")
138 .with_usage("fim-casefold <on|off>")
139 .with_args({
140 { "on", "Enables casefold" },
141 { "off", "Disables casefold" },
142 })
143 .get();
144}
145
146inline std::string desktop_usage()
147{
148 return HelpEntry{"fim-desktop"}
149 .with_description("Configure the desktop integration")
150 .with_usage("fim-desktop <setup> <json-file>")
151 .with_args({
152 { "setup", "Sets up the desktop integration with an input json file" },
153 { "json-file", "Path to the json file with the desktop configuration"},
154 })
155 .with_usage("fim-desktop <enable> [entry,mimetype,icon,none]")
156 .with_args({
157 { "enable", "Enables the desktop integration selectively" },
158 { "entry", "Enables the start menu desktop entry"},
159 { "mimetype", "Enables the mimetype"},
160 { "icon", "Enables the icon for the file manager and desktop entry"},
161 { "none", "Disables desktop integrations"},
162 })
163 .with_usage("fim-desktop <clean>")
164 .with_args({
165 { "clean", "Cleans the desktop integration files from XDG_DATA_HOME" },
166 })
167 .with_usage("fim-desktop <dump> <icon> <file>")
168 .with_args({
169 { "dump", "Dumps the selected integration data" },
170 { "icon", "Dumps the desktop icon to a file" },
171 { "file", "Path to the icon file, the extension is appended automatically if not specified" },
172 })
173 .with_usage("fim-desktop <dump> <entry|mimetype>")
174 .with_args({
175 { "dump", "Dumps the selected integration data" },
176 { "entry", "The desktop entry of the application" },
177 { "mimetype", "The mime type of the application" },
178 })
179 .get();
180}
181
182inline std::string env_usage()
183{
184 return HelpEntry{"fim-env"}
185 .with_description("Define environment variables in FlatImage")
186 .with_usage("fim-env <add|set> <'key=value'...>")
187 .with_args({
188 { "add", "Include a novel environment variable" },
189 { "set", "Redefines the environment variables as the input arguments" },
190 { "'key=value'...", "List of variables to add or set" },
191 })
192 .with_example("fim-env add 'APP_NAME=hello-world' 'HOME=/home/my-app'")
193 .with_usage("fim-env <del> <keys...>")
194 .with_args({
195 { "del", "Delete one or more environment variables" },
196 { "keys...", "List of variable names to delete" },
197 })
198 .with_example("fim-env del APP_NAME HOME")
199 .with_usage("fim-env <list>")
200 .with_args({
201 { "list", "Lists configured environment variables" },
202 })
203 .with_usage("fim-env <clear>")
204 .with_args({
205 { "clear", "Clears configured environment variables" },
206 })
207 .get();
208}
209
210inline std::string exec_usage()
211{
212 return HelpEntry{"fim-exec"}
213 .with_description("Executes a command as a regular user")
214 .with_usage("fim-exec <program> [args...]")
215 .with_args({
216 { "program", "Name of the program to execute, it can be the name of a binary or the full path" },
217 { "args...", "Arguments for the executed program" },
218 })
219 .with_example(R"(fim-exec echo -e "hello\nworld")")
220 .get();
221}
222
223inline std::string instance_usage()
224{
225 return HelpEntry{"fim-instance"}
226 .with_description("Manage running instances")
227 .with_usage("fim-instance <exec> <id> [args...]")
228 .with_args({
229 { "exec", "Run a command in a running instance" },
230 { "id" , "ID of the instance in which to execute the command" },
231 { "args" , "Arguments for the 'exec' command" },
232 })
233 .with_example("fim-instance exec 0 echo hello")
234 .with_usage("fim-instance <list>")
235 .with_args({
236 { "list", "Lists current instances" },
237 })
238 .get();
239}
240
241inline std::string layer_usage()
242{
243 return HelpEntry{"fim-layer"}
244 .with_description("Manage the layers of the current FlatImage")
245 .with_usage("fim-layer <create> <in-dir> <out-file>")
246 .with_args({
247 { "create", "Creates a novel layer from <in-dir> and save in <out-file>" },
248 { "in-dir", "Input directory to create a novel layer from"},
249 { "out-file" , "Output file name of the layer file"},
250 })
251 .with_usage("fim-layer <add> <in-file>")
252 .with_args({
253 { "add", "Includes the novel layer <in-file> in the image in the top of the layer stack" },
254 { "in-file", "Path to the layer file to include in the FlatImage"},
255 })
256 .with_usage("fim-layer <commit> <binary|layer|file> [path]")
257 .with_args({
258 { "commit", "Compresses current changes into a layer" },
259 { "binary", "Appends the layer to the FlatImage binary" },
260 { "layer", "Saves the layer to $FIM_DIR_DATA/layers with auto-increment naming" },
261 { "file", "Saves the layer to the specified file path" },
262 { "path", "File path (required when using 'file' mode)" },
263 })
264 .with_usage("fim-layer <list>")
265 .with_args({
266 { "list", "Lists all embedded and external layers in the format index:offset:size:path" },
267 })
268 .get();
269}
270
271inline std::string notify_usage()
272{
273 return HelpEntry{"fim-notify"}
274 .with_description("Notify with 'notify-send' when the program starts")
275 .with_usage("fim-notify <on|off>")
276 .with_args({
277 { "on", "Turns on notify-send to signal the application start" },
278 { "off", "Turns off notify-send to signal the application start" },
279 })
280 .get();
281}
282
283inline std::string overlay_usage()
284{
285 return HelpEntry{"fim-overlay"}
286 .with_description("Show or select the default overlay filesystem")
287 .with_usage("fim-overlay <set> <overlayfs|unionfs|bwrap>")
288 .with_args({
289 { "set", "Sets the default overlay filesystem to use" },
290 { "overlayfs", "Uses 'fuse-overlayfs' as the overlay filesystem" },
291 { "unionfs", "Uses 'unionfs-fuse' as the overlay filesystem" },
292 { "bwrap", "Uses 'bubblewrap' native overlay options as the overlay filesystem" },
293 })
294 .with_usage("fim-overlay <show>")
295 .with_args({
296 { "show", "Shows the current overlay filesystem" },
297 })
298 .get();
299}
300
301inline std::string perms_usage()
302{
303 return HelpEntry{"fim-perms"}
304 .with_description("Edit current permissions for the flatimage")
305 .with_note("Permissions: all,audio,dbus_system,dbus_user,dev,gpu,home,input,media,network,optical,shm,udev,usb,wayland,xorg")
306 .with_usage("fim-perms <add|del|set> <perms...>")
307 .with_args({
308 { "add", "Allow one or more permissions" },
309 { "del", "Delete one or more permissions" },
310 { "set", "Replace all permissions with the specified set" },
311 { "perms...", "One or more permissions" },
312 })
313 .with_example("fim-perms add home,network,gpu")
314 .with_example("fim-perms set wayland,audio,network")
315 .with_note("The 'all' permission sets all available permissions and cannot be combined with other permissions")
316 .with_usage("fim-perms <list|clear>")
317 .with_args({
318 { "list", "Lists the current permissions" },
319 { "clear", "Clears all permissions" },
320 })
321 .get();
322}
323
324inline std::string remote_usage()
325{
326 return HelpEntry{"fim-remote"}
327 .with_description("Configure the remote URL for recipes")
328 .with_usage("fim-remote <set> <url>")
329 .with_args({
330 { "set", "Set the remote URL" },
331 { "url", "The remote URL to configure" },
332 })
333 .with_example("fim-remote set https://updates.example.com/repo")
334 .with_usage("fim-remote <show>")
335 .with_args({
336 { "show", "Display the current remote URL" },
337 })
338 .with_usage("fim-remote <clear>")
339 .with_args({
340 { "clear", "Clear the configured remote URL" },
341 })
342 .get();
343}
344
345inline std::string recipe_usage()
346{
347 return HelpEntry{"fim-recipe"}
348 .with_description("Fetch, inspect, and install recipes from a remote repository")
349 .with_usage("fim-recipe <fetch> <recipes>")
350 .with_args({
351 { "fetch", "Download one or more recipes with their dependencies without installing packages" },
352 { "recipes", "Name(s) of the recipe(s) to download (comma-separated for multiple)" },
353 })
354 .with_note("Recipes and all dependencies are downloaded from URL/DISTRO/latest/<recipe>.json to path_dir_host_config/recipes/DISTRO/latest/<recipe>.json")
355 .with_example(R"(fim-recipe fetch gpu)")
356 .with_example(R"(fim-recipe fetch gpu,audio,xorg)")
357 .with_usage("fim-recipe <info> <recipes>")
358 .with_args({
359 { "info", "Display information about one or more locally cached recipes including dependencies" },
360 { "recipes", "Name(s) of the recipe(s) to inspect (comma-separated for multiple)" },
361 })
362 .with_example(R"(fim-recipe info gpu)")
363 .with_example(R"(fim-recipe info gpu,audio,xorg)")
364 .with_usage("fim-recipe <install> <recipes>")
365 .with_args({
366 { "install", "Download recipes with dependencies, validate no cycles exist, and install all packages" },
367 { "recipes", "Name(s) of the recipe(s) to install (comma-separated for multiple)" },
368 })
369 .with_note("The remote URL must be configured using 'fim-remote set <url>'")
370 .with_note("Dependencies are resolved recursively and cyclic dependencies are detected")
371 .with_example(R"(fim-recipe install gpu)")
372 .with_example(R"(fim-recipe install gpu,audio,xorg)")
373 .get();
374}
375
376inline std::string root_usage()
377{
378 return HelpEntry{"fim-root"}
379 .with_description("Executes a command as the root user")
380 .with_usage("fim-root <program> [args...]")
381 .with_args({
382 { "program", "Name of the program to execute, it can be the name of a binary or the full path" },
383 { "args...", "Arguments for the executed program" },
384 })
385 .with_example(R"(fim-root id -u)")
386 .get();
387}
388
389inline std::string unshare_usage()
390{
391 return HelpEntry{"fim-unshare"}
392 .with_description("Configure namespace unsharing options for isolation")
393 .with_note("Unshare options: all,user,ipc,pid,net,uts,cgroup")
394 .with_note("USER and CGROUP use '-try' variants in bubblewrap for permissiveness")
395 .with_usage("fim-unshare <add|del|set> <options...>")
396 .with_args({
397 { "add", "Enable one or more unshare options" },
398 { "del", "Remove one or more unshare options" },
399 { "set", "Replace all unshare options with the specified set" },
400 { "options...", "One or more unshare options (comma-separated)" },
401 })
402 .with_example("fim-unshare add ipc,pid")
403 .with_example("fim-unshare set user,ipc,net")
404 .with_note("The 'all' option enables all available unshare options and cannot be combined with others")
405 .with_usage("fim-unshare <list|clear>")
406 .with_args({
407 { "list", "Lists the current unshare options" },
408 { "clear", "Clears all unshare options" },
409 })
410 .get();
411}
412
413inline std::string version_usage()
414{
415 return HelpEntry{"fim-version"}
416 .with_description("Displays version information of FlatImage")
417 .with_usage("fim-version <short|full|deps>")
418 .with_args({
419 { "short", "Displays the version as a string" },
420 { "full", "Displays the version and build information in json" },
421 { "deps", "Displays dependencies metadata in json" },
422 })
423 .get();
424}
425
426} // namespace ns_cmd::ns_help
427
428/* vim: set expandtab fdm=marker ts=2 sw=2 tw=100 et :*/
Help system and command documentation.
Value< std::vector< std::string > > get(fs::path const &path_file_binary)
Get existing variables from the database.
Definition env.hpp:144