Give an error if a non-number is passed to dcpomatic2_create -s (#2488).
authorCarl Hetherington <cth@carlh.net>
Mon, 10 Apr 2023 22:54:13 +0000 (00:54 +0200)
committerCarl Hetherington <cth@carlh.net>
Tue, 11 Apr 2023 18:31:45 +0000 (20:31 +0200)
src/lib/create_cli.cc
src/lib/create_cli.h
src/tools/dcpomatic_create.cc
test/create_cli_test.cc

index 2cbff6e85bc2900ec6342cccb72e7d6371d00905..81e35389383383c870ef1cc529a05425f15a7b41 100644 (file)
@@ -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);
index e473be1f2844a84c64d215f82376f70ee307ba23..58f7cf20c151f1bcf6ebcdacb126f8b56c7cc56e 100644 (file)
@@ -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;
index bd059e9f8e68a0c6d2250bf30fc5f40fb079ed72..caaba6b3808ba90b8a0ab7ad49633828b8e5459e 100644 (file)
@@ -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);
                        }
                }
 
index 71281a63e34630cc40d7684ee45ab4a17f6044b5..3bc819604e17dd5519842ac4739b016329ce9372 100644 (file)
@@ -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);
 }