blob: e15873756cb8f3f6b1208ae2718156b0b1732396 [file] [log] [blame]
Brian Silvermanea2c95f2021-02-10 18:10:26 -08001#ifndef AOS_AOS_CLI_UTILS_H_
2#define AOS_AOS_CLI_UTILS_H_
3
4#include "aos/configuration.h"
5#include "aos/events/shm_event_loop.h"
6#include "gflags/gflags.h"
7
8namespace aos {
9
10// The information needed by the main function of a CLI tool.
11struct CliUtilInfo {
12 // If this returns true, main should return immediately with 0.
13 // If this returns false, the other fields will be filled out appropriately.
14 // event_loop will be filled out before channel_filter is called.
15 bool Initialize(int *argc, char ***argv,
16 std::function<bool(const aos::Channel *)> channel_filter);
17
18 std::optional<aos::FlatbufferDetachedBuffer<aos::Configuration>> config;
19 std::optional<aos::ShmEventLoop> event_loop;
20 std::vector<const aos::Channel *> found_channels;
21
22 private:
23 // Generate eval command to populate autocomplete responses. Eval escapes
24 // spaces so channels are paired with their types. If a complete channel name
25 // is found, only autocompletes the type to avoid repeating arguments. Returns
26 // no autocomplete suggestions if a channel and type is found with the current
27 // arguments.
28 void Autocomplete(std::string_view channel_name,
29 std::string_view message_type,
30 std::function<bool(const aos::Channel *)> channel_filter);
31
32 void ShiftArgs(int *argc, char ***argv) {
33 for (int i = 1; i + 1 < *argc; ++i) {
34 (*argv)[i] = (*argv)[i + 1];
35 }
36 --*argc;
37 }
38};
39
40} // namespace aos
41
42#endif // AOS_AOS_CLI_UTILS_H_