@@ -234,6 +234,82 @@ struct shell_static_entry {
234
234
uint8_t padding [Z_SHELL_STATIC_ENTRY_PADDING ];
235
235
};
236
236
237
+ /**
238
+ * @brief Shell structured help descriptor.
239
+ *
240
+ * @details This structure provides an organized way to specify command help
241
+ * as opposed to a free-form string. This helps make help messages more
242
+ * consistent and easier to read.
243
+ */
244
+ struct shell_cmd_help {
245
+ /* @cond INTERNAL_HIDDEN */
246
+ uint32_t magic ;
247
+ /* @endcond */
248
+ const char * description ; /*!< Command description */
249
+ const char * usage ; /*!< Command usage string */
250
+ };
251
+
252
+ /**
253
+ * @cond INTERNAL_HIDDEN
254
+ */
255
+
256
+ /**
257
+ * @brief Magic number used to identify the beginning of a structured help
258
+ * message when cast to a char pointer.
259
+ */
260
+ #define SHELL_STRUCTURED_HELP_MAGIC 0x86D20BC4
261
+
262
+ /**
263
+ * @endcond
264
+ */
265
+
266
+ /**
267
+ * @brief Check if help string is structured help.
268
+ *
269
+ * @param help Pointer to help string or structured help.
270
+ * @return true if help is structured, false otherwise.
271
+ */
272
+ static inline bool shell_help_is_structured (const char * help )
273
+ {
274
+ const struct shell_cmd_help * structured = (const struct shell_cmd_help * )help ;
275
+
276
+ return structured != NULL && structured -> magic == SHELL_STRUCTURED_HELP_MAGIC ;
277
+ }
278
+
279
+ #if defined(CONFIG_SHELL_HELP ) || defined(__DOXYGEN__ )
280
+ /**
281
+ * @brief Helper macro to create structured help inline.
282
+ *
283
+ * This macro allows you to pass structured help directly to existing shell macros.
284
+ *
285
+ * Example:
286
+ *
287
+ * @code{.c}
288
+ * #define MY_CMD_HELP SHELL_HELP("Do stuff", "<device> <arg1> [<arg2>]")
289
+ * SHELL_CMD_REGISTER(my_cmd, NULL, MY_CMD_HELP, &my_cmd_handler, 1, 1);
290
+ * @endcode
291
+ *
292
+ * @param[in] _description Command description.
293
+ * This can be a multi-line string. First line should be one sentence
294
+ * describing the command. Additional lines might be used to provide
295
+ * additional details.
296
+ *
297
+ * @param[in] _usage Command usage string.
298
+ * This can be a multi-line string. First line should always be
299
+ * indicating the command syntax (_without_ the command name).
300
+ * Additional lines may be used to provide additional details, e.g.
301
+ * explain the meaning of each argument, allowed values, etc.
302
+ */
303
+ #define SHELL_HELP (_description , _usage ) \
304
+ ((const char *)&(const struct shell_cmd_help){ \
305
+ .magic = SHELL_STRUCTURED_HELP_MAGIC, \
306
+ .description = (_description), \
307
+ .usage = (_usage), \
308
+ })
309
+ #else
310
+ #define SHELL_HELP (_description , _usage ) NULL
311
+ #endif /* CONFIG_SHELL_HELP */
312
+
237
313
/**
238
314
* @brief Macro for defining and adding a root command (level 0) with required
239
315
* number of arguments.
@@ -244,7 +320,7 @@ struct shell_static_entry {
244
320
*
245
321
* @param[in] syntax Command syntax (for example: history).
246
322
* @param[in] subcmd Pointer to a subcommands array.
247
- * @param[in] help Pointer to a command help string.
323
+ * @param[in] help Pointer to a command help string (use @ref SHELL_HELP for structured help)
248
324
* @param[in] handler Pointer to a function handler.
249
325
* @param[in] mandatory Number of mandatory arguments including command name.
250
326
* @param[in] optional Number of optional arguments.
@@ -275,7 +351,7 @@ struct shell_static_entry {
275
351
* exists and equals 1.
276
352
* @param[in] syntax Command syntax (for example: history).
277
353
* @param[in] subcmd Pointer to a subcommands array.
278
- * @param[in] help Pointer to a command help string.
354
+ * @param[in] help Pointer to a command help string (use @ref SHELL_HELP for structured help) .
279
355
* @param[in] handler Pointer to a function handler.
280
356
* @param[in] mandatory Number of mandatory arguments including command name.
281
357
* @param[in] optional Number of optional arguments.
@@ -303,7 +379,7 @@ struct shell_static_entry {
303
379
*
304
380
* @param[in] syntax Command syntax (for example: history).
305
381
* @param[in] subcmd Pointer to a subcommands array.
306
- * @param[in] help Pointer to a command help string.
382
+ * @param[in] help Pointer to a command help string. Use @ref SHELL_HELP for structured help.
307
383
* @param[in] handler Pointer to a function handler.
308
384
*/
309
385
#define SHELL_CMD_REGISTER (syntax , subcmd , help , handler ) \
@@ -319,7 +395,7 @@ struct shell_static_entry {
319
395
* exists and equals 1.
320
396
* @param[in] syntax Command syntax (for example: history).
321
397
* @param[in] subcmd Pointer to a subcommands array.
322
- * @param[in] help Pointer to a command help string.
398
+ * @param[in] help Pointer to a command help string. Use @ref SHELL_HELP for structured help.
323
399
* @param[in] handler Pointer to a function handler.
324
400
*/
325
401
#define SHELL_COND_CMD_REGISTER (flag , syntax , subcmd , help , handler ) \
@@ -455,7 +531,7 @@ struct shell_static_entry {
455
531
*
456
532
* @param[in] syntax Command syntax (for example: history).
457
533
* @param[in] subcmd Pointer to a subcommands array.
458
- * @param[in] help Pointer to a command help string.
534
+ * @param[in] help Pointer to a command help string. Use @ref SHELL_HELP for structured help.
459
535
* @param[in] handler Pointer to a function handler.
460
536
* @param[in] mand Number of mandatory arguments including command name.
461
537
* @param[in] opt Number of optional arguments.
@@ -477,7 +553,7 @@ struct shell_static_entry {
477
553
* exists and equals 1.
478
554
* @param[in] syntax Command syntax (for example: history).
479
555
* @param[in] subcmd Pointer to a subcommands array.
480
- * @param[in] help Pointer to a command help string.
556
+ * @param[in] help Pointer to a command help string. Use @ref SHELL_HELP for structured help.
481
557
* @param[in] handler Pointer to a function handler.
482
558
* @param[in] mand Number of mandatory arguments including command name.
483
559
* @param[in] opt Number of optional arguments.
0 commit comments