mirror of
https://github.com/flutter/flutter.git
synced 2026-02-20 02:29:02 +08:00
93 lines
2.4 KiB
C++
93 lines
2.4 KiB
C++
// Copyright 2013 The Chromium Authors. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
// found in the LICENSE file.
|
|
|
|
#include <iomanip>
|
|
#include <iostream>
|
|
#include <sstream>
|
|
#include <string>
|
|
|
|
#include "lib/ftl/strings/string_view.h"
|
|
|
|
// Include once for the default enum definition.
|
|
#include "flutter/shell/common/switches.h"
|
|
|
|
#undef SHELL_COMMON_SWITCHES_H_
|
|
|
|
struct SwitchDesc {
|
|
shell::Switch sw;
|
|
const ftl::StringView flag;
|
|
const char* help;
|
|
};
|
|
|
|
#undef DEF_SWITCHES_START
|
|
#undef DEF_SWITCH
|
|
#undef DEF_SWITCHES_END
|
|
|
|
// clang-format off
|
|
#define DEF_SWITCHES_START static const struct SwitchDesc gSwitchDescs[] = {
|
|
#define DEF_SWITCH(p_swtch, p_flag, p_help) \
|
|
{ .sw = shell::Switch:: p_swtch, .flag = p_flag, .help = p_help },
|
|
#define DEF_SWITCHES_END };
|
|
// clang-format on
|
|
|
|
// Include again for struct definition.
|
|
#include "flutter/shell/common/switches.h"
|
|
|
|
namespace shell {
|
|
|
|
void PrintUsage(const std::string& executable_name) {
|
|
std::cerr << std::endl << " " << executable_name << std::endl << std::endl;
|
|
|
|
std::cerr << "Available Flags:" << std::endl;
|
|
|
|
const uint32_t column_width = 80;
|
|
|
|
const uint32_t flags_count = static_cast<uint32_t>(Switch::Sentinel);
|
|
|
|
uint32_t max_width = 2;
|
|
for (uint32_t i = 0; i < flags_count; i++) {
|
|
auto desc = gSwitchDescs[i];
|
|
max_width = std::max<uint32_t>(desc.flag.size() + 2, max_width);
|
|
}
|
|
|
|
const uint32_t help_width = column_width - max_width - 3;
|
|
|
|
std::cerr << std::string(column_width, '-') << std::endl;
|
|
for (uint32_t i = 0; i < flags_count; i++) {
|
|
auto desc = gSwitchDescs[i];
|
|
|
|
std::cerr << std::setw(max_width)
|
|
<< std::string("--") + desc.flag.ToString() << " : ";
|
|
|
|
std::istringstream stream(desc.help);
|
|
int32_t remaining = help_width;
|
|
|
|
std::string word;
|
|
while (stream >> word && remaining > 0) {
|
|
remaining -= (word.size() + 1);
|
|
if (remaining <= 0) {
|
|
std::cerr << std::endl
|
|
<< std::string(max_width, ' ') << " " << word << " ";
|
|
remaining = help_width;
|
|
} else {
|
|
std::cerr << word << " ";
|
|
}
|
|
}
|
|
|
|
std::cerr << std::endl;
|
|
}
|
|
std::cerr << std::string(column_width, '-') << std::endl;
|
|
}
|
|
|
|
const ftl::StringView FlagForSwitch(Switch swtch) {
|
|
for (uint32_t i = 0; i < static_cast<uint32_t>(Switch::Sentinel); i++) {
|
|
if (gSwitchDescs[i].sw == swtch) {
|
|
return gSwitchDescs[i].flag;
|
|
}
|
|
}
|
|
return ftl::StringView();
|
|
}
|
|
|
|
} // namespace shell
|