Skip to content

feat: add command base #279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ ignore=E203,E501,W503
max-line-length=88
application_import_names=rethinkdb
exclude = .git,__pycache__,tests
per-file-ignores =
rethinkdb/cli/__init__.py: F401
10 changes: 5 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 11 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,22 @@ maintainers = [
[tool.poetry.urls]
"Bug Tracker" = "https://github.com/rethinkdb/rethinkdb-python/issues/"

# this should be shipped with the C++ code not the python client
# [tool.poetry.scripts]
# rethinkdb-import = 'rethinkdb.main:app'
# RethinkDB is aliasing the commands to `rethinkdb <command>`, therefore it
# can be executed as `rethinkdb dump` or `rethinkdb-dump`.
[tool.poetry.scripts]
rethinkdb = "rethinkdb.cli.main:cmd_main"
rethinkdb-dump = "rethinkdb.cli._dump:cmd_dump"
rethinkdb-export = "rethinkdb.cli._export:cmd_export"
rethinkdb-import = "rethinkdb.cli._import:cmd_import"
rethinkdb-index-rebuild = "rethinkdb.cli._index_rebuild:cmd_index_rebuild"
rethinkdb-repl = "rethinkdb.cli._repl:cmd_repl"
rethinkdb-restore = "rethinkdb.cli._restore:cmd_restore"

[tool.poetry.dependencies]
pydantic = "^1.9"
python = "^3.7"
ujson = "^5.2.0"
click = "^8.1.3"

[tool.poetry.dev-dependencies]
bandit = "^1.7"
Expand Down
28 changes: 28 additions & 0 deletions rethinkdb/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2022 RethinkDB
#
# Licensed under the Apache License, Version 2.0 (the 'License');
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an 'AS IS' BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
RethinkDB CLI module defines the management commands that can be used to
interact with the database. These commands are for exporting/importing data.

Although these commands can be used to prepare data for backup, depending on
your needs, you may want to evaluate more mature backup backup solutions.
"""

from rethinkdb.cli._dump import cmd_dump
from rethinkdb.cli._export import cmd_export
from rethinkdb.cli._import import cmd_import
from rethinkdb.cli._index_rebuild import cmd_index_rebuild
from rethinkdb.cli._repl import cmd_repl
from rethinkdb.cli._restore import cmd_restore
31 changes: 31 additions & 0 deletions rethinkdb/cli/_dump.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env python

# Copyright 2022 RethinkDB
#
# Licensed under the Apache License, Version 2.0 (the 'License');
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an 'AS IS' BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This file incorporates work covered by the following copyright:
# Copyright 2010-2016 RethinkDB, all rights reserved.

"""
Dump creates an archive of data from a RethinkDB cluster.
"""
import click


@click.command
def cmd_dump():
"""
Dump creates an archive of data from a RethinkDB cluster.
"""
click.echo("dump command")
31 changes: 31 additions & 0 deletions rethinkdb/cli/_export.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env python

# Copyright 2022 RethinkDB
#
# Licensed under the Apache License, Version 2.0 (the 'License');
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an 'AS IS' BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This file incorporates work covered by the following copyright:
# Copyright 2010-2016 RethinkDB, all rights reserved.

"""
Export exports data from a RethinkDB cluster into a directory.
"""
import click


@click.command
def cmd_export():
"""
Export data from a RethinkDB cluster into a directory.
"""
click.echo("export command")
32 changes: 32 additions & 0 deletions rethinkdb/cli/_import.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python

# Copyright 2022 RethinkDB
#
# Licensed under the Apache License, Version 2.0 (the 'License');
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an 'AS IS' BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This file incorporates work covered by the following copyright:
# Copyright 2010-2016 RethinkDB, all rights reserved.

"""
Import loads data into a RethinkDB cluster.
"""

import click


@click.command
def cmd_import():
"""
Import loads data into a RethinkDB cluster.
"""
click.echo("import command")
35 changes: 35 additions & 0 deletions rethinkdb/cli/_index_rebuild.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env python

# Copyright 2022 RethinkDB
#
# Licensed under the Apache License, Version 2.0 (the 'License');
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an 'AS IS' BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This file incorporates work covered by the following copyright:
# Copyright 2010-2016 RethinkDB, all rights reserved.

"""
Index rebuild recreates outdated secondary indexes in a cluster.

This should be used after upgrading to a newer version of rethinkdb. There
will be a notification in the web UI if any secondary indexes are out-of-date.
"""

import click


@click.command
def cmd_index_rebuild():
"""
Rebuild outdated secondary indexes.
"""
click.echo("index rebuild command")
41 changes: 41 additions & 0 deletions rethinkdb/cli/_repl.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env python

# Copyright 2022 RethinkDB
#
# Licensed under the Apache License, Version 2.0 (the 'License');
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an 'AS IS' BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This file incorporates work covered by the following copyright:
# Copyright 2010-2016 RethinkDB, all rights reserved.

"""
The main command is a special group that is the root of the command tree.

This command creates a subcommand tree that with the following commands for
those cases when the rethinkdb binary is not installed:
- dump
- export
- import
- index_rebuild
- repl
- restore
"""

import click


@click.command
def cmd_repl():
"""
Rebuild outdated secondary indexes.
"""
click.echo("repl command")
32 changes: 32 additions & 0 deletions rethinkdb/cli/_restore.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python

# Copyright 2022 RethinkDB
#
# Licensed under the Apache License, Version 2.0 (the 'License');
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an 'AS IS' BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This file incorporates work covered by the following copyright:
# Copyright 2010-2016 RethinkDB, all rights reserved.

"""
Restore loads data into a RethinkDB cluster from an archive.
"""

import click


@click.command
def cmd_restore():
"""
Restore loads data into a RethinkDB cluster from an archive.
"""
click.echo("restore command")
57 changes: 57 additions & 0 deletions rethinkdb/cli/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env python

# Copyright 2022 RethinkDB
#
# Licensed under the Apache License, Version 2.0 (the 'License');
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an 'AS IS' BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# This file incorporates work covered by the following copyright:
# Copyright 2010-2016 RethinkDB, all rights reserved.

"""
The main command is a special group that is the root of the command tree.

This command creates a subcommand tree that with the following commands for
those cases when the rethinkdb binary is not installed:
- dump
- export
- import
- index_rebuild
- repl
- restore
"""

import click

from rethinkdb.cli import (
cmd_dump,
cmd_export,
cmd_import,
cmd_index_rebuild,
cmd_repl,
cmd_restore,
)


@click.group
def cmd_main():
"""
Group of commands for the RethinkDB database.
"""


cmd_main.add_command(cmd_dump, "dump")
cmd_main.add_command(cmd_export, "export")
cmd_main.add_command(cmd_import, "import")
cmd_main.add_command(cmd_index_rebuild, "index_rebuild")
cmd_main.add_command(cmd_repl, "repl")
cmd_main.add_command(cmd_restore, "restore")