11import json
2+ import argparse
23from pathlib import Path
34
45
@@ -9,13 +10,15 @@ def __load_json(path: str):
910 return raw_json
1011
1112
12- def create_file (file_data : dict , is_ext : bool ):
13+ def create_file (file_data : dict , is_ext : bool , verbose : bool ):
1314 """ファイルを作成します
1415
1516 :param file_data: テーマから抽出したファイル情報
1617 :type file_data: dict
1718 :param is_ext: 拡張子用のファイルか否か
1819 :type is_ext: bool
20+ :param verbose: 詳細表示か否か
21+ :type verbose: bool
1922 """
2023 current = Path ("files" )
2124 if not current .is_dir ():
@@ -24,7 +27,9 @@ def create_file(file_data: dict, is_ext: bool):
2427 file_path = (
2528 current .joinpath (f"DummyName.{ key } " ) if is_ext else current .joinpath (key )
2629 )
27- if file_path .is_file ():
30+ if not verbose :
31+ continue
32+ elif file_path .is_file ():
2833 print (f"skip: { str (file_path )} " )
2934 continue
3035 else :
@@ -33,18 +38,22 @@ def create_file(file_data: dict, is_ext: bool):
3338 print (f"create: { str (file_path )} " )
3439
3540
36- def create_folder (folder_data : dict ):
41+ def create_folder (folder_data : dict , verbose : bool ):
3742 """フォルダを作成します。フォルダだけだとgit管理に含まれないのでからのファイルをフォルダ内に作っておきます。
3843
3944 :param folder_info_json: _description_
4045 :type folder_info_json: dict
46+ :param verbose: 詳細表示か否か
47+ :type verbose: bool
4148 """
4249 current = Path ("folders" )
4350 if not current .is_dir ():
4451 current .mkdir ()
4552 for folder_name in folder_data .keys ():
4653 folder_path = current .joinpath (folder_name )
47- if folder_path .is_dir ():
54+ if not verbose :
55+ continue
56+ elif folder_path .is_dir ():
4857 print (f"skip: { str (folder_path )} " )
4958 continue
5059 else :
@@ -54,15 +63,26 @@ def create_folder(folder_data: dict):
5463 print (f"create: { folder_path } " )
5564
5665
57- def main ():
66+ def create_parser ():
67+ parser = argparse .ArgumentParser ()
68+ parser .add_argument ("-v" , "--verbose" , action = "store_true" )
69+ return parser
70+
71+
72+ def main (args = None ):
73+ parser = create_parser ()
74+ args = parser .parse_args (args )
75+
76+ verbose = args .verbose
77+
5878 file_data = __load_json ("./manifests/files.json" )
59- create_file (file_data , False )
79+ create_file (file_data , False , verbose )
6080
6181 ext_data = __load_json ("./manifests/extensions.json" )
62- create_file (ext_data , True )
82+ create_file (ext_data , True , verbose )
6383
6484 folder_data = __load_json ("./manifests/folders.json" )
65- create_folder (folder_data )
85+ create_folder (folder_data , verbose )
6686
6787
6888if __name__ == "__main__" :
0 commit comments