This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

CLI command with parameter

Hello,

I would like to have something like this:

ROOT_COMMAND SubCommand CustomParameter

Example:

DeviceName Set ExampleDeviceName

Where CustomParameter can be a string or hex value, that I would like to get and store in non volatile memory using Flash Data Storage. Is it possible with CLI? What is the right approach?

  • Hi,

    Yes it is possible and quite easy with CLI.

    I would recommend to implement handlers for both commands: DeviceName and Set. DeviceName can have a simple handler to print command help - please refer to CLI examples. Actual handler shall be implemented within Set command. To make it even more easy I would recommend you to implement 2 subcommands: SetString and SetHex.

    I would do it like that:

    NRF_CLI_CREATE_STATIC_SUBCMD_SET(m_sub_device_name)
    {
        NRF_CLI_CMD(SetHex,    NULL, "Your subcommand help string.",  cmd_set_hex),
        NRF_CLI_CMD(SetString, NULL, "Your subcommand help string.",  cmd_set_string),
        NRF_CLI_SUBCMD_SET_END
    };
    NRF_CLI_CMD_REGISTER(DeviceName,
                         &m_sub_device_name,
                         "Your command help string.",
                         cmd_device_name);
    
Related