chore: make format_app.py accept path to app
prior to this change, the script accepts the app name and assumes the app is in 'apps' sub dir. however, we have lib-ee for enterprise, we may also technically have the same app reside in more than two sub-dirs e.g. lib-ce and lib-ee
This commit is contained in:
parent
a3e5ea0bc8
commit
817aa3051b
|
@ -11,7 +11,7 @@ import sys
|
||||||
|
|
||||||
def handle_cli_args():
|
def handle_cli_args():
|
||||||
parser = argparse.ArgumentParser(description='A script for formatting a given app within emqx')
|
parser = argparse.ArgumentParser(description='A script for formatting a given app within emqx')
|
||||||
parser.add_argument("-a", "--application", required=True, help="The application which is to be formatted.")
|
parser.add_argument("-a", "--application", required=True, help="The relative path to the application which is to be formatted.")
|
||||||
parser.add_argument('-b', "--branch", help="The git branch to be switched to before formatting the code. Required unless the -f option is passed in which case the value will be ignored even if provided.")
|
parser.add_argument('-b', "--branch", help="The git branch to be switched to before formatting the code. Required unless the -f option is passed in which case the value will be ignored even if provided.")
|
||||||
parser.add_argument('-f', "--format_in_place", default=False, action="store_true", help="Pass the -f option to format on the current git branch, otherwise a branch name must be provided by passing the -b option.")
|
parser.add_argument('-f', "--format_in_place", default=False, action="store_true", help="Pass the -f option to format on the current git branch, otherwise a branch name must be provided by passing the -b option.")
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
@ -24,12 +24,9 @@ def handle_cli_args():
|
||||||
|
|
||||||
def get_app_path(application):
|
def get_app_path(application):
|
||||||
root_path = os.path.dirname(os.path.realpath(__file__))
|
root_path = os.path.dirname(os.path.realpath(__file__))
|
||||||
full_path = f"{root_path}/../apps/{application}"
|
full_path = f"{root_path}/../{application}"
|
||||||
isdir = os.path.isdir(full_path)
|
if os.path.isdir(full_path):
|
||||||
|
|
||||||
if isdir:
|
|
||||||
return full_path
|
return full_path
|
||||||
|
|
||||||
sys.exit(f"The application provided ({application}) does not appear at the expected location: {full_path}")
|
sys.exit(f"The application provided ({application}) does not appear at the expected location: {full_path}")
|
||||||
|
|
||||||
|
|
||||||
|
@ -52,7 +49,7 @@ def maybe_add_rebar_plugin():
|
||||||
text = f.read()
|
text = f.read()
|
||||||
erlfmt_pattern = "\{project_plugins.+?erlfmt.+\}"
|
erlfmt_pattern = "\{project_plugins.+?erlfmt.+\}"
|
||||||
plugin_pattern = "\{project_plugins.+?\}"
|
plugin_pattern = "\{project_plugins.+?\}"
|
||||||
|
|
||||||
if not re.search(erlfmt_pattern, text) and not re.search(plugin_pattern, text):
|
if not re.search(erlfmt_pattern, text) and not re.search(plugin_pattern, text):
|
||||||
f.write("\n{project_plugins, [erlfmt]}.\n")
|
f.write("\n{project_plugins, [erlfmt]}.\n")
|
||||||
elif not re.search(erlfmt_pattern, text) and re.search(plugin_pattern, text):
|
elif not re.search(erlfmt_pattern, text) and re.search(plugin_pattern, text):
|
||||||
|
@ -70,7 +67,7 @@ def main():
|
||||||
maybe_switch_git_branch(args.format_in_place, args.branch)
|
maybe_switch_git_branch(args.format_in_place, args.branch)
|
||||||
maybe_add_rebar_plugin()
|
maybe_add_rebar_plugin()
|
||||||
execute_formatting()
|
execute_formatting()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in New Issue