forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswitches.cc
More file actions
95 lines (78 loc) · 2.82 KB
/
switches.cc
File metadata and controls
95 lines (78 loc) · 2.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// Copyright 2013 The Flutter 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 "impeller/scene/importer/switches.h"
#include <algorithm>
#include <cctype>
#include <filesystem>
#include <map>
#include "flutter/fml/file.h"
#include "impeller/compiler/utilities.h"
#include "impeller/scene/importer/types.h"
namespace impeller {
namespace scene {
namespace importer {
static const std::map<std::string, SourceType> kKnownSourceTypes = {
{"gltf", SourceType::kGLTF},
};
void Switches::PrintHelp(std::ostream& stream) {
stream << std::endl;
stream << "SceneC is an offline 3D geometry file parser." << std::endl;
stream << "---------------------------------------------------------------"
<< std::endl;
stream << "Valid Argument are:" << std::endl;
stream << "--input=<source_file>" << std::endl;
stream << "[optional] --input-kind={";
for (const auto& source_type : kKnownSourceTypes) {
stream << source_type.first << ", ";
}
stream << "} (default: gltf)" << std::endl;
stream << "--output=<output_file>" << std::endl;
}
Switches::Switches() = default;
Switches::~Switches() = default;
static SourceType SourceTypeFromCommandLine(
const fml::CommandLine& command_line) {
auto source_type_option =
command_line.GetOptionValueWithDefault("input-type", "gltf");
auto source_type_search = kKnownSourceTypes.find(source_type_option);
if (source_type_search == kKnownSourceTypes.end()) {
return SourceType::kUnknown;
}
return source_type_search->second;
}
Switches::Switches(const fml::CommandLine& command_line)
: working_directory(std::make_shared<fml::UniqueFD>(fml::OpenDirectory(
compiler::Utf8FromPath(std::filesystem::current_path()).c_str(),
false, // create if necessary,
fml::FilePermission::kRead))),
source_file_name(command_line.GetOptionValueWithDefault("input", "")),
input_type(SourceTypeFromCommandLine(command_line)),
output_file_name(command_line.GetOptionValueWithDefault("output", "")) {
if (!working_directory || !working_directory->is_valid()) {
return;
}
}
bool Switches::AreValid(std::ostream& explain) const {
bool valid = true;
if (input_type == SourceType::kUnknown) {
explain << "Unknown input type." << std::endl;
valid = false;
}
if (!working_directory || !working_directory->is_valid()) {
explain << "Could not figure out working directory." << std::endl;
valid = false;
}
if (source_file_name.empty()) {
explain << "Input file name was empty." << std::endl;
valid = false;
}
if (output_file_name.empty()) {
explain << "Target output file name was empty." << std::endl;
valid = false;
}
return valid;
}
} // namespace importer
} // namespace scene
} // namespace impeller