1
2//
3// This source file is part of appleseed.
4// Visit http://appleseedhq.net/ for additional information and resources.
5//
6// This software is released under the MIT license.
7//
8// Copyright (c) 2010-2013 Francois Beaune, Jupiter Jazz Limited
9// Copyright (c) 2014-2017 Francois Beaune, The appleseedhq Organization
10//
11// Permission is hereby granted, free of charge, to any person obtaining a copy
12// of this software and associated documentation files (the "Software"), to deal
13// in the Software without restriction, including without limitation the rights
14// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15// copies of the Software, and to permit persons to whom the Software is
16// furnished to do so, subject to the following conditions:
17//
18// The above copyright notice and this permission notice shall be included in
19// all copies or substantial portions of the Software.
20//
21// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
27// THE SOFTWARE.
28//
29
30// Interface header.
31#include "commandlinehandler.h"
32
33// appleseed.shared headers.
34#include "application/superlogger.h"
35
36// appleseed.foundation headers.
37#include "foundation/utility/log.h"
38
39using namespace appleseed::shared;
40using namespace foundation;
41
42namespace appleseed {
43namespace cli {
44
45CommandLineHandler::CommandLineHandler()
46 : CommandLineHandlerBase("appleseed.cli")
47{
48 add_default_options();
49
50 parser().set_default_option_handler(
51 &m_filename
52 .set_min_value_count(0)
53 .set_max_value_count(1));
54
55 parser().add_option_handler(
56 &m_configuration
57 .add_name("--configuration")
58 .add_name("-c")
59 .set_description("select the configuration")
60 .set_syntax("name")
61 .set_exact_value_count(1));
62
63 parser().add_option_handler(
64 &m_params
65 .add_name("--parameter")
66 .add_name("-p")
67 .set_description("set a custom parameter")
68 .set_syntax("name=value")
69 .set_flags(OptionHandler::Repeatable)
70 .set_exact_value_count(1));
71
72#if defined __APPLE__ || defined _WIN32
73
74 parser().add_option_handler(
75 &m_display_output
76 .add_name("--display-output")
77 .set_description("display the output image"));
78
79#endif
80
81 parser().add_option_handler(
82 &m_disable_autosave
83 .add_name("--disable-autosave")
84 .set_description("disable automatic saving of rendered images"));
85
86 parser().add_option_handler(
87 &m_threads
88 .add_name("--threads")
89 .add_name("-t")
90 .set_description("set the number of rendering threads")
91 .set_syntax("n")
92 .set_exact_value_count(1));
93
94 parser().add_option_handler(
95 &m_output.add_name("--output")
96 .add_name("-o")
97 .set_description("set the name of the output file")
98 .set_syntax("filename")
99 .set_exact_value_count(1));
100
101 parser().add_option_handler(
102 &m_continuous_saving
103 .add_name("--continuous-saving")
104 .set_description("write tiles to disk as soon as they are rendered"));
105
106 parser().add_option_handler(
107 &m_resolution
108 .add_name("--resolution")
109 .add_name("-r")
110 .set_description("set the resolution of the rendered image")
111 .set_syntax("width height")
112 .set_exact_value_count(2));
113
114 parser().add_option_handler(
115 &m_window
116 .add_name("--window")
117 .add_name("-w")
118 .set_description("restrict rendering to a given rectangle (expressed in pixels)")
119 .set_syntax("x0 y0 x1 y1")
120 .set_exact_value_count(4));
121
122 parser().add_option_handler(
123 &m_samples
124 .add_name("--samples")
125 .add_name("-s")
126 .set_description("set the minimum and maximum numbers of samples per pixel")
127 .set_syntax("min max")
128 .set_exact_value_count(2));
129
130 parser().add_option_handler(
131 &m_passes
132 .add_name("--passes")
133 .set_description("set the number of rendering passes")
134 .set_syntax("n")
135 .set_exact_value_count(1));
136
137 parser().add_option_handler(
138 &m_override_shading
139 .add_name("--override-shading")
140 .set_description("override shading with a diagnostic shader")
141 .set_syntax("shader")
142 .set_exact_value_count(1));
143
144 parser().add_option_handler(
145 &m_select_object_instances
146 .add_name("--select-object-instances")
147 .set_description("select which object instances to include in the render using a regular expression")
148 .set_syntax("regex")
149 .set_exact_value_count(1));
150
151 parser().add_option_handler(
152 &m_mplay_display
153 .add_name("--mplay")
154 .set_description("use Houdini's mplay"));
155
156 parser().add_option_handler(
157 &m_hrmanpipe_display
158 .add_name("--hrmanpipe")
159 .set_description("use Houdini's hrmanpipe; the argument is the socket number to pass to hrmanpipe")
160 .set_syntax("socket")
161 .set_exact_value_count(1));
162
163 parser().add_option_handler(
164 &m_run_unit_tests
165 .add_name("--run-unit-tests")
166 .add_name("-ut")
167 .set_description("run unit tests; filter them based on the optional regular expression argument")
168 .set_min_value_count(0)
169 .set_max_value_count(1));
170
171 parser().add_option_handler(
172 &m_run_unit_benchmarks
173 .add_name("--run-unit-benchmarks")
174 .add_name("-ub")
175 .set_description("run unit benchmarks; filter them based on the optional regular expression argument")
176 .set_min_value_count(0)
177 .set_max_value_count(1));
178
179 parser().add_option_handler(
180 &m_verbose_unit_tests
181 .add_name("--verbose-unit-tests")
182 .add_name("-utv")
183 .set_description("enable verbose mode while unit testing"));
184
185 parser().add_option_handler(
186 &m_benchmark_mode
187 .add_name("--benchmark-mode")
188 .set_description("enable benchmark mode"));
189}
190
191void CommandLineHandler::print_program_usage(
192 const char* executable_name,
193 SuperLogger& logger) const
194{
195 SaveLogFormatterConfig save_config(logger);
196 logger.set_verbosity_level(LogMessage::Info);
197 logger.set_format(LogMessage::Info, "{message}");
198
199 LOG_INFO(logger, "usage: %s [options] project.appleseed", executable_name);
200 LOG_INFO(logger, "options:");
201
202 parser().print_usage(logger);
203}
204
205} // namespace cli
206} // namespace appleseed
207