Skip to content

Commit 6b66771

Browse files
committed
Add messages to help with horizon-imp cli arg usage for #744
1 parent b979731 commit 6b66771

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

src/imp/imp_main.cpp

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,33 @@
2525

2626
using json = nlohmann::json;
2727

28+
static void expect_filename_arg(const std::vector<std::string> &filenames, const char *name, size_t i)
29+
{
30+
if (filenames.size() <= i || !Glib::file_test(filenames.at(i), Glib::FILE_TEST_EXISTS)) {
31+
g_warning("%s filename argument at %i missing or does not exist", name, static_cast<int>(i));
32+
}
33+
}
34+
35+
static void expect_dir_arg(const std::vector<std::string> &filenames, const char *name, size_t i)
36+
{
37+
if (filenames.size() <= i || filenames.at(i).size() == 0) {
38+
g_warning("%s directory argument at %i missing", name, static_cast<int>(i));
39+
}
40+
}
41+
42+
static void expect_pool_env(const std::string &pool_base_path)
43+
{
44+
if (pool_base_path.length() <= 0) {
45+
g_warning("HORIZON_POOL dir env var is not set");
46+
}
47+
else if (!Glib::file_test(pool_base_path, Glib::FILE_TEST_EXISTS)) {
48+
g_warning("HORIZON_POOL dir does not exist");
49+
}
50+
else if (!Glib::file_test(Glib::build_filename(pool_base_path, "pool.json"), Glib::FILE_TEST_EXISTS)) {
51+
g_warning("HORIZON_POOL dir does not contain pool.json");
52+
}
53+
}
54+
2855
int main(int argc, char *argv[])
2956
{
3057
#ifdef G_OS_WIN32
@@ -38,6 +65,7 @@ int main(int argc, char *argv[])
3865

3966
Glib::OptionContext options;
4067
options.set_summary("horizon interactive manipulator");
68+
options.set_description("The 'HORIZON_POOL' env var should be set directory of the pool being used.");
4169
options.set_help_enabled();
4270

4371
Glib::OptionGroup group("imp", "imp");
@@ -123,41 +151,59 @@ int main(int argc, char *argv[])
123151
horizon::setup_locale();
124152

125153
horizon::create_cache_and_config_dir();
126-
127154
std::unique_ptr<horizon::ImpBase> imp = nullptr;
128155
if (mode_sch) {
156+
expect_filename_arg(filenames, "blocks", 0);
157+
expect_dir_arg(filenames, "pictures", 1);
158+
expect_pool_env(pool_base_path);
129159
imp.reset(new horizon::ImpSchematic(filenames, {pool_base_path}));
130160
}
131161
else if (mode_symbol) {
162+
expect_filename_arg(filenames, "symbol", 0);
163+
expect_pool_env(pool_base_path);
132164
imp.reset(new horizon::ImpSymbol(filenames.at(0), pool_base_path, temp_mode));
133165
if (filenames.size() > 1)
134166
imp->set_suggested_filename(filenames.at(1));
135167
}
136168
else if (mode_padstack) {
169+
expect_filename_arg(filenames, "padstack", 0);
170+
expect_pool_env(pool_base_path);
137171
imp.reset(new horizon::ImpPadstack(filenames.at(0), pool_base_path, temp_mode));
138172
if (filenames.size() > 1)
139173
imp->set_suggested_filename(filenames.at(1));
140174
}
141175
else if (mode_package) {
176+
expect_filename_arg(filenames, "package", 0);
177+
expect_pool_env(pool_base_path);
142178
imp.reset(new horizon::ImpPackage(filenames.at(0), pool_base_path, temp_mode));
143179
if (filenames.size() > 1)
144180
imp->set_suggested_filename(filenames.at(1));
145181
}
146182
else if (mode_board) {
183+
expect_filename_arg(filenames, "board", 0);
184+
expect_filename_arg(filenames, "planes", 1);
185+
expect_filename_arg(filenames, "blocks", 2);
186+
expect_dir_arg(filenames, "pictures", 3);
187+
expect_pool_env(pool_base_path);
147188
imp.reset(new horizon::ImpBoard(filenames, {pool_base_path}));
148189
}
149190
else if (mode_frame) {
191+
expect_filename_arg(filenames, "frame", 0);
192+
expect_pool_env(pool_base_path);
150193
imp.reset(new horizon::ImpFrame(filenames.at(0), pool_base_path, temp_mode));
151194
if (filenames.size() > 1)
152195
imp->set_suggested_filename(filenames.at(1));
153196
}
154197
else if (mode_decal) {
198+
expect_filename_arg(filenames, "decal", 0);
199+
expect_pool_env(pool_base_path);
155200
imp.reset(new horizon::ImpDecal(filenames.at(0), pool_base_path, temp_mode));
156201
if (filenames.size() > 1)
157202
imp->set_suggested_filename(filenames.at(1));
158203
}
159204
else {
160205
std::cout << "wrong invocation" << std::endl;
206+
std::cout << options.get_help().c_str();
161207
return 1;
162208
}
163209
imp->set_read_only(read_only);

0 commit comments

Comments
 (0)