From 918c7a8a6d8fde839b0ed8b9db9c01e3d33d3bbd Mon Sep 17 00:00:00 2001 From: Willi Date: Fri, 29 Nov 2024 16:53:26 +0100 Subject: [PATCH] Add epilog in commands help to link to arlas_cli documentation --- arlas/cli/collections.py | 25 ++++++++++++------------ arlas/cli/configurations.py | 10 +++++----- arlas/cli/index.py | 19 +++++++++--------- arlas/cli/org.py | 39 +++++++++++++++++++++---------------- arlas/cli/persist.py | 12 ++++++------ arlas/cli/user.py | 8 ++++---- arlas/cli/variables.py | 3 ++- 7 files changed, 62 insertions(+), 54 deletions(-) diff --git a/arlas/cli/collections.py b/arlas/cli/collections.py index 1a12eb2..0bab4b4 100644 --- a/arlas/cli/collections.py +++ b/arlas/cli/collections.py @@ -16,14 +16,15 @@ def configuration(config: str = typer.Option(default=None, help="Name of the ARL variables["arlas"] = Configuration.solve_config(config) -@collections.command(help="List collections", name="list") +@collections.command(help="List collections", name="list", epilog=variables["help_epilog"]) def list_collections(): config = variables["arlas"] collections = Service.list_collections(config) __print_table(collections[0], collections[1:], sortby="name") -@collections.command(help="Count the number of hits within a collection (or all collection if not provided)") +@collections.command(help="Count the number of hits within a collection (or all collection if not provided)", + epilog=variables["help_epilog"]) def count( collection: str = typer.Argument(default=None, help="Collection's name") ): @@ -32,7 +33,7 @@ def count( __print_table(count[0], count[1:], sortby="collection name") -@collections.command(help="Describe a collection") +@collections.command(help="Describe a collection", epilog=variables["help_epilog"]) def describe( collection: str = typer.Argument(help="Collection's name") ): @@ -44,7 +45,7 @@ def describe( __print_table(fields[0], fields[1:], sortby=None) -@collections.command(help="Set collection visibility to public") +@collections.command(help="Set collection visibility to public", epilog=variables["help_epilog"]) def public( collection: str = typer.Argument(help="Collection's name") ): @@ -53,7 +54,7 @@ def public( print("{} is {}".format(collection, "public" if ispublic else "private")) -@collections.command(help="Set collection visibility to private") +@collections.command(help="Set collection visibility to private", epilog=variables["help_epilog"]) def private( collection: str = typer.Argument(help="Collection's name") ): @@ -62,7 +63,7 @@ def private( print("{} is {}".format(collection, "public" if ispublic else "private")) -@collections.command(help="Share the collection with the organisation") +@collections.command(help="Share the collection with the organisation", epilog=variables["help_epilog"]) def share( collection: str = typer.Argument(help="Collection's name"), organisation: str = typer.Argument(help="Organisation's name") @@ -72,7 +73,7 @@ def share( print("{} is shared with {}".format(collection, ", ".join(shared))) -@collections.command(help="Unshare the collection with the organisation") +@collections.command(help="Unshare the collection with the organisation", epilog=variables["help_epilog"]) def unshare( collection: str = typer.Argument(help="Collection's name"), organisation: str = typer.Argument(help="Organisation's name") @@ -82,7 +83,7 @@ def unshare( print("{} is shared with {}".format(collection, ", ".join(shared))) -@collections.command(help="Set the collection display name", name="name") +@collections.command(help="Set the collection display name", name="name", epilog=variables["help_epilog"]) def set_display_name( collection: str = typer.Argument(help="Collection's name"), name: str = typer.Argument(help="The display name") @@ -92,7 +93,7 @@ def set_display_name( print("{} display name is {}".format(collection, name)) -@collections.command(help="Set the field display name", name="set_alias") +@collections.command(help="Set the field display name", name="set_alias", epilog=variables["help_epilog"]) def set_field_display_name( collection: str = typer.Argument(help="Collection's name"), field_path: str = typer.Argument(help="The field path"), @@ -103,7 +104,7 @@ def set_field_display_name( __print_table(fields[0], fields[1:], sortby=None) -@collections.command(help="Display a sample of a collection") +@collections.command(help="Display a sample of a collection", epilog=variables["help_epilog"]) def sample( collection: str = typer.Argument(help="Collection's name"), pretty: bool = typer.Option(default=True), @@ -114,7 +115,7 @@ def sample( print(json.dumps(sample.get("hits", []), indent=2 if pretty else None)) -@collections.command(help="Delete a collection") +@collections.command(help="Delete a collection", epilog=variables["help_epilog"]) def delete( collection: str = typer.Argument(help="collection's name") ): @@ -128,7 +129,7 @@ def delete( print("{} has been deleted on {}.".format(collection, config)) -@collections.command(help="Create a collection") +@collections.command(help="Create a collection", epilog=variables["help_epilog"]) def create( collection: str = typer.Argument(help="Collection's name"), model: str = typer.Option(default=None, help="Name of the model within your configuration, or URL or file path"), diff --git a/arlas/cli/configurations.py b/arlas/cli/configurations.py index 64f3245..21fc568 100644 --- a/arlas/cli/configurations.py +++ b/arlas/cli/configurations.py @@ -10,7 +10,7 @@ configurations = typer.Typer() -@configurations.command(help="List configurations", name="list") +@configurations.command(help="List configurations", name="list", epilog=variables["help_epilog"]) def list_configurations(): confs = [] for (name, conf) in Configuration.settings.arlas.items(): @@ -20,7 +20,7 @@ def list_configurations(): print(tab) -@configurations.command(help="Add a configuration", name="create") +@configurations.command(help="Add a configuration", name="create", epilog=variables["help_epilog"]) def create_configuration( name: str = typer.Argument(help="Name of the configuration"), server: str = typer.Option(help="ARLAS Server url"), @@ -76,7 +76,7 @@ def create_configuration( print("Configuration {} created.".format(name)) -@configurations.command(help="Add a configuration for ARLAS Cloud", name="login") +@configurations.command(help="Add a configuration for ARLAS Cloud", name="login", epilog=variables["help_epilog"]) def login( auth_login: str = typer.Argument(help="ARLAS login"), elastic_login: str = typer.Argument(help="Elasticsearch login"), @@ -130,7 +130,7 @@ def login( print("{} is now your default configuration.".format(name)) -@configurations.command(help="Delete a configuration", name="delete") +@configurations.command(help="Delete a configuration", name="delete", epilog=variables["help_epilog"]) def delete_configuration( config: str = typer.Argument(help="Name of the configuration"), ): @@ -143,7 +143,7 @@ def delete_configuration( print("Configuration {} deleted.".format(config)) -@configurations.command(help="Describe a configuration", name="describe") +@configurations.command(help="Describe a configuration", name="describe", epilog=variables["help_epilog"]) def describe_configuration( config: str = typer.Argument(help="Name of the configuration"), ): diff --git a/arlas/cli/index.py b/arlas/cli/index.py index 1d77b0b..9dfc010 100644 --- a/arlas/cli/index.py +++ b/arlas/cli/index.py @@ -17,7 +17,7 @@ def configuration(config: str = typer.Option(default=None, help="Name of the ARL variables["arlas"] = Configuration.solve_config(config) -@indices.command(help="List indices", name="list") +@indices.command(help="List indices", name="list", epilog=variables["help_epilog"]) def list_indices(): config = variables["arlas"] indices = Service.list_indices(config) @@ -27,7 +27,7 @@ def list_indices(): print(f"Total count: {sum([int(index_info[2]) for index_info in indices[1:]])}") -@indices.command(help="Describe an index") +@indices.command(help="Describe an index", epilog=variables["help_epilog"]) def describe( index: str = typer.Argument(help="index's name") ): @@ -38,7 +38,7 @@ def describe( print(tab) -@indices.command(help="Clone an index and set its name") +@indices.command(help="Clone an index and set its name", epilog=variables["help_epilog"]) def clone( source: str = typer.Argument(help="Source index name"), target: str = typer.Argument(help="Target cloned index name") @@ -50,7 +50,8 @@ def clone( print(tab) -@indices.command(help="Migrate an index on another arlas configuration, and set the target index name") +@indices.command(help="Migrate an index on another arlas configuration, and set the target index name", + epilog=variables["help_epilog"]) def migrate( source: str = typer.Argument(help="Source index name"), arlas_target: str = typer.Argument(help="Target ARLAS Configuration name"), @@ -63,7 +64,7 @@ def migrate( print(tab) -@indices.command(help="Display a sample of an index") +@indices.command(help="Display a sample of an index", epilog=variables["help_epilog"]) def sample( index: str = typer.Argument(help="index's name"), pretty: bool = typer.Option(default=True), @@ -74,7 +75,7 @@ def sample( print(json.dumps(sample["hits"].get("hits", []), indent=2 if pretty else None)) -@indices.command(help="Create an index") +@indices.command(help="Create an index", epilog=variables["help_epilog"]) def create( index: str = typer.Argument(help="index's name"), mapping: str = typer.Option(help="Name of the mapping within your configuration, or URL or file path"), @@ -96,7 +97,7 @@ def create( print("Index {} created on {}".format(index, config)) -@indices.command(help="Index data") +@indices.command(help="Index data", epilog=variables["help_epilog"]) def data( index: str = typer.Argument(help="index's name"), files: list[str] = typer.Argument(help="List of paths to the file(s) containing the data. Format: NDJSON"), @@ -114,7 +115,7 @@ def data( i = i + 1 -@indices.command(help="Generate the mapping based on the data") +@indices.command(help="Generate the mapping based on the data", epilog=variables["help_epilog"]) def mapping( file: str = typer.Argument(help="Path to the file containing the data. Format: NDJSON"), nb_lines: int = typer.Option(default=2, help="Number of line to consider for generating the mapping. Avoid going over 10."), @@ -150,7 +151,7 @@ def mapping( print(json.dumps(mapping, indent=2)) -@indices.command(help="Delete an index") +@indices.command(help="Delete an index", epilog=variables["help_epilog"]) def delete( index: str = typer.Argument(help="index's name") ): diff --git a/arlas/cli/org.py b/arlas/cli/org.py index 2f087af..b50d074 100644 --- a/arlas/cli/org.py +++ b/arlas/cli/org.py @@ -7,7 +7,7 @@ org = typer.Typer() -@org.command(help="List organisations", name="list") +@org.command(help="List organisations", name="list", epilog=variables["help_epilog"]) def list_organisations(): config = variables["arlas"] organisations = Service.list_organisations(config) @@ -17,19 +17,19 @@ def list_organisations(): print(tab) -@org.command(help="Create organisation with the given name", name="add") +@org.command(help="Create organisation with the given name", name="add", epilog=variables["help_epilog"]) def create_organisation(organisation: str = typer.Argument(help="Organisation's name")): config = variables["arlas"] print(Service.create_organisation(config, organisation).get("id")) -@org.command(help="Delete the organisation", name="delete") +@org.command(help="Delete the organisation", name="delete", epilog=variables["help_epilog"]) def delete_organisation(org_id: str = typer.Argument(help="Organisation's identifier")): config = variables["arlas"] print(Service.delete_organisation(config, org_id).get("message")) -@org.command(help="List the collections of the organisation", name="collections") +@org.command(help="List the collections of the organisation", name="collections", epilog=variables["help_epilog"]) def collections(org_id: str = typer.Argument(help="Organisation's identifier")): config = variables["arlas"] organisations = Service.list_organisation_collections(config, org_id) @@ -39,7 +39,7 @@ def collections(org_id: str = typer.Argument(help="Organisation's identifier")): print(tab) -@org.command(help="List the users of the organisation", name="users") +@org.command(help="List the users of the organisation", name="users", epilog=variables["help_epilog"]) def users(org_id: str = typer.Argument(help="Organisation's identifier")): config = variables["arlas"] users = Service.list_organisation_users(config, org_id) @@ -48,7 +48,8 @@ def users(org_id: str = typer.Argument(help="Organisation's identifier")): print(tab) -@org.command(help="Add a user to the organisation, and optionally within groups", name="add_user") +@org.command(help="Add a user to the organisation, and optionally within groups", name="add_user", + epilog=variables["help_epilog"]) def add_user(org_id: str = typer.Argument(help="Organisation's identifier"), email: str = typer.Argument(help="User's email"), group: list[str] = typer.Option([], help="Group identifier")): @@ -56,14 +57,14 @@ def add_user(org_id: str = typer.Argument(help="Organisation's identifier"), print(Service.add_user_in_organisation(config, org_id, email, group)) -@org.command(help="Remove the user from the organisation", name="delete_user") +@org.command(help="Remove the user from the organisation", name="delete_user", epilog=variables["help_epilog"]) def delete_user(org_id: str = typer.Argument(help="Organisation's identifier"), user_id: str = typer.Argument(help="User ID")): config = variables["arlas"] Service.delete_user_in_organisation(config, org_id, user_id) -@org.command(help="List the groups of the organisation", name="groups") +@org.command(help="List the groups of the organisation", name="groups", epilog=variables["help_epilog"]) def groups(org_id: str = typer.Argument(help="Organisation's identifier")): config = variables["arlas"] tab = PrettyTable(["id", "name", "description", "is technical", "type"], sortby="name", align="l") @@ -74,7 +75,7 @@ def groups(org_id: str = typer.Argument(help="Organisation's identifier")): print(tab) -@org.command(help="List the permissions of the organisation", name="permissions") +@org.command(help="List the permissions of the organisation", name="permissions", epilog=variables["help_epilog"]) def permissions(org_id: str = typer.Argument(help="Organisation's identifier")): config = variables["arlas"] groups = Service.list_organisation_permissions(config, org_id) @@ -83,7 +84,7 @@ def permissions(org_id: str = typer.Argument(help="Organisation's identifier")): print(tab) -@org.command(help="Add a group to the organisation", name="add_group") +@org.command(help="Add a group to the organisation", name="add_group", epilog=variables["help_epilog"]) def add_group(org_id: str = typer.Argument(help="Organisation's identifier"), name: str = typer.Argument(help="Group name"), description: str = typer.Argument(help="Group description")): @@ -91,14 +92,14 @@ def add_group(org_id: str = typer.Argument(help="Organisation's identifier"), print(Service.add_group_in_organisation(config, org_id, name, description).get("id")) -@org.command(help="Remove the group from the organisation", name="delete_group") +@org.command(help="Remove the group from the organisation", name="delete_group", epilog=variables["help_epilog"]) def delete_group(org_id: str = typer.Argument(help="Organisation's identifier"), id: str = typer.Argument(help="Group ID")): config = variables["arlas"] print(Service.delete_group_in_organisation(config, org_id, id).get("message")) -@org.command(help="Add a permission to the organisation", name="add_permission") +@org.command(help="Add a permission to the organisation", name="add_permission", epilog=variables["help_epilog"]) def add_permission(org_id: str = typer.Argument(help="Organisation's identifier"), value: str = typer.Argument(help="Permission value"), description: str = typer.Argument(help="Permission description")): @@ -106,14 +107,16 @@ def add_permission(org_id: str = typer.Argument(help="Organisation's identifier" print(Service.add_permission_in_organisation(config, org_id, value, description).get("id")) -@org.command(help="Remove the permission from the organisation", name="delete_permission") +@org.command(help="Remove the permission from the organisation", name="delete_permission", + epilog=variables["help_epilog"]) def delete_permission(org_id: str = typer.Argument(help="Organisation's identifier"), id: str = typer.Argument(help="Permission ID")): config = variables["arlas"] print(Service.delete_permission_in_organisation(config, org_id, id).get("message")) -@org.command(help="Add a permission to a group within the organisation", name="add_permission_to_group") +@org.command(help="Add a permission to a group within the organisation", name="add_permission_to_group", + epilog=variables["help_epilog"]) def add_permission_to_group(org_id: str = typer.Argument(help="Organisation's identifier"), group_id: str = typer.Argument(help="Group identifier"), permission_id: str = typer.Argument(help="Permission identifier")): @@ -121,7 +124,8 @@ def add_permission_to_group(org_id: str = typer.Argument(help="Organisation's id print(Service.add_permission_to_group_in_organisation(config, org_id, group_id, permission_id)) -@org.command(help="Remove a permission to a group within the organisation", name="delete_permission_from_group") +@org.command(help="Remove a permission to a group within the organisation", name="delete_permission_from_group", + epilog=variables["help_epilog"]) def delete_permission_from_group(organisation: str = typer.Argument(help="Organisation's identifier"), group_id: str = typer.Argument(help="Group identifier"), permission_id: str = typer.Argument(help="Permission identifier")): @@ -129,7 +133,8 @@ def delete_permission_from_group(organisation: str = typer.Argument(help="Organi print(Service.delete_permission_from_group_in_organisation(config, organisation, group_id, permission_id)) -@org.command(help="Add a user to a group within the organisation", name="add_user_to_group") +@org.command(help="Add a user to a group within the organisation", name="add_user_to_group", + epilog=variables["help_epilog"]) def add_user_to_group(org_id: str = typer.Argument(help="Organisation's identifier"), user_id: str = typer.Argument(help="User identifier"), group_id: str = typer.Argument(help="Group identifier")): @@ -137,7 +142,7 @@ def add_user_to_group(org_id: str = typer.Argument(help="Organisation's identifi print(Service.add_permission_to_group_in_organisation(config, org_id, user_id, group_id)) -@org.command(help="Remove a user from a group within the organisation", name="delete_user_from_group") +@org.command(help="Remove a user from a group within the organisation", name="delete_user_from_group", epilog=variables["help_epilog"]) def delete_user_from_group(org_id: str = typer.Argument(help="Organisation's identifier"), user_id: str = typer.Argument(help="User identifier"), group_id: str = typer.Argument(help="Group identifier")): diff --git a/arlas/cli/persist.py b/arlas/cli/persist.py index 34c5622..f11f05e 100644 --- a/arlas/cli/persist.py +++ b/arlas/cli/persist.py @@ -15,7 +15,7 @@ def configuration(config: str = typer.Option(default=None, help="Name of the ARL variables["arlas"] = Configuration.solve_config(config) -@persist.command(help="Add an entry, returns its ID", name="add") +@persist.command(help="Add an entry, returns its ID", name="add", epilog=variables["help_epilog"]) def add( file: str = typer.Argument(help="File path"), zone: str = typer.Argument(help="zone"), @@ -29,7 +29,7 @@ def add( print(id) -@persist.command(help="Delete an entry", name="delete") +@persist.command(help="Delete an entry", name="delete", epilog=variables["help_epilog"]) def delete( id: str = typer.Argument(help="entry identifier") ): @@ -50,7 +50,7 @@ def delete( print("Resource {} deleted.".format(id)) -@persist.command(help="Retrieve an entry", name="get") +@persist.command(help="Retrieve an entry", name="get", epilog=variables["help_epilog"]) def get( id: str = typer.Argument(help="entry identifier") ): @@ -58,7 +58,7 @@ def get( print(Service.persistence_get(config, id=id).get("doc_value"), end="") -@persist.command(help="List entries within a zone", name="zone") +@persist.command(help="List entries within a zone", name="zone", epilog=variables["help_epilog"]) def zone( zone: str = typer.Argument(help="Zone name") ): @@ -69,7 +69,7 @@ def zone( print(tab) -@persist.command(help="List groups allowed to access a zone", name="groups") +@persist.command(help="List groups allowed to access a zone", name="groups", epilog=variables["help_epilog"]) def groups( zone: str = typer.Argument(help="Zone name") ): @@ -80,7 +80,7 @@ def groups( print(tab) -@persist.command(help="Describe an entry", name="describe") +@persist.command(help="Describe an entry", name="describe", epilog=variables["help_epilog"]) def describe( id: str = typer.Argument(help="entry identifier") ): diff --git a/arlas/cli/user.py b/arlas/cli/user.py index bf6f32c..af4839b 100644 --- a/arlas/cli/user.py +++ b/arlas/cli/user.py @@ -6,25 +6,25 @@ user = typer.Typer() -@user.command(help="Create user", name="add") +@user.command(help="Create user", name="add", epilog=variables["help_epilog"]) def add(email: str = typer.Argument(help="User's email")): config = variables["arlas"] print(Service.create_user(config, email).get("id")) -@user.command(help="Delete user", name="delete") +@user.command(help="Delete user", name="delete", epilog=variables["help_epilog"]) def delete(id: str = typer.Argument(help="User's identifier")): config = variables["arlas"] print(Service.delete_user(config, id).get("message")) -@user.command(help="Activate user account", name="activate") +@user.command(help="Activate user account", name="activate", epilog=variables["help_epilog"]) def activate(id: str = typer.Argument(help="User's identifier")): config = variables["arlas"] print(Service.activate(config, id).get("message")) -@user.command(help="Deactivate user account", name="deactivate") +@user.command(help="Deactivate user account", name="deactivate", epilog=variables["help_epilog"]) def deactivate(id: str = typer.Argument(help="User's identifier")): config = variables["arlas"] print(Service.deactivate(config, id).get("message")) diff --git a/arlas/cli/variables.py b/arlas/cli/variables.py index 29af626..8839688 100644 --- a/arlas/cli/variables.py +++ b/arlas/cli/variables.py @@ -2,5 +2,6 @@ variables = { - "configuration_file": os.path.join(os.path.expanduser('~'), ".arlas", "cli", "configuration.yaml") + "configuration_file": os.path.join(os.path.expanduser('~'), ".arlas", "cli", "configuration.yaml"), + "help_epilog": "See full arlas_cli documentation at https://gisaia.github.io/arlas_cli/" }