diff --git a/src/geoserverx/cli/cli.py b/src/geoserverx/cli/cli.py index 17a7211..d8af9c4 100644 --- a/src/geoserverx/cli/cli.py +++ b/src/geoserverx/cli/cli.py @@ -26,12 +26,6 @@ def callback(): """ -# Enum for request type -class requestEnum(str, Enum): - _sync = "sync" - _async = "async" - - # Enum for vector file type class vectorFileEnum(str, Enum): shapefile = "shapefile" @@ -41,7 +35,6 @@ class vectorFileEnum(str, Enum): @SyncGeoServerX.exception_handler @app.command(help="Get all workspaces in the Geoserver") def workspaces( - request: requestEnum = requestEnum._sync, url: str = typer.Option( "http://127.0.0.1:8080/geoserver/rest/", help="Geoserver REST URL" ), @@ -53,31 +46,27 @@ def workspaces( Get all workspaces in the Geoserver looks like - gsx workspaces --url --username --password """ - if request.value == "sync": - client = SyncGeoServerX(username, password, url) - result = client.get_all_workspaces() - if "code" in result: - print(result) - else: - if output == "json": - print(result.model_dump_json(indent=2)) - else: - try: - table = Table("Name", "Link") - for workspace in result.workspaces.workspace: - table.add_row(workspace.name, workspace.href) - console.print(table) - except AttributeError: - print(result.response) + client = SyncGeoServerX(username, password, url) + result = client.get_all_workspaces() + if "code" in result: + print(result) else: - print("Async support will be shortly") + if output == "json": + print(result.model_dump_json(indent=2)) + else: + try: + table = Table("Name", "Link") + for workspace in result.workspaces.workspace: + table.add_row(workspace.name, workspace.href) + console.print(table) + except AttributeError: + print(result.response) @SyncGeoServerX.exception_handler @app.command(help="Get workspace in the Geoserver") def workspace( workspace: str, - request: requestEnum = requestEnum._sync, url: str = typer.Option( "http://127.0.0.1:8080/geoserver/rest/", help="Geoserver REST URL" ), @@ -89,36 +78,33 @@ def workspace( Get workspace in the Geoserver looks like - gsx workspace --url --username --password """ - if request.value == "sync": - client = SyncGeoServerX(username, password, url) - result = client.get_workspace(workspace) - if "code" in result: - print(result) - else: - if output == "json": - print(result.model_dump_json(indent=2)) - else: - try: - table = Table("Column", "Value") - table.add_row("name", result.workspace.name) - table.add_row("isolated", str(result.workspace.isolated)) - table.add_row("dateCreated", result.workspace.dateCreated) - table.add_row("dataStores", result.workspace.dataStores) - table.add_row("coverageStores", result.workspace.coverageStores) - table.add_row("wmsStores", result.workspace.wmsStores) - table.add_row("wmtsStores", result.workspace.wmtsStores) - console.print(table) - except AttributeError: - print(result.response) + + client = SyncGeoServerX(username, password, url) + result = client.get_workspace(workspace) + if "code" in result: + print(result) else: - print("Async support will be shortly") + if output == "json": + print(result.model_dump_json(indent=2)) + else: + try: + table = Table("Column", "Value") + table.add_row("name", result.workspace.name) + table.add_row("isolated", str(result.workspace.isolated)) + table.add_row("dateCreated", result.workspace.dateCreated) + table.add_row("dataStores", result.workspace.dataStores) + table.add_row("coverageStores", result.workspace.coverageStores) + table.add_row("wmsStores", result.workspace.wmsStores) + table.add_row("wmtsStores", result.workspace.wmtsStores) + console.print(table) + except AttributeError: + print(result.response) @SyncGeoServerX.exception_handler @app.command(help="Delete workspace in the Geoserver") def delete_workspace( workspace: str, - request: requestEnum = requestEnum._sync, recurse: bool = typer.Option(False, help="Delete all stores,layers,styles,etc."), url: str = typer.Option( "http://127.0.0.1:8080/geoserver/rest/", help="Geoserver REST URL" @@ -130,19 +116,15 @@ def delete_workspace( Delete workspace in the Geoserver looks like - gsx delete-workspace --recurse/--no-recurse --url --username --password """ - if request.value == "sync": - client = SyncGeoServerX(username, password, url) - result = client.delete_workspace(workspace, recurse) - print(result.response) - else: - print("Async support will be shortly") + client = SyncGeoServerX(username, password, url) + result = client.delete_workspace(workspace, recurse) + print(result.response) @SyncGeoServerX.exception_handler @app.command(help="Add workspace in the Geoserver") def create_workspace( workspace: str, - request: requestEnum = requestEnum._sync, default: bool = typer.Option(False, help="Make workspace default?"), isolated: bool = typer.Option(False, help="Make workspace isolated?"), url: str = typer.Option( @@ -155,20 +137,16 @@ def create_workspace( Add workspace in the Geoserver looks like - gsx create-workspace --default/--no-default --isolated/--no-isolated --url --username --password """ - if request.value == "sync": - client = SyncGeoServerX(username, password, url) - result = client.create_workspace(workspace, default, isolated) - print(result.response) - else: - print("Async support will be shortly") + client = SyncGeoServerX(username, password, url) + result = client.create_workspace(workspace, default, isolated) + print(result.response) @SyncGeoServerX.exception_handler @app.command(help="Add workspace in the Geoserver") def update_workspace( current_name: str, - request: requestEnum = requestEnum._sync, new_name: Optional[str] = typer.Option(None, help="New Workspace name"), isolated: Optional[bool] = typer.Option(False, help="Make workspace isolated?"), url: str = typer.Option( @@ -181,22 +159,18 @@ def update_workspace( Update existing workspace in the Geoserver looks like - gsx update-workspace --new-name --isolated/--no-isolated --username --password """ - if request.value == "sync": - client = SyncGeoServerX(username, password, url) - result = client.update_workspace( - current_name, - UpdateWorkspaceInfo(name=new_name, isolated=isolated), - ) - print(result.response) - else: - print("Async support will be shortly") + client = SyncGeoServerX(username, password, url) + result = client.update_workspace( + current_name, + UpdateWorkspaceInfo(name=new_name, isolated=isolated), + ) + print(result.response) @SyncGeoServerX.exception_handler @app.command(help="Get vector stores in specific workspaces") def vector_st_wp( - request: requestEnum = requestEnum._sync, workspace: str = typer.Option(..., help="Workspace name"), url: str = typer.Option( "http://127.0.0.1:8080/geoserver/rest/", help="Geoserver REST URL" @@ -207,18 +181,15 @@ def vector_st_wp( """ Get vector stores in specific workspaces """ - if request.value == "sync": - client = SyncGeoServerX(username, password, url) - result = client.get_vector_stores_in_workspaces(workspace).model_dump_json() - print(result) - else: - print("Async support will be shortly") + + client = SyncGeoServerX(username, password, url) + result = client.get_vector_stores_in_workspaces(workspace).model_dump_json() + print(result) @SyncGeoServerX.exception_handler @app.command(help="Get raster stores in specific workspaces") def raster_st_wp( - request: requestEnum = requestEnum._sync, workspace: str = typer.Option(..., help="Workspace name"), url: str = typer.Option( "http://127.0.0.1:8080/geoserver/rest/", help="Geoserver REST URL" @@ -229,18 +200,15 @@ def raster_st_wp( """ Get raster stores in specific workspaces """ - if request.value == "sync": - client = SyncGeoServerX(username, password, url) - result = client.get_raster_stores_in_workspaces(workspace).model_dump_json() - print(result) - else: - print("Async support will be shortly") + + client = SyncGeoServerX(username, password, url) + result = client.get_raster_stores_in_workspaces(workspace).model_dump_json() + print(result) @SyncGeoServerX.exception_handler @app.command(help="Get vector store information in specific workspaces") def vector_store( - request: requestEnum = requestEnum._sync, workspace: str = typer.Option(..., help="Workspace name"), store: str = typer.Option(..., help="Store name"), url: str = typer.Option( @@ -252,18 +220,14 @@ def vector_store( """ Get vector store information in specific workspaces """ - if request.value == "sync": - client = SyncGeoServerX(username, password, url) - result = client.get_vector_store(workspace, store).model_dump_json() - print(result) - else: - print("Async support will be shortly") + client = SyncGeoServerX(username, password, url) + result = client.get_vector_store(workspace, store).model_dump_json() + print(result) @SyncGeoServerX.exception_handler @app.command(help="Get raster store information in specific workspaces") def raster_store( - request: requestEnum = requestEnum._sync, workspace: str = typer.Option(..., help="Workspace name"), store: str = typer.Option(..., help="Store name"), url: str = typer.Option( @@ -275,18 +239,14 @@ def raster_store( """ Get raster store information in specific workspaces """ - if request.value == "sync": - client = SyncGeoServerX(username, password, url) - result = client.get_raster_store(workspace, store).model_dump_json() - print(result) - else: - print("Async support will be shortly") + client = SyncGeoServerX(username, password, url) + result = client.get_raster_store(workspace, store).model_dump_json() + print(result) @SyncGeoServerX.exception_handler @app.command(help="Get all styles in Geoserver") def styles( - request: requestEnum = requestEnum._sync, url: str = typer.Option( "http://127.0.0.1:8080/geoserver/rest/", help="Geoserver REST URL" ), @@ -296,18 +256,14 @@ def styles( """ Get all styles in Geoserver """ - if request.value == "sync": - client = SyncGeoServerX(username, password, url) - result = client.get_all_styles().model_dump_json() - print(result) - else: - print("Async support will be shortly") + client = SyncGeoServerX(username, password, url) + result = client.get_all_styles().model_dump_json() + print(result) @SyncGeoServerX.exception_handler @app.command(help="Get style in Geoserver") def style( - request: requestEnum = requestEnum._sync, url: str = typer.Option( "http://127.0.0.1:8080/geoserver/rest/", help="Geoserver REST URL" ), @@ -318,18 +274,14 @@ def style( """ Get style in Geoserver """ - if request.value == "sync": - client = SyncGeoServerX(username, password, url) - result = client.get_style(style).model_dump_json() - print(result) - else: - print("Async support will be shortly") + client = SyncGeoServerX(username, password, url) + result = client.get_style(style).model_dump_json() + print(result) @SyncGeoServerX.exception_handler @app.command(help="Create Vector Layer in Geoserver") def create_file( - request: requestEnum = requestEnum._sync, url: str = typer.Option( "http://127.0.0.1:8080/geoserver/rest/", help="Geoserver REST URL" ), @@ -343,24 +295,18 @@ def create_file( """ Create Vector Layer in Geoserver """ - if request.value == "sync": - client = SyncGeoServerX(username, password, url) - try: - files = open(file, "rb") - result = client.create_file_store( - workspace, store, files.read(), service_type - ) - print(result) - except Exception: - print("File path is incorrect") - else: - print("Async support will be shortly") + client = SyncGeoServerX(username, password, url) + try: + files = open(file, "rb") + result = client.create_file_store(workspace, store, files.read(), service_type) + print(result) + except Exception: + print("File path is incorrect") @SyncGeoServerX.exception_handler @app.command(help="Create PostgreSQL store in Geoserver") def create_pg_store( - request: requestEnum = requestEnum._sync, url: str = typer.Option( "http://127.0.0.1:8080/geoserver/rest/", help="Geoserver REST URL" ), @@ -377,26 +323,22 @@ def create_pg_store( """ Create PostgreSQL store in Geoserver """ - if request.value == "sync": - client = SyncGeoServerX(username, password, url) - result = client.create_pg_store( - name=name, - workspace=workspace, - host=host, - port=port, - username=dbuser, - password=dbpwd, - database=dbname, - ) - print(result) - else: - print("Async support will be shortly") + client = SyncGeoServerX(username, password, url) + result = client.create_pg_store( + name=name, + workspace=workspace, + host=host, + port=port, + username=dbuser, + password=dbpwd, + database=dbname, + ) + print(result) @SyncGeoServerX.exception_handler @app.command(help="Get all layers in the Geoserver") def layers( - request: requestEnum = requestEnum._sync, url: str = typer.Option( "http://127.0.0.1:8080/geoserver/rest/", help="Geoserver REST URL" ), @@ -407,18 +349,14 @@ def layers( """ Get all layers in the Geoserver """ - if request.value == "sync": - client = SyncGeoServerX(username, password, url) - result = client.get_all_layers(workspace).model_dump_json() - print(result) - else: - print("Async support will be shortly") + client = SyncGeoServerX(username, password, url) + result = client.get_all_layers(workspace).model_dump_json() + print(result) @SyncGeoServerX.exception_handler @app.command(help="Get layer in the Geoserver") def layer( - request: requestEnum = requestEnum._sync, workspace: str = typer.Option(..., help="Workspace name"), layer: str = typer.Option(..., help="Layer name"), detail: bool = typer.Option(False, help="Detail Info"), @@ -431,18 +369,14 @@ def layer( """ Get workspace in the Geoserver """ - if request.value == "sync": - client = SyncGeoServerX(username, password, url) - result = client.get_layer(workspace, layer, detail).model_dump_json() - print(result) - else: - print("Async support will be shortly") + client = SyncGeoServerX(username, password, url) + result = client.get_layer(workspace, layer, detail).model_dump_json() + print(result) @SyncGeoServerX.exception_handler @app.command(help="Get layer groups in the Geoserver") def layer_groups( - request: requestEnum = requestEnum._sync, workspace: str = typer.Option(default=None, help="Workspace name"), url: str = typer.Option( "http://127.0.0.1:8080/geoserver/rest/", help="Geoserver REST URL" @@ -453,18 +387,14 @@ def layer_groups( """ Get layer groups in the Geoserver """ - if request.value == "sync": - client = SyncGeoServerX(username, password, url) - result = client.get_all_layer_groups(workspace).json() - print(result) - else: - print("Async support will be shortly") + client = SyncGeoServerX(username, password, url) + result = client.get_all_layer_groups(workspace).json() + print(result) @SyncGeoServerX.exception_handler @app.command(help="Get all geofence rules in the Geoserver") def geofence_rules( - request: requestEnum = requestEnum._sync, url: str = typer.Option( "http://127.0.0.1:8080/geoserver/rest/", help="Geoserver REST URL" ), @@ -474,18 +404,14 @@ def geofence_rules( """ Get all geofence rules in the Geoserver """ - if request.value == "sync": - client = SyncGeoServerX(username, password, url) - result = client.get_all_geofence_rules().model_dump_json() - print(result) - else: - print("Async support will be shortly") + client = SyncGeoServerX(username, password, url) + result = client.get_all_geofence_rules().model_dump_json() + print(result) @SyncGeoServerX.exception_handler @app.command(help="Get geofence rule in the Geoserver") def geofence_rule( - request: requestEnum = requestEnum._sync, id: int = typer.Option(..., help="Geofence rule id"), url: str = typer.Option( "http://127.0.0.1:8080/geoserver/rest/", help="Geoserver REST URL" @@ -496,9 +422,6 @@ def geofence_rule( """ Get geofence rule in the Geoserver """ - if request.value == "sync": - client = SyncGeoServerX(username, password, url) - result = client.get_geofence_rule(id).model_dump_json() - print(result) - else: - print("Async support will be shortly") + client = SyncGeoServerX(username, password, url) + result = client.get_geofence_rule(id).model_dump_json() + print(result)