diff --git a/d4science_copernicus/auth_cds.py b/d4science_copernicus/auth_cds.py index ee5e3dc..a8bddb2 100644 --- a/d4science_copernicus/auth_cds.py +++ b/d4science_copernicus/auth_cds.py @@ -3,11 +3,14 @@ import os import cdsapi import argparse +# Version of the library +__version__ = "1.0.0" def cds_help(): """Provide instructions on how to use methods programmatically from Jupyter.""" help_message = ''' CDS Authentication Helper - Jupyter Usage Guide + Version: %s Available Functions: --------------------- @@ -34,7 +37,7 @@ def cds_help(): 5. Show current configuration from environment and files: cds_show_conf() - ''' + ''' % __version__ print(help_message) class AuthCDS: @@ -229,7 +232,10 @@ def cds_show_conf(verbose=True): def main(): parser = argparse.ArgumentParser( - description="Authenticate with CDS and configure .cdsapirc") + description="""Authenticate with CDS and configure .cdsapirc + Version: {__version__}""", + add_help=False + ) parser.add_argument( "-v", "--verbose", action="store_true", @@ -261,8 +267,35 @@ def main(): action="store_true", help="Print current configuration from environment and files" ) + parser.add_argument( + "-h", "--help", + action="store_true", + help="Display help information with usage examples" + ) args = parser.parse_args() + + if not any(vars(args).values()): + print("CDS Authentication CLI") + print("Version: %s" % __version__) + print("----------------------") + print("Usage:") + print(" python auth_cds.py [OPTIONS]") + print("Options:") + print(" -v, --verbose Enable verbose mode for detailed logging") + print(" -a, --authenticate Run authentication and set environment variables") + print(" -s, --save-config PATH Save configuration to a specific file path") + print(" -r, --remove-config Remove saved configurations from default paths") + print(" -q, --query-credentials Prompt user to re-enter credentials") + print(" -p, --print-config Print current configuration from environment and files") + print(" -h, --help Display this help information with usage examples") + print("Run with -h or --help to see examples and additional information.") + return + + if args.help: + cds_help() + return + auth = AuthCDS(verbose=args.verbose) if args.authenticate: @@ -292,3 +325,6 @@ def main(): env_config, file_config = auth.show_credentials() auth.log(f"Environment Config: {env_config}") auth.log(f"File Config: {file_config}") + +if __name__ == "__main__": + main() \ No newline at end of file