Skip to content

Commit

Permalink
feat(input-file): add input-file flag (#50)
Browse files Browse the repository at this point in the history
## What type of PR is this? (check all applicable)

- [x] πŸ• Feature
- [ ] πŸ› Bug Fix
- [ ] πŸ“ Documentation Update
- [ ] 🎨 Style
- [ ] πŸ§‘β€πŸ’» Code Refactor
- [ ] πŸ”₯ Performance Improvements
- [ ] βœ… Test
- [ ] πŸ€– Build
- [ ] πŸ” CI
- [ ] πŸ“¦ Chore (Release)
- [ ] ⏩ Revert

## Description

Add `-i` to add precise input file rather than basic data.json file

## Related Tickets & Documents

#7 

## Added tests?

- [ ] πŸ‘ yes
- [x] πŸ™… no, because they aren't needed
- [ ] πŸ™‹ no, because I need help

(Ps: I tested locally, I know that it isn't the best way to check if the
feature works, but currently it's very hard to make functionnal tests)
  • Loading branch information
Miou-zora authored Jul 10, 2023
1 parent b02460c commit d498d7c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
5 changes: 4 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ def check_all(github: Github, sshParser: SshKeyRepositoryParserEpitech, mirror_n

def main():
args = argumentManager()
json_file = json.load(open("data.json"))
input_file = "data.json"
if args.input_file is not None:
input_file = args.input_file[0]
json_file = json.load(open(input_file))
if (json_file["token"] == "[your token]"):
print(f"{bcolors.FAIL}You need to change the token in data.json{bcolors.ENDC}")
exit(84)
Expand Down
1 change: 1 addition & 0 deletions src/argument_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def argumentManager():
parser.add_argument("--friend", "-f", nargs=1, action="extend", help="Can add friend to mirror repository.")
parser.add_argument("--mirror-name", "-m", nargs=1, help="Change the mirror repository name.")
parser.add_argument("--commit", "-o", nargs=1, help="change the first commit push to the main repository")
parser.add_argument("--input-file", "-i", nargs=1, help="Input file to be used to generate the mirror repository.")
parser.add_argument("sshKey", nargs=1, help="SSH key(s) to be added to the mirror repository.")
parsed_args = parser.parse_args()
if parsed_args.friend:
Expand Down
23 changes: 22 additions & 1 deletion src/test/test_argument_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ def compare_input_expected(self, stdin_args: list[str], expected: dict):
if value not in param_expected:
param_expected[value] = self.all_parameters[value]
namespace_param_expected: Namespace = Namespace(**param_expected)
self.assertEqual(namespace_param_expected, param_result)
for value in namespace_param_expected.__dict__:
self.assertEqual(namespace_param_expected.__dict__[value], param_result.__dict__[value])

def test_help_flag(self):
with self.assertRaises(SystemExit) as se:
Expand Down Expand Up @@ -113,3 +114,23 @@ def test_multiple_flag(self):
stdin_args: list[str] = ["main.py", "ssh", "-m", "mirrorNameTest", "-f", "friendTest", "-o", "commitTest"]
expected: dict = {"sshKey": ["ssh"], "mirror_name": ["mirrorNameTest"], "friend": ["friendTest"], "commit": ["commitTest"]}
self.compare_input_expected(stdin_args, expected)

def test_one_long_flag_input_file(self):
stdin_args: list[str] = ["main.py", "ssh", "--input-file", "inputFileTest"]
expected: dict = {"sshKey": ["ssh"], "input_file": ["inputFileTest"]}
self.compare_input_expected(stdin_args, expected)

def test_one_short_flag_input_file(self):
stdin_args: list[str] = ["main.py", "ssh", "-i", "inputFileTest"]
expected: dict = {"sshKey": ["ssh"], "input_file": ["inputFileTest"]}
self.compare_input_expected(stdin_args, expected)

def test_multiple_flag_input_file(self):
stdin_args: list[str] = ["main.py", "ssh", "-i", "inputFileTest0", "-i", "inputFileTest1"]
expected: dict = {"sshKey": ["ssh"], "input_file": ["inputFileTest1"]}
self.compare_input_expected(stdin_args, expected)

def test_multiple_same_flag_input_file(self):
stdin_args: list[str] = ["main.py", "ssh", "-i", "inputFileTest", "-i", "inputFileTest"]
expected: dict = {"sshKey": ["ssh"], "input_file": ["inputFileTest"]}
self.compare_input_expected(stdin_args, expected)

0 comments on commit d498d7c

Please sign in to comment.