Skip to content

CLI: click -> argparse #400

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 8 commits into from
Oct 2, 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
18 changes: 15 additions & 3 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,18 @@ $ pipx install --suffix=@next 'vcspull' --pip-args '\--pre' --force

- _Add your latest changes from PRs here_

**Maintenance release, no features or fixes**

### Internal

- Move from click to :mod:{argparse}

Click was more difficult to control and workwith, ironically.

### Packaging

- Drop click dependency (#400)

## vcspull v1.14.0 (2022-10-01)

**Maintenance release, no features or fixes**
Expand Down Expand Up @@ -230,7 +242,7 @@ Patch branch: [`v1.12.x`](https://github.com/vcs-python/vcspull/tree/v1.12.x)

### Fix

- Tab-completion for repository names and configurations
- Tab-completion for repository names and configurations (retracted in v1.15)

## vcspull 1.11.1 (2022-03-12)

Expand Down Expand Up @@ -272,7 +284,7 @@ Patch branch: [`v1.12.x`](https://github.com/vcs-python/vcspull/tree/v1.12.x)

### Improvements

- Experimental completion, see {ref}`completion`:
- Experimental completion (retracted in v1.15):

- Completion for sync:

Expand All @@ -281,7 +293,7 @@ Patch branch: [`v1.12.x`](https://github.com/vcs-python/vcspull/tree/v1.12.x)

### Documentation

- Added {ref}`completion`:
- Added completion:

## vcspull 1.9.0 (2022-02-26)

Expand Down
27 changes: 0 additions & 27 deletions docs/cli/completion.md

This file was deleted.

7 changes: 0 additions & 7 deletions docs/cli/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,3 @@ vcspull

sync
```

```{toctree}
:caption: More
:maxdepth: 1

completion
```
17 changes: 10 additions & 7 deletions docs/cli/sync.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@

# vcspull sync

## Command

```{eval-rst}
.. argparse::
:module: vcspull.cli
:func: create_parser
:prog: vcspull
:path: sync
```

## Filtering repos

As of 1.13.x, `$ vcspull sync` with no args passed will show a help dialog:
Expand Down Expand Up @@ -80,10 +90,3 @@ Print traceback for errored repos:
```console
$ vcspull --log-level DEBUG sync --exit-on-error grako django
```

```{eval-rst}
.. click:: vcspull.cli.sync:sync
:prog: vcspull sync
:commands: sync
:nested: full
```
11 changes: 8 additions & 3 deletions docs/cli/vcspull.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@
# vcspull

```{eval-rst}
.. click:: vcspull.cli:cli
:prog: Usage
:nested: none
.. argparse::
:module: vcspull.cli
:func: create_parser
:prog: vcspull
:nosubcommands:

subparser_name : @replace
See :ref:`cli-sync`
```
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"sphinx.ext.todo",
"sphinx.ext.napoleon",
"sphinx.ext.linkcode",
"sphinx_click.ext", # sphinx-click
"sphinxarg.ext", # sphinx-argparse
"sphinx_inline_tabs",
"sphinx_copybutton",
"sphinxext.opengraph",
Expand Down
39 changes: 20 additions & 19 deletions poetry.lock

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

6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ vcspull = 'vcspull:cli.cli'

[tool.poetry.dependencies]
python = "^3.9"
click = "~8"
libvcs = "~0.17.0"
colorama = ">=0.3.9"

Expand All @@ -70,7 +69,6 @@ furo = "*"
gp-libs = "0.0.1a16"
sphinx-autobuild = "*"
sphinx-autodoc-typehints = "*"
sphinx-click = "*"
sphinx-inline-tabs = "*"
sphinxext-opengraph = "*"
sphinx-copybutton = "*"
Expand Down Expand Up @@ -105,7 +103,6 @@ types-colorama = "*"
[tool.poetry.extras]
docs = [
"sphinx",
"sphinx-click",
"sphinx-autodoc-typehints",
"sphinx-autobuild",
"sphinxext-rediraffe",
Expand All @@ -129,6 +126,9 @@ lint = [
"types-colorama",
]

[tool.poetry.group.dev.dependencies]
sphinx-argparse = "^0.3.1"

[tool.mypy]
python_version = 3.9
warn_unused_configs = true
Expand Down
65 changes: 39 additions & 26 deletions src/vcspull/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,52 @@
~~~~~~~~~~~

"""
import argparse
import logging

import click

from libvcs.__about__ import __version__ as libvcs_version

from ..__about__ import __version__
from ..log import setup_logger
from .sync import sync
from .sync import create_sync_subparser, sync

log = logging.getLogger(__name__)


@click.group(
context_settings={
"obj": {},
"help_option_names": ["-h", "--help"],
}
)
@click.option(
"--log-level",
default="INFO",
help="Log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)",
)
@click.version_option(
__version__,
"-V",
"--version",
message=f"%(prog)s %(version)s, libvcs {libvcs_version}",
)
def cli(log_level):
setup_logger(log=log, level=log_level.upper())


# Register sub-commands here
cli.add_command(sync)
def create_parser():
parser = argparse.ArgumentParser(prog="vcspull")
parser.add_argument(
"--version",
"-V",
action="version",
version=f"%(prog)s {__version__}, libvcs {libvcs_version}",
)
parser.add_argument(
"--log-level",
action="store",
default="INFO",
help="Log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)",
)
subparsers = parser.add_subparsers(dest="subparser_name")
sync_parser = subparsers.add_parser("sync")
create_sync_subparser(sync_parser)

return parser


def cli(args=None):
parser = create_parser()
args = parser.parse_args(args)

setup_logger(log=log, level=args.log_level.upper())

if args.subparser_name is None:
parser.print_help()
return
elif args.subparser_name == "sync":
sync(
repo_terms=args.repo_terms,
config=args.config,
exit_on_error=args.exit_on_error,
parser=parser,
)
Loading