Repository: dogancanbakir/pirebok (language: python)

Issue:
add cli support
add cli support for random fuzzer


Discussion / hints:

Fix patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b9c237a..50c3aeb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,4 +7,5 @@
 - Random comment rewriting transformer
 - Random comment removing transformer
 - Random number encoding transformer
+- Add CLI support
 - Random fuzzer
diff --git a/pirebok/__init__.py b/pirebok/__init__.py
index d67f1d2..b28fb7b 100644
--- a/pirebok/__init__.py
+++ b/pirebok/__init__.py
@@ -1,3 +1,5 @@
 __author__ = """Doğan Can Bakır"""
 __email__ = 'dogancanbakir@protonmail.com'
 __version__ = '0.1.0'
+
+from pirebok.pirebok import random_fuzzer
diff --git a/pirebok/cli.py b/pirebok/cli.py
index 495ad48..4751946 100644
--- a/pirebok/cli.py
+++ b/pirebok/cli.py
@@ -1,13 +1,18 @@
 import click
 
+from pirebok.pirebok import random_fuzzer
+
 
 @click.command(no_args_is_help=True)
+@click.option('-r', '--random', default=True, help="choose random fuzzer (default)")
 @click.option('-p', '--payload', help="payload to fuzz")
-def main(payload):
+def main(payload: str, random: bool) -> None:
     if not payload:
         raise ValueError("payload is required.")
 
-    click.echo("")
+    if random:
+        fuzzer = random_fuzzer()
+        click.echo(fuzzer.fuzz(payload))
 
 
 if __name__ == "__main__":
diff --git a/pirebok/fuzzers/__init__.py b/pirebok/fuzzers/__init__.py
index e69de29..ea8bc96 100644
--- a/pirebok/fuzzers/__init__.py
+++ b/pirebok/fuzzers/__init__.py
@@ -0,0 +1,2 @@
+from pirebok.fuzzers.fuzzer import Fuzzer
+from pirebok.fuzzers.random_fuzzer import RandomFuzzer
diff --git a/pirebok/fuzzers/random_fuzzer.py b/pirebok/fuzzers/random_fuzzer.py
index d4031ea..87938ed 100644
--- a/pirebok/fuzzers/random_fuzzer.py
+++ b/pirebok/fuzzers/random_fuzzer.py
@@ -1,8 +1,8 @@
 import random
 from typing import List
 
-from pirebok.fuzzers.fuzzer import Fuzzer
-from pirebok.transformers.transformer import Transformer
+from pirebok.fuzzers import Fuzzer
+from pirebok.transformers import Transformer
 
 
 class RandomFuzzer(Fuzzer):
diff --git a/pirebok/pirebok.py b/pirebok/pirebok.py
index e69de29..362ec1d 100644
--- a/pirebok/pirebok.py
+++ b/pirebok/pirebok.py
@@ -0,0 +1,7 @@
+from pirebok.fuzzers import Fuzzer, RandomFuzzer
+from pirebok.transformers import Transformer
+
+
+def random_fuzzer() -> Fuzzer:
+    transformers = [cls() for cls in Transformer.__subclasses__()]  # type: ignore
+    return RandomFuzzer(transformers)
diff --git a/pirebok/transformers/__init__.py b/pirebok/transformers/__init__.py
index e69de29..ef206eb 100644
--- a/pirebok/transformers/__init__.py
+++ b/pirebok/transformers/__init__.py
@@ -0,0 +1,6 @@
+from pirebok.transformers.random_case_swapping_transformer import RandomCaseSwappingTransformer
+from pirebok.transformers.random_comment_removing_transformer import RandomCommentRemovingTransformer
+from pirebok.transformers.random_comment_rewriting_transformer import RandomCommentRewritingTransformer
+from pirebok.transformers.random_number_encoding_transformer import RandomNumberEncodingTransformer
+from pirebok.transformers.random_space_substitution_transformer import RandomSpaceSubstitutionTransformer
+from pirebok.transformers.transformer import Transformer


Test patch:
diff --git a/tests/test_random_case_swapping_transformer.py b/tests/test_random_case_swapping_transformer.py
index 3a17f79..7f4aef3 100644
--- a/tests/test_random_case_swapping_transformer.py
+++ b/tests/test_random_case_swapping_transformer.py
@@ -1,7 +1,6 @@
 import pytest
 
-from pirebok.transformers.random_case_swapping_transformer import RandomCaseSwappingTransformer
-from pirebok.transformers.transformer import Transformer
+from pirebok.transformers import RandomCaseSwappingTransformer, Transformer
 
 
 @pytest.fixture
diff --git a/tests/test_random_comment_removing_transformer.py b/tests/test_random_comment_removing_transformer.py
index 2da3a07..f35b790 100644
--- a/tests/test_random_comment_removing_transformer.py
+++ b/tests/test_random_comment_removing_transformer.py
@@ -1,7 +1,6 @@
 import pytest
 
-from pirebok.transformers.random_comment_removing_transformer import RandomCommentRemovingTransformer
-from pirebok.transformers.transformer import Transformer
+from pirebok.transformers import RandomCommentRemovingTransformer, Transformer
 
 
 @pytest.fixture
diff --git a/tests/test_random_comment_rewriting_transformer.py b/tests/test_random_comment_rewriting_transformer.py
index 43810a9..f76f135 100644
--- a/tests/test_random_comment_rewriting_transformer.py
+++ b/tests/test_random_comment_rewriting_transformer.py
@@ -1,7 +1,6 @@
 import pytest
 
-from pirebok.transformers.random_comment_rewriting_transformer import RandomCommentRewritingTransformer
-from pirebok.transformers.transformer import Transformer
+from pirebok.transformers import RandomCommentRewritingTransformer, Transformer
 
 
 @pytest.fixture
diff --git a/tests/test_random_number_encoding_transformer.py b/tests/test_random_number_encoding_transformer.py
index 2ba5020..9ef0681 100644
--- a/tests/test_random_number_encoding_transformer.py
+++ b/tests/test_random_number_encoding_transformer.py
@@ -1,7 +1,6 @@
 import pytest
 
-from pirebok.transformers.random_number_encoding_transformer import RandomNumberEncodingTransformer
-from pirebok.transformers.transformer import Transformer
+from pirebok.transformers import RandomNumberEncodingTransformer, Transformer
 
 
 @pytest.fixture
diff --git a/tests/test_random_space_substitution_transformer.py b/tests/test_random_space_substitution_transformer.py
index 98ee2ce..312f496 100644
--- a/tests/test_random_space_substitution_transformer.py
+++ b/tests/test_random_space_substitution_transformer.py
@@ -1,7 +1,6 @@
 import pytest
 
-from pirebok.transformers.random_space_substitution_transformer import RandomSpaceSubstitutionTransformer
-from pirebok.transformers.transformer import Transformer
+from pirebok.transformers import RandomSpaceSubstitutionTransformer, Transformer
 
 
 @pytest.fixture