You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(main): add token retrieval and validation for API authentication
This update introduces a new function `get_token` that retrieves the API token based on priority from three sources: a passed parameter, an environment variable, and a configuration file. The main command-line interface (CLI) has been updated to utilize this function, ensuring that the API token is validated before executing subcommands such as installing hooks, generating documentation, and committing changes. This change improves the user experience by providing clear error messages when the API token is not provided, enhancing the overall robustness of the Penify CLI tool.
parser=argparse.ArgumentParser(description="Penify CLI tool for managing Git hooks and generating documentation.")
204
232
233
+
parser.add_argument("-t", "--token", help="API token for authentication. If not provided, will check PENIFY_API_TOKEN environment variable, then .penify config file.")
install_parser=subparsers.add_parser("install-hook", help="Install the Git post-commit hook.")
209
239
install_parser.add_argument("-l", "--location", required=True, help="Location in which to install the Git hook.")
210
-
install_parser.add_argument("-t", "--token", help="API token for authentication. If not provided, the environment variable 'PENIFY_API_TOKEN' will be used.", default=os.getenv('PENIFY_API_TOKEN'))
211
240
212
241
# Subcommand: uninstall-hook
213
242
uninstall_parser=subparsers.add_parser("uninstall-hook", help="Uninstall the Git post-commit hook.")
214
243
uninstall_parser.add_argument("-l", "--location", required=True, help="Location from which to uninstall the Git hook.")
215
244
216
245
# Subcommand: doc-gen
217
246
doc_gen_parser=subparsers.add_parser("doc-gen", help="Generate documentation for specified files or folders.")
218
-
doc_gen_parser.add_argument("-t", "--token", help="API token for authentication. If not provided, the environment variable 'PENIFY_API_TOKEN' will be used.", default=os.getenv('PENIFY_API_TOKEN'))
219
247
doc_gen_parser.add_argument("-fl", "--file_path", help="Path of the file to generate documentation.")
220
248
doc_gen_parser.add_argument("-cf", "--complete_folder_path", help="Generate documentation for the entire folder.")
221
249
doc_gen_parser.add_argument("-gf", "--git_folder_path", help="Path to the folder, with git, to scan for modified files. Defaults to the current folder.", default=os.getcwd())
222
250
223
251
# Subcommand: commit
224
252
commit_parser=subparsers.add_parser("commit", help="Commit with a message.")
225
253
commit_parser.add_argument("-gf", "--git_folder_path", help="Path to the folder, with git, to scan for modified files. Defaults to the current folder.", default=os.getcwd())
226
-
commit_parser.add_argument("-t", "--token", help="API token for authentication. If not provided, the environment variable 'PENIFY_API_TOKEN' will be used.", default=os.getenv('PENIFY_API_TOKEN'))
0 commit comments