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