@@ -143,6 +143,85 @@ cli_do_demoapp_getopts(int argc, char **argv)
143143 options .doFailover = true;
144144 strlcpy (options .formation , "default" , sizeof (options .formation ));
145145
146+ /*
147+ * Add support for environment variables for some of those options.
148+ */
149+ if (env_exists (PG_AUTOCTL_DEMO_CLIENTS ))
150+ {
151+ char clients [BUFSIZE ] = { 0 };
152+
153+ if (!get_env_copy (PG_AUTOCTL_DEMO_CLIENTS , clients , sizeof (clients )))
154+ {
155+ /* errors have already been logged */
156+ exit (EXIT_CODE_BAD_ARGS );
157+ }
158+
159+ if (!stringToInt (clients , & (options .clientsCount )))
160+ {
161+ log_fatal ("Failed to parse \"%s\" integer value \"%s\"" ,
162+ PG_AUTOCTL_DEMO_CLIENTS ,
163+ clients );
164+ exit (EXIT_CODE_BAD_ARGS );
165+ }
166+ }
167+
168+ if (env_exists (PG_AUTOCTL_DEMO_DURATION ))
169+ {
170+ char duration [BUFSIZE ] = { 0 };
171+
172+ if (!get_env_copy (PG_AUTOCTL_DEMO_DURATION , duration , sizeof (duration )))
173+ {
174+ /* errors have already been logged */
175+ exit (EXIT_CODE_BAD_ARGS );
176+ }
177+
178+ if (!stringToInt (duration , & (options .duration )))
179+ {
180+ log_fatal ("Failed to parse \"%s\" integer value \"%s\"" ,
181+ PG_AUTOCTL_DEMO_DURATION ,
182+ duration );
183+ exit (EXIT_CODE_BAD_ARGS );
184+ }
185+ }
186+
187+ if (env_exists (PG_AUTOCTL_DEMO_FAILOVER_FIRST ))
188+ {
189+ char first [BUFSIZE ] = { 0 };
190+
191+ if (!get_env_copy (PG_AUTOCTL_DEMO_FAILOVER_FIRST , first , sizeof (first )))
192+ {
193+ /* errors have already been logged */
194+ exit (EXIT_CODE_BAD_ARGS );
195+ }
196+
197+ if (!stringToInt (first , & (options .firstFailover )))
198+ {
199+ log_fatal ("Failed to parse \"%s\" integer value \"%s\"" ,
200+ PG_AUTOCTL_DEMO_FAILOVER_FIRST ,
201+ first );
202+ exit (EXIT_CODE_BAD_ARGS );
203+ }
204+ }
205+
206+ if (env_exists (PG_AUTOCTL_DEMO_FAILOVER_FREQ ))
207+ {
208+ char freq [BUFSIZE ] = { 0 };
209+
210+ if (!get_env_copy (PG_AUTOCTL_DEMO_FAILOVER_FREQ , freq , sizeof (freq )))
211+ {
212+ /* errors have already been logged */
213+ exit (EXIT_CODE_BAD_ARGS );
214+ }
215+
216+ if (!stringToInt (freq , & (options .failoverFreq )))
217+ {
218+ log_fatal ("Failed to parse \"%s\" integer value \"%s\"" ,
219+ PG_AUTOCTL_DEMO_FAILOVER_FREQ ,
220+ freq );
221+ exit (EXIT_CODE_BAD_ARGS );
222+ }
223+ }
224+
146225 /*
147226 * The only command lines that are using cli_do_demoapp_getopts are
148227 * terminal ones: they don't accept subcommands. In that case our option
0 commit comments