From 6d0f1c43848e628524f92ef6ea334943d843b7f6 Mon Sep 17 00:00:00 2001
From: Pavel Bitiukov <bp72@users.noreply.github.com>
Date: Fri, 10 Nov 2023 20:43:30 +0000
Subject: [PATCH] Add support for passing the .toml config in the arguments
 (#285)

---
 autoflake.py      |  6 +++++-
 test_autoflake.py | 22 ++++++++++++++++++++++
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/autoflake.py b/autoflake.py
index 6d42f16..13e3136 100755
--- a/autoflake.py
+++ b/autoflake.py
@@ -1251,7 +1251,11 @@ def merge_configuration_file(
 
     if "config_file" in flag_args:
         config_file = pathlib.Path(flag_args["config_file"]).resolve()
-        config = process_config_file(str(config_file))
+        process_method = process_config_file
+        if config_file.suffix == ".toml":
+            process_method = process_pyproject_toml
+
+        config = process_method(str(config_file))
 
         if not config:
             _LOGGER.error(
diff --git a/test_autoflake.py b/test_autoflake.py
index ad3315a..9971639 100755
--- a/test_autoflake.py
+++ b/test_autoflake.py
@@ -3389,6 +3389,28 @@ def test_config_option(self) -> None:
                 check=True,
             )
 
+    def test_merge_configuration_file__toml_config_option(self) -> None:
+        with temporary_file(
+            suffix=".toml",
+            contents=("[tool.autoflake]\n" "check = true\n"),
+        ) as temp_config:
+            self.create_file("test_me.py")
+            files = [self.effective_path("test_me.py")]
+
+            args, success = autoflake.merge_configuration_file(
+                {
+                    "files": files,
+                    "config_file": temp_config,
+                },
+            )
+
+            assert success is True
+            assert args == self.with_defaults(
+                files=files,
+                config_file=temp_config,
+                check=True,
+            )
+
     def test_load_false(self) -> None:
         self.create_file("test_me.py")
         self.create_file(