///////////////////////////////////////////////////////////////////////////
| 54 | |
| 55 | //////////////////////////////////////////////////////////////////////////////// |
| 56 | int CmdColumns::execute(std::string& output) { |
| 57 | // Obtain the arguments from the description. That way, things like '--' |
| 58 | // have already been handled. |
| 59 | auto words = Context::getContext().cli2.getWords(); |
| 60 | if (words.size() > 1) throw std::string("You can only specify one search string."); |
| 61 | |
| 62 | // Include all columns in the table. |
| 63 | std::vector<std::string> names; |
| 64 | for (const auto& col : Context::getContext().columns) names.push_back(col.first); |
| 65 | |
| 66 | std::sort(names.begin(), names.end()); |
| 67 | |
| 68 | // Render a list of column names, formats and examples. |
| 69 | Table formats; |
| 70 | formats.width(Context::getContext().getWidth()); |
| 71 | formats.add("Columns"); |
| 72 | formats.add("Type"); |
| 73 | formats.add("Modifiable"); |
| 74 | formats.add("Supported Formats"); |
| 75 | formats.add("Example"); |
| 76 | setHeaderUnderline(formats); |
| 77 | |
| 78 | for (const auto& name : names) { |
| 79 | if (words.size() == 0 || find(name, words[0], false) != std::string::npos) { |
| 80 | auto styles = Context::getContext().columns[name]->styles(); |
| 81 | auto examples = Context::getContext().columns[name]->examples(); |
| 82 | |
| 83 | for (unsigned int i = 0; i < styles.size(); ++i) { |
| 84 | auto row = formats.addRow(); |
| 85 | formats.set(row, 0, i == 0 ? name : ""); |
| 86 | formats.set(row, 1, i == 0 ? Context::getContext().columns[name]->type() : ""); |
| 87 | formats.set(row, 2, |
| 88 | i == 0 ? (Context::getContext().columns[name]->modifiable() ? "Modifiable" |
| 89 | : "Read Only") |
| 90 | : ""); |
| 91 | formats.set(row, 3, styles[i] + (i == 0 ? "*" : "")); |
| 92 | formats.set(row, 4, i < examples.size() ? examples[i] : ""); |
| 93 | } |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | auto row = formats.addRow(); |
| 98 | formats.set(row, 0, "<uda>"); |
| 99 | formats.set(row, 1, "<type>"); |
| 100 | formats.set(row, 2, "Modifiable"); |
| 101 | formats.set(row, 3, "default*"); |
| 102 | |
| 103 | row = formats.addRow(); |
| 104 | formats.set(row, 0, ""); |
| 105 | formats.set(row, 3, "indicator"); |
| 106 | |
| 107 | output = optionalBlankLine() + formats.render() + '\n' + |
| 108 | "* Means default format, and therefore optional. For example, 'due' and " |
| 109 | "'due.formatted' are equivalent.\n"; |
| 110 | |
| 111 | return 0; |
| 112 | } |
| 113 |
nothing calls this directly
no test coverage detected