Impl --yes flag
This commit is contained in:
@@ -347,6 +347,10 @@ def ensureUnmuxOutputDirectory(context, outputDirectory):
|
|||||||
if context.get('dry_run', False):
|
if context.get('dry_run', False):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
if context.get('yes', False):
|
||||||
|
os.makedirs(resolvedOutputDirectory, exist_ok=True)
|
||||||
|
return True
|
||||||
|
|
||||||
if not confirmUnmuxOutputDirectoryCreation(resolvedOutputDirectory):
|
if not confirmUnmuxOutputDirectoryCreation(resolvedOutputDirectory):
|
||||||
raise click.ClickException("Unmux output directory creation aborted by user.")
|
raise click.ClickException("Unmux output directory creation aborted by user.")
|
||||||
|
|
||||||
@@ -876,6 +880,12 @@ def getUnmuxSequence(trackDescriptor: TrackDescriptor, sourcePath, targetPrefix,
|
|||||||
@click.option('-l', '--label', type=str, default='', help='Label to be used as filename prefix')
|
@click.option('-l', '--label', type=str, default='', help='Label to be used as filename prefix')
|
||||||
@click.option("-o", "--output-directory", type=str, default='', help=UNMUX_OUTPUT_DIRECTORY_OPTION_HELP)
|
@click.option("-o", "--output-directory", type=str, default='', help=UNMUX_OUTPUT_DIRECTORY_OPTION_HELP)
|
||||||
@click.option("-s", "--subtitles-only", is_flag=True, default=False)
|
@click.option("-s", "--subtitles-only", is_flag=True, default=False)
|
||||||
|
@click.option(
|
||||||
|
"--yes",
|
||||||
|
is_flag=True,
|
||||||
|
default=False,
|
||||||
|
help="Create a missing unmux output directory without prompting.",
|
||||||
|
)
|
||||||
@click.option(
|
@click.option(
|
||||||
'--nice',
|
'--nice',
|
||||||
type=int,
|
type=int,
|
||||||
@@ -897,6 +907,7 @@ def unmux(ctx,
|
|||||||
label,
|
label,
|
||||||
output_directory,
|
output_directory,
|
||||||
subtitles_only,
|
subtitles_only,
|
||||||
|
yes,
|
||||||
nice,
|
nice,
|
||||||
cpu):
|
cpu):
|
||||||
from ffx.file_properties import FileProperties
|
from ffx.file_properties import FileProperties
|
||||||
@@ -912,6 +923,7 @@ def unmux(ctx,
|
|||||||
ctx.obj['resource_limits']['niceness'] = nice
|
ctx.obj['resource_limits']['niceness'] = nice
|
||||||
ctx.obj['resource_limits']['cpu_limit'] = cpu
|
ctx.obj['resource_limits']['cpu_limit'] = cpu
|
||||||
ctx.obj['resource_limits']['cpu_percent'] = cpu
|
ctx.obj['resource_limits']['cpu_percent'] = cpu
|
||||||
|
ctx.obj['yes'] = bool(yes)
|
||||||
|
|
||||||
output_directory, requires_output_directory = resolveUnmuxOutputDirectory(
|
output_directory, requires_output_directory = resolveUnmuxOutputDirectory(
|
||||||
ctx.obj,
|
ctx.obj,
|
||||||
|
|||||||
@@ -174,10 +174,10 @@ class UnmuxCliTests(unittest.TestCase):
|
|||||||
self.home_dir,
|
self.home_dir,
|
||||||
self.database_path,
|
self.database_path,
|
||||||
"--subtitles-only",
|
"--subtitles-only",
|
||||||
|
"--yes",
|
||||||
"--label",
|
"--label",
|
||||||
"dball",
|
"dball",
|
||||||
str(source_path),
|
str(source_path),
|
||||||
input_text="y\n",
|
|
||||||
)
|
)
|
||||||
self.assertCompleted(completed)
|
self.assertCompleted(completed)
|
||||||
|
|
||||||
|
|||||||
@@ -122,6 +122,20 @@ class UnmuxOutputDirectoryTests(unittest.TestCase):
|
|||||||
mocked_getchar.assert_called_once()
|
mocked_getchar.assert_called_once()
|
||||||
mocked_confirm.assert_not_called()
|
mocked_confirm.assert_not_called()
|
||||||
|
|
||||||
|
def test_yes_creates_missing_output_directory_without_prompt(self):
|
||||||
|
with tempfile.TemporaryDirectory() as tempdir:
|
||||||
|
output_directory = Path(tempdir) / "missing" / "parents" / "manual"
|
||||||
|
|
||||||
|
with patch("ffx.cli.click.confirm") as mocked_confirm:
|
||||||
|
created = cli.ensureUnmuxOutputDirectory(
|
||||||
|
{"dry_run": False, "yes": True},
|
||||||
|
str(output_directory),
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertTrue(created)
|
||||||
|
self.assertTrue(output_directory.is_dir())
|
||||||
|
mocked_confirm.assert_not_called()
|
||||||
|
|
||||||
def test_missing_output_directory_can_be_rejected(self):
|
def test_missing_output_directory_can_be_rejected(self):
|
||||||
with tempfile.TemporaryDirectory() as tempdir:
|
with tempfile.TemporaryDirectory() as tempdir:
|
||||||
output_directory = Path(tempdir) / "missing" / "manual"
|
output_directory = Path(tempdir) / "missing" / "manual"
|
||||||
|
|||||||
Reference in New Issue
Block a user