All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
cli_command.h File Reference

Command metadata and helpers. More...

#include <furi.h>
#include <toolbox/pipe.h>
#include <lib/flipper_application/flipper_application.h>

Go to the source code of this file.

Data Structures

struct  CliCommandDescriptor
 
struct  CliCommandExternalConfig
 Configuration for locating external commands. More...
 

Macros

#define CLI_PLUGIN_API_VERSION   1
 
#define CLI_COMMAND_INTERFACE(name, execute_callback, flags, stack_depth, app_id)
 

Typedefs

typedef void(* CliCommandExecuteCallback) (PipeSide *pipe, FuriString *args, void *context)
 CLI command execution callback pointer.
 

Enumerations

enum  CliCommandFlag {
  CliCommandFlagDefault = 0 , CliCommandFlagParallelSafe = (1 << 0) , CliCommandFlagInsomniaSafe = (1 << 1) , CliCommandFlagDontAttachStdio = (1 << 2) ,
  CliCommandFlagUseShellThread , CliCommandFlagExternal = (1 << 4)
}
 

Functions

bool cli_is_pipe_broken_or_is_etx_next_char (PipeSide *side)
 Detects if Ctrl+C has been pressed or session has been terminated.
 
void cli_print_usage (const char *cmd, const char *usage, const char *arg)
 Print unified cmd usage tip.
 

Detailed Description

Command metadata and helpers.

Macro Definition Documentation

◆ CLI_COMMAND_INTERFACE

#define CLI_COMMAND_INTERFACE ( name,
execute_callback,
flags,
stack_depth,
app_id )
Value:
static const CliCommandDescriptor cli_##name##_desc = { \
#name, \
&execute_callback, \
flags, \
stack_depth, \
}; \
\
static const FlipperAppPluginDescriptor plugin_descriptor = { \
.appid = app_id, \
.ep_api_version = CLI_PLUGIN_API_VERSION, \
.entry_point = &cli_##name##_desc, \
}; \
\
const FlipperAppPluginDescriptor* cli_##name##_ep(void) { \
return &plugin_descriptor; \
}
Definition cli_command.h:49

Typedef Documentation

◆ CliCommandExecuteCallback

typedef void(* CliCommandExecuteCallback) (PipeSide *pipe, FuriString *args, void *context)

CLI command execution callback pointer.

This callback will be called from a separate thread spawned just for your command. The pipe will be installed as the thread's stdio, so you can use printf, getchar and other standard functions to communicate with the user.

Parameters
[in]pipePipe that can be used to send and receive data. If CliCommandFlagDontAttachStdio was not set, you can also use standard C functions (printf, getc, etc.) to access this pipe.
[in]argsString with what was passed after the command
[in]contextWhatever you provided to cli_add_command

Enumeration Type Documentation

◆ CliCommandFlag

Enumerator
CliCommandFlagDefault 

Default.

CliCommandFlagParallelSafe 

Safe to run in parallel with other apps.

CliCommandFlagInsomniaSafe 

Safe to run with insomnia mode on.

CliCommandFlagDontAttachStdio 

Do no attach I/O pipe to thread stdio.

CliCommandFlagUseShellThread 

Don't start a separate thread to run the command in.

Incompatible with DontAttachStdio

CliCommandFlagExternal 

The command comes from a .fal file.

Function Documentation

◆ cli_is_pipe_broken_or_is_etx_next_char()

bool cli_is_pipe_broken_or_is_etx_next_char ( PipeSide * side)

Detects if Ctrl+C has been pressed or session has been terminated.

Parameters
[in]sidePointer to pipe side given to the command thread
Warning
This function also assumes that the pipe is installed as the thread's stdio
This function will consume 0 or 1 bytes from the pipe

◆ cli_print_usage()

void cli_print_usage ( const char * cmd,
const char * usage,
const char * arg )

Print unified cmd usage tip.

Parameters
cmdcmd name
usageusage tip
argarg passed by user