blob: a2d8c62e72cba18e1fe22aead06042a861f77288 [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,
Austin Schuh59f3b0f2021-07-31 20:50:40 -070016 std::function<bool(const aos::Channel *)> channel_filter,
Austin Schuhba2c8652022-08-17 14:56:08 -070017 std::string_view channel_filter_description,
Austin Schuh59f3b0f2021-07-31 20:50:40 -070018 bool expect_args);
Brian Silvermanea2c95f2021-02-10 18:10:26 -080019
20 std::optional<aos::FlatbufferDetachedBuffer<aos::Configuration>> config;
21 std::optional<aos::ShmEventLoop> event_loop;
22 std::vector<const aos::Channel *> found_channels;
23
24 private:
25 // Generate eval command to populate autocomplete responses. Eval escapes
26 // spaces so channels are paired with their types. If a complete channel name
27 // is found, only autocompletes the type to avoid repeating arguments. Returns
28 // no autocomplete suggestions if a channel and type is found with the current
29 // arguments.
30 void Autocomplete(std::string_view channel_name,
31 std::string_view message_type,
32 std::function<bool(const aos::Channel *)> channel_filter);
33
34 void ShiftArgs(int *argc, char ***argv) {
35 for (int i = 1; i + 1 < *argc; ++i) {
36 (*argv)[i] = (*argv)[i + 1];
37 }
38 --*argc;
39 }
40};
41
42} // namespace aos
43
44#endif // AOS_AOS_CLI_UTILS_H_