1414
1515DEFAULT_PROJECT_LANGUAGE = "c"
1616DEFAULT_PROJECT_DIRECTORY = R"~/Documents/Coding/{language_name}/leetcode/"
17+ DEFAULT_COMMIT_MESSAGE = "initialise project {problem_name}"
1718
1819
1920@click .command ()
3233 "-l" ,
3334 help = "The language of the code to generate." ,
3435 default = DEFAULT_PROJECT_LANGUAGE ,
36+ show_default = True ,
3537)
3638@click .option (
3739 "--directory" ,
3840 "-d" ,
3941 help = "The directory for the project to be created in." ,
4042 default = DEFAULT_PROJECT_DIRECTORY ,
43+ show_default = True ,
4144)
4245@click .option (
4346 "--force" ,
4447 "-f" ,
4548 help = "Force-creates the project directory even if it already exists." ,
4649 default = False ,
4750 is_flag = True ,
48- show_default = True ,
4951)
5052@click .option (
5153 "--git-init" ,
5254 "-g" ,
5355 help = "Initialises a git repository in the project directory." ,
5456 default = False ,
5557 is_flag = True ,
56- show_default = False ,
58+ )
59+ @click .option (
60+ "--git-commit" ,
61+ "-c" ,
62+ help = (
63+ "Creates an initial commit in the project directory. "
64+ "Can be used without --git-init if you have a parent repository."
65+ ),
66+ default = False ,
67+ is_flag = True ,
68+ )
69+ @click .option (
70+ "--git-commit-message" ,
71+ "-m" ,
72+ help = (
73+ "Creates an initial commit in the project directory. "
74+ "Can be used without --git-init if you have a parent repository already."
75+ ),
76+ default = DEFAULT_COMMIT_MESSAGE ,
77+ show_default = True ,
5778)
5879@click .help_option ("--help" , "-h" )
5980@click .argument ("url_or_slug" , required = False )
60- def lpg (
81+ def lpg ( # pylint: disable=too-many-arguments, too-many-positional-arguments
6182 url_or_slug : str | None = None ,
6283 title_slug : str | None = None ,
6384 url : str | None = None ,
6485 lang : str = DEFAULT_PROJECT_LANGUAGE ,
6586 directory : str = DEFAULT_PROJECT_DIRECTORY ,
6687 force : bool = True ,
6788 git_init : bool = False ,
89+ git_commit : bool = False ,
90+ git_commit_message : str = DEFAULT_COMMIT_MESSAGE ,
6891):
6992 """Creates a LeetCode skeleton project from the given problem URL or
7093 title slug in the specified programming language."""
@@ -78,7 +101,14 @@ def lpg(
78101 title_slug , template_data = get_leetcode_template (lang , title_slug , url )
79102 path = create_project (title_slug , directory , template_data , force )
80103 if git_init :
81- subprocess .run ("git init" , check = True )
104+ subprocess .run (["git" , "init" ], check = True )
105+ if git_commit :
106+ subprocess .run (["git" , "add" , "." ], check = True )
107+ subprocess .run (
108+ ["git" , "commit" , "-m" , git_commit_message .format (problem_name = title_slug )],
109+ check = False ,
110+ )
111+
82112 click .echo (f"Successfully created project at { path } !" )
83113
84114
0 commit comments