diff options
| author | Carl Hetherington <cth@carlh.net> | 2023-04-11 00:54:13 +0200 |
|---|---|---|
| committer | Carl Hetherington <cth@carlh.net> | 2023-04-11 20:31:45 +0200 |
| commit | e1aac965a70ad8f50716325ef31a1829161dc6d3 (patch) | |
| tree | 479f6b6a873aef239fa2cd2924839e973dbedd2a | |
| parent | 87354b0a1d1f9ad48202f13e3bc2c6c3937b8a81 (diff) | |
Give an error if a non-number is passed to dcpomatic2_create -s (#2488).
| -rw-r--r-- | src/lib/create_cli.cc | 11 | ||||
| -rw-r--r-- | src/lib/create_cli.h | 2 | ||||
| -rw-r--r-- | src/tools/dcpomatic_create.cc | 2 | ||||
| -rw-r--r-- | test/create_cli_test.cc | 8 |
4 files changed, 17 insertions, 6 deletions
diff --git a/src/lib/create_cli.cc b/src/lib/create_cli.cc index 2cbff6e85..81e353893 100644 --- a/src/lib/create_cli.cc +++ b/src/lib/create_cli.cc @@ -123,7 +123,6 @@ CreateCLI::CreateCLI (int argc, char* argv[]) , threed (false) , dcp_content_type (nullptr) , container_ratio (nullptr) - , still_length (10) , standard (dcp::Standard::SMPTE) , no_use_isdcf_name (false) , twok (false) @@ -184,12 +183,20 @@ CreateCLI::CreateCLI (int argc, char* argv[]) return boost::filesystem::path(s); }; + std::function<optional<int> (string s)> string_to_nonzero_int = [](string s) { + auto const value = dcp::raw_convert<int>(s); + if (value == 0) { + return boost::optional<int>(); + } + return boost::optional<int>(value); + }; + argument_option(i, argc, argv, "-n", "--name", &claimed, &error, &name); argument_option(i, argc, argv, "-t", "--template", &claimed, &error, &template_name_string); argument_option(i, argc, argv, "-c", "--dcp-content-type", &claimed, &error, &dcp_content_type_string); argument_option(i, argc, argv, "-f", "--dcp-frame-rate", &claimed, &error, &dcp_frame_rate_int); argument_option(i, argc, argv, "", "--container-ratio", &claimed, &error, &container_ratio_string); - argument_option(i, argc, argv, "-s", "--still-length", &claimed, &error, &still_length); + argument_option(i, argc, argv, "-s", "--still-length", &claimed, &error, &still_length, string_to_nonzero_int); argument_option(i, argc, argv, "", "--standard", &claimed, &error, &standard_string); argument_option(i, argc, argv, "", "--config", &claimed, &error, &config_dir, string_to_path); argument_option(i, argc, argv, "-o", "--output", &claimed, &error, &output_dir, string_to_path); diff --git a/src/lib/create_cli.h b/src/lib/create_cli.h index e473be1f2..58f7cf20c 100644 --- a/src/lib/create_cli.h +++ b/src/lib/create_cli.h @@ -52,7 +52,7 @@ public: DCPContentType const * dcp_content_type; boost::optional<int> dcp_frame_rate; Ratio const * container_ratio; - int still_length; + boost::optional<int> still_length; dcp::Standard standard; bool no_use_isdcf_name; boost::optional<boost::filesystem::path> config_dir; diff --git a/src/tools/dcpomatic_create.cc b/src/tools/dcpomatic_create.cc index bd059e9f8..caaba6b38 100644 --- a/src/tools/dcpomatic_create.cc +++ b/src/tools/dcpomatic_create.cc @@ -184,7 +184,7 @@ main (int argc, char* argv[]) for (auto i: film->content()) { auto ic = dynamic_pointer_cast<ImageContent> (i); if (ic && ic->still()) { - ic->video->set_length (cc.still_length * 24); + ic->video->set_length(cc.still_length.get_value_or(10) * 24); } } diff --git a/test/create_cli_test.cc b/test/create_cli_test.cc index 71281a63e..3bc819604 100644 --- a/test/create_cli_test.cc +++ b/test/create_cli_test.cc @@ -93,7 +93,7 @@ BOOST_AUTO_TEST_CASE (create_cli_test) cc = run ("dcpomatic2_create x --still-length 42"); BOOST_CHECK (!cc.error); - BOOST_CHECK_EQUAL (cc.still_length, 42); + BOOST_CHECK_EQUAL(cc.still_length.get_value_or(0), 42); cc = run ("dcpomatic2_create x --standard SMPTE"); BOOST_CHECK (!cc.error); @@ -123,7 +123,7 @@ BOOST_AUTO_TEST_CASE (create_cli_test) BOOST_CHECK (!cc.error); BOOST_REQUIRE (cc.config_dir); BOOST_CHECK_EQUAL (*cc.config_dir, "foo/bar"); - BOOST_CHECK_EQUAL (cc.still_length, 42); + BOOST_CHECK_EQUAL(cc.still_length.get_value_or(0), 42); BOOST_REQUIRE (cc.output_dir); BOOST_CHECK_EQUAL (*cc.output_dir, "flaps"); BOOST_REQUIRE_EQUAL (cc.content.size(), 3U); @@ -190,4 +190,8 @@ BOOST_AUTO_TEST_CASE (create_cli_test) BOOST_CHECK_EQUAL(cc.content[0].path, "dcp"); BOOST_REQUIRE(static_cast<bool>(cc.content[0].cpl)); BOOST_CHECK_EQUAL(*cc.content[0].cpl, "123456-789-0"); + + cc = run("dcpomatic2_create -s SMPTE sheila.wav"); + BOOST_CHECK(!cc.still_length); + BOOST_CHECK(cc.error); } |
