xref: /openbmc/openpower-hw-diags/cli.cpp (revision d28d5f8b)
1 #include <attn/attn_config.hpp>
2 
3 #include <algorithm>
4 #include <string>
5 
6 /** @brief Search the command line arguments for an option */
getCliOption(char ** i_begin,char ** i_end,const std::string & i_option)7 bool getCliOption(char** i_begin, char** i_end, const std::string& i_option)
8 {
9     return (i_end != std::find(i_begin, i_end, i_option));
10 }
11 
12 /** @brief Search the command line arguments for a setting value */
getCliSetting(char ** i_begin,char ** i_end,const std::string & i_setting)13 char* getCliSetting(char** i_begin, char** i_end, const std::string& i_setting)
14 {
15     char** value = std::find(i_begin, i_end, i_setting);
16     return (value != i_end && ++value != i_end) ? *value : 0;
17 }
18 
19 /** @brief Parse command line for configuration flags */
parseConfig(char ** i_begin,char ** i_end,attn::Config * o_config)20 void parseConfig(char** i_begin, char** i_end, attn::Config* o_config)
21 {
22     char* setting;
23 
24     // --all on/off takes precedence over individual settings
25     setting = getCliSetting(i_begin, i_end, "--all");
26     if (nullptr != setting)
27     {
28         if (std::string("off") == setting)
29         {
30             o_config->clearFlagAll();
31         }
32 
33         if (std::string("on") == setting)
34         {
35             o_config->setFlagAll();
36         }
37     }
38     // Parse individual options
39     else
40     {
41         setting = getCliSetting(i_begin, i_end, "--vital");
42         if (nullptr != setting)
43         {
44             if (std::string("off") == setting)
45             {
46                 o_config->clearFlag(attn::enVital);
47             }
48             if (std::string("on") == setting)
49             {
50                 o_config->setFlag(attn::enVital);
51             }
52         }
53 
54         setting = getCliSetting(i_begin, i_end, "--checkstop");
55         if (nullptr != setting)
56         {
57             if (std::string("off") == setting)
58             {
59                 o_config->clearFlag(attn::enCheckstop);
60             }
61             if (std::string("on") == setting)
62             {
63                 o_config->setFlag(attn::enCheckstop);
64             }
65         }
66 
67         setting = getCliSetting(i_begin, i_end, "--terminate");
68         if (nullptr != setting)
69         {
70             if (std::string("off") == setting)
71             {
72                 o_config->clearFlag(attn::enTerminate);
73             }
74             if (std::string("on") == setting)
75             {
76                 o_config->setFlag(attn::enTerminate);
77             }
78         }
79 
80         setting = getCliSetting(i_begin, i_end, "--breakpoints");
81         if (nullptr != setting)
82         {
83             if (std::string("off") == setting)
84             {
85                 o_config->clearFlag(attn::enBreakpoints);
86             }
87             if (std::string("on") == setting)
88             {
89                 o_config->setFlag(attn::enBreakpoints);
90             }
91         }
92 
93         // This option determines whether we service a TI or breakpoint in the
94         // case where TI info is available but not valid. The default setting
95         // of this is "clear" meaning we will handle breakpoint by default.
96         // This flag is not affected by the set/clear all command line option.
97         if (true == getCliOption(i_begin, i_end, "--defaultti"))
98         {
99             o_config->setFlag(attn::dfltTi);
100         }
101 
102         setting = getCliSetting(i_begin, i_end, "--clrattnintr");
103         if (nullptr != setting)
104         {
105             if (std::string("off") == setting)
106             {
107                 o_config->clearFlag(attn::enClrAttnIntr);
108             }
109             if (std::string("on") == setting)
110             {
111                 o_config->setFlag(attn::enClrAttnIntr);
112             }
113         }
114     }
115 }
116