ores.cpp.shell-command.operation_header

Table of Contents

The class declaration for one operation model's shell command unit.

The facet's entity archetypes render a fixed CRUD set. This archetype renders what the model declares: one process_* handler per message that carries a :subject: and a :response:, because the subject is what the command sends to and the response is what it prints. A message with no response answers with nothing to show, and a payload struct has no subject at all, so neither becomes a command.

The model type is the only difference from the entity archetypes, and it is stated here rather than inherited so the entity archetypes keep rendering entities. Nothing else about the facet changes: the opt-in, the part the unit lands in and the aggregator that calls register_commands are the same.

A declared field without a :default: is a positional argument; one with a :default: is a --<name> flag, so the struct's own initialiser stands when the caller omits it. A list field arrives as one comma-separated token.

1. Template

The full template source. Edit here and re-tangle with compass build --direct tangle_codegen_templates to regenerate library/templates/cpp_shell_operation_header.hpp.mustache.

{{! GENERATED FILE — tangled from projects/ores.codegen/library/templates/ores.cpp.shell-command.operation_header.org. Edit the org source. }}
{{{cpp_license}}}
{{#operation}}
#ifndef ORES_SHELL_APP_COMMANDS_{{entity_singular_upper}}_OPERATIONS_COMMANDS_HPP
#define ORES_SHELL_APP_COMMANDS_{{entity_singular_upper}}_OPERATIONS_COMMANDS_HPP

#include "ores.logging/make_logger.hpp"
#include "ores.nats/service/nats_client.hpp"
#include <ostream>
#include <string>
#include <vector>

namespace cli {

class Menu;

}

namespace ores::shell::app::commands {

/**
 * @brief The operations {{entity_singular}} declares that no entity's CRUD verbs state.
 *
 * One command per message the protocol declares with a subject and a response,
 * so the REPL surface and the protocol stay one declaration.
 */
class {{entity_singular}}_operations_commands {
private:
    inline static std::string_view logger_name =
        "ores.shell.app.commands.{{component}}.{{entity_singular}}_operations_commands";

    static auto& lg() {
        using namespace ores::logging;
        static auto instance = make_logger(logger_name);
        return instance;
    }

public:
    /**
     * @brief Register the {{entity_singular}} operations on the root menu.
     */
    static void register_commands(cli::Menu& root_menu,
                                  ores::nats::service::nats_client& session);
{{#shell_commands}}

    /**
     * @brief {{usage}}
     */
    static void process_{{identifier}}(std::ostream& out,
                                      ores::nats::service::nats_client& session,
                                      const std::vector<std::string>& args);
{{/shell_commands}}
};

}

#endif
{{/operation}}

2. See also

Emacs 29.3 (Org mode 9.6.15)