11import sys
22import argparse
33from yaml import dump
4+ from .text_utils import handle_context_arg
5+ from .text_utils import handle_tag_message_args
6+ from commit_helper .conventions .karma_angular import angular_convention
7+ from commit_helper .conventions .changelog import changelog_convention
8+ from commit_helper .conventions .symphony_cmf import symphony_convention
9+
410
511supported_conventions = [
612 "angular" ,
2430def gen_co_author (co_author ):
2531 if co_author is '' :
2632 return ''
27- return " \n Co-authored-by: %s" % co_author
33+ return ' \n Co-authored-by: %s' % co_author
2834
2935
3036def create_file (convention_name , dont_create = False ): # pragma: no cover
@@ -38,23 +44,36 @@ def create_file(convention_name, dont_create=False): # pragma: no cover
3844
3945
4046def parser_cli ():
41- desc = " A commit formatter tool to help you follow commit conventions."
47+ desc = ' A commit formatter tool to help you follow commit conventions.'
4248 help_convention = \
4349 """
4450 Selects a convention to be used for the commit.
4551 Required if there's no commiter.yml file.
4652 """
4753 parser = argparse .ArgumentParser (description = desc )
48- parser .add_argument ("-ca" , "--co-author" ,
49- help = "Make your friend an co-author to the commit" ,
50- dest = "co_author" , default = '' )
51- parser .add_argument ("-nf" , "--no-file" , dest = "no_file" ,
52- help = "Disables the creation of a commiter.yml file" ,
53- action = "store_true" )
54- parser .add_argument ("-c" , "--convention" , choices = supported_conventions ,
55- dest = "convention" , default = '' , help = help_convention )
56- parser .add_argument ("-d" , "--debug" , action = "store_true" , dest = "debug" ,
57- help = "Toggles debug option" )
54+ parser .add_argument ('-t' , '--tag' , dest = 'tag' , default = '' ,
55+ help = 'Pass your commit tag directly' )
56+
57+ parser .add_argument ('-m' , '--message' , dest = 'message' , default = '' ,
58+ help = 'Pass your commit message directly' )
59+
60+ parser .add_argument ('-ct' , '--context' , dest = 'context' , default = '' ,
61+ help = 'Pass your commit context directly' )
62+
63+ parser .add_argument ('-ca' , '--co-author' ,
64+ help = 'Make your friend an co-author to the commit' ,
65+ dest = 'co_author' , default = '' )
66+
67+ parser .add_argument ('-nf' , '--no-file' , dest = 'no_file' ,
68+ help = 'Disables the creation of a commiter.yml file' ,
69+ action = 'store_true' )
70+
71+ parser .add_argument ('-c' , '--convention' , choices = supported_conventions ,
72+ dest = 'convention' , default = '' , help = help_convention )
73+
74+ parser .add_argument ('-d' , '--debug' , action = 'store_true' , dest = 'debug' ,
75+ help = 'Toggles debug option' )
76+
5877 return parser
5978
6079
@@ -69,3 +88,19 @@ def validate_commiter_file(stream_file): # pragma: no cover
6988 if stream_file ['commit_pattern' ] is None or stream_file ['context' ] is None :
7089 print ("Error: Your commiter file lacks a commit_pattern or context!" )
7190 sys .exit (0 )
91+
92+
93+ def handle_conventioned_commit (convention , args ):
94+ tag , msg = handle_tag_message_args (args .tag , args .message )
95+
96+ if convention == 'angular' or convention == 'karma' :
97+ context = handle_context_arg (args .context )
98+ commit_message = angular_convention (tag , msg , context )
99+
100+ elif convention == 'changelog' :
101+ commit_message = changelog_convention (tag , msg )
102+
103+ elif convention == 'symphony' :
104+ commit_message = symphony_convention (tag , msg )
105+
106+ return commit_message
0 commit comments