Skip to content

Commit afb20a2

Browse files
committed
add(flag support): support to --no-generate and --convention
Co-authored-by:
1 parent a6f19df commit afb20a2

File tree

7 files changed

+37
-35
lines changed

7 files changed

+37
-35
lines changed

conventions/changelog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from utils import change_if_none
44

55

6-
def changelog_convention(co_author):
6+
def changelog_convention(co_author=''):
77
tag, msg = get_text()
88
tag = tag.upper()
99
co_author = change_if_none(co_author)

conventions/karma_angular.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from utils import change_if_none
44

55

6-
def angular_convention(co_author):
6+
def angular_convention(co_author=''):
77
tag, msg, context = get_text(context=True)
88
tag = tag.lower()
99
co_author = change_if_none(co_author)

conventions/no_convention.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from utils import change_if_none
33

44

5-
def just_message(co_author):
5+
def just_message(co_author=''):
66
msg = str(input("commit message: "))
77
co_author = change_if_none(co_author)
88
composed = """%s\n\nCo-authored-by: """ % msg.capitalize()

conventions/symphony_cmf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from utils import change_if_none
44

55

6-
def symphony_convention(co_author):
6+
def symphony_convention(co_author=''):
77
tag, msg = get_text()
88
tag = tag.capitalize()
99
co_author = change_if_none(co_author)

generator.py

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@
1717
from utils import create_file
1818

1919

20-
# TODO:
21-
# - add support to --convention flag
22-
# - add support to --no-generate flag
23-
2420
parser = parser_cli()
2521
args = parser.parse_args()
2622

@@ -46,22 +42,21 @@
4642
just_message(args.co_author)
4743
except YAMLError as exc:
4844
print(exc)
49-
else:
50-
print("No config files found!\nRunning default script...")
51-
opt = int(input(menu) or 4)
52-
if opt == 1:
53-
print("You're using the angular convention")
45+
46+
elif args.convention is not '':
47+
convention = str(args.convention)
48+
if convention == 'angular' or convention == 'karma':
5449
angular_convention(parser.co_author)
55-
create_file('angular')
56-
elif opt == 2:
57-
print("You're using the changelog convention")
58-
changelog_convention(args.co_author)
59-
create_file('changelog')
60-
elif opt == 3:
61-
print("You're using the symphony convention")
50+
create_file(convention, args.no_file)
51+
elif convention == 'changelog':
52+
changelog_convention(parser.co_author)
53+
create_file(convention, args.no_file)
54+
elif convention == 'symphony':
6255
symphony_convention(args.co_author)
63-
create_file('symphony')
64-
elif opt == 4:
65-
print("You're not using a convention")
66-
just_message(args.co_author)
67-
create_file('none')
56+
create_file(convention, args.no_file)
57+
elif convention == 'message':
58+
just_message(convention)
59+
create_file('none', args.no_file)
60+
61+
else:
62+
parser.print_help()

test/test_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def mock_input(s):
3636
if not c == 'context':
3737
raise AssertionError()
3838

39+
3940
def test_change_if_none():
4041
string = 'asopdfha'
4142
string2 = None

utils.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"angular",
66
"changelog",
77
"symphony",
8-
"message_only",
8+
"message",
99
]
1010

1111
menu = """
@@ -31,25 +31,31 @@ def get_text(context=False):
3131
return tag, msg
3232

3333

34-
def create_file(convention_name):
35-
data = dict(
36-
convention=convention_name
37-
)
38-
with open('commiter.yml', 'w') as output_file:
39-
dump(data, output_file, default_flow_style=False)
34+
def create_file(convention_name, dont_create=False):
35+
if not dont_create:
36+
data = dict(
37+
convention=convention_name
38+
)
39+
with open('commiter.yml', 'w') as output_file:
40+
dump(data, output_file, default_flow_style=False)
4041

4142

4243
def parser_cli():
43-
parser = argparse.ArgumentParser()
44+
desc = "A commit formatter tool to help you follow commit conventions."
45+
help_convention = \
46+
"""
47+
Selects a convention to be used for the commit.
48+
Required if there's no commiter.yml file.
49+
"""
50+
parser = argparse.ArgumentParser(description=desc)
4451
parser.add_argument("--co-author",
4552
help="make your friend an co-author to the commit",
4653
dest="co_author", default=None)
4754
parser.add_argument("--no-generate", dest="no_file",
4855
help="disables the creation of a commiter.yml file",
4956
default=True, type=bool)
5057
parser.add_argument("--convention", choices=supported_conventions,
51-
dest="convention",
52-
help="selects a convention to be used for the commit")
58+
dest="convention", default='', help=help_convention)
5359
return parser
5460

5561

0 commit comments

Comments
 (0)