cli: initial mockup

This commit is contained in:
Anna “CyberTailor” 2024-01-05 20:04:47 +05:00
parent 939a88525e
commit 28bbdf9774
Signed by: CyberTaIlor
GPG Key ID: E7B76EDC50864BB1
10 changed files with 277 additions and 0 deletions

8
.bumpversion.cfg Normal file
View File

@ -0,0 +1,8 @@
[bumpversion]
current_version = 0.1.0
commit = True
tag = True
tag_name = {new_version}
sign_tags = True
[bumpversion:file:find_work/__init__.py]

3
.bumpversion.cfg.license Normal file
View File

@ -0,0 +1,3 @@
SPDX-FileCopyrightText: 2024 Anna <cyber@sysrq.in>
SPDX-License-Identifier: CC0-1.0

16
.drone.yml Normal file
View File

@ -0,0 +1,16 @@
# SPDX-License-Identifier: CC0-1.0
# SPDX-FileCopyrightText: 2023 Anna <cyber@sysrq.in>
kind: pipeline
type: docker
name: default
workspace:
path: /tests
steps:
- name: test
image: 31z4/tox:4
user: root
commands:
- tox run

7
find_work/__init__.py Normal file
View File

@ -0,0 +1,7 @@
# SPDX-License-Identifier: WTFPL
# SPDX-FileCopyrightText: 2024 Anna <cyber@sysrq.in>
# No warranty
""" Personal advice utility for Gentoo package maintainers """
__version__ = "0.1.0"

49
find_work/__main__.py Normal file
View File

@ -0,0 +1,49 @@
# SPDX-License-Identifier: WTFPL
# SPDX-FileCopyrightText: 2024 Anna <cyber@sysrq.in>
# No warranty
from typing import Callable
import click
from click_aliases import ClickAliasedGroup
import find_work
import find_work.cli.repology
from find_work.cli import Options
def help_text(docstring: str) -> Callable:
"""
Override function's docstring.
:param docstring: new docstring
:return: decorated function
"""
def decorate(f: Callable) -> Callable:
f.__doc__ = docstring
return f
return decorate
@click.group(cls=ClickAliasedGroup,
context_settings={"help_option_names": ["-h", "--help"]})
@click.option("-I", "--installed", is_flag=True,
help="Only match installed packages.")
@click.version_option(find_work.__version__, "-V", "--version")
@click.pass_context
@help_text(find_work.__doc__)
def cli(ctx: click.Context, installed: bool) -> None:
ctx.ensure_object(Options)
ctx.obj.only_installed = installed
@cli.group(aliases=["rep", "r"], cls=ClickAliasedGroup)
@click.option("-r", "--repo", required=True,
help="Repository name on Repology.")
@click.pass_obj
def repology(options: Options, repo: str) -> None:
""" Use Repology to find work. """
options.repology.repo = repo
repology.add_command(find_work.cli.repology.outdated, aliases=["out", "o"])

21
find_work/cli/__init__.py Normal file
View File

@ -0,0 +1,21 @@
# SPDX-License-Identifier: WTFPL
# SPDX-FileCopyrightText: 2024 Anna <cyber@sysrq.in>
# No warranty
""" Modules implementing command-line functionality """
from dataclasses import dataclass, field
@dataclass
class RepologyOptions:
""" Repology subcommand options """
repo: str = ""
@dataclass
class Options:
""" Global options """
only_installed: bool = False
repology: RepologyOptions = field(default_factory=RepologyOptions)

15
find_work/cli/repology.py Normal file
View File

@ -0,0 +1,15 @@
# SPDX-License-Identifier: WTFPL
# SPDX-FileCopyrightText: 2024 Anna <cyber@sysrq.in>
# No warranty
""" CLI subcommands for everything Repology. """
import click
from find_work.cli import Options
@click.command()
@click.pass_obj
def outdated(options: Options) -> None:
""" Find outdated packages. """

79
man/find-work.1 Normal file
View File

@ -0,0 +1,79 @@
.\" SPDX-FileType: DOCUMENTATION
.\" SPDX-FileCopyrightText: 2024 Anna <cyber@sysrq.in>
.\" SPDX-License-Identifier: CC0-1.0
.\" No warranty
.Dd January 4, 2024
.Dt FIND-WORK 1
.Os
.Sh NAME
.Nm find-work
.Nd discover ebuilds to improve
.Sh SYNOPSIS
.Nm
.Op Fl hV
.Nm
.Op Fl I
.Ar module
.Op Ar arg ...
.Ar command
.Sh DESCRIPTION
.Nm
provides global and module-specific options.
Global options must precede the module name, and are as follows:
.Bl -tag -width tenletters
.It Fl h , -help
Display usage information and exit immediately.
.It Fl I , -installed
Only match installed packages.
.It Fl V , -version
Display program version and exit immediately.
.El
.Pp
The modules for
.Nm
are as follows:
.Bl -tag -width repology
.It Xo
.Cm repology
.Op Fl r Ar repo
.Ar command
.Xc
.Dl Pq alias: Cm rep , Cm r
.Pp
This module uses Repology API to find work.
.Pp
.Ar command
can be one of the following:
.Bl -tag -width Ds
.It Ic outdated Pq alias: Ic out , Ic o
Find outdated packages.
.El
.Pp
The options for
.Cm find-work repology
are as follows:
.Bl -tag -width Ds
.It Fl r Ar repo
Repository name on repology.
This option is required.
Some examples for Gentoo include:
.Bl -bullet -compact -width 1n
.It
.Ql gentoo
.It
.Ql gentoo_ovl_guru
.It
.Ql gentoo_ovl_pentoo
.It
.Ql gentoo_ovl_science
.El
.El
.Sh EXIT STATUS
.Ex -std
.Sh EXAMPLES
Find outdated GURU packages installed on your system using Repology data:
.Pp
.Dl "$ find-work repology -r gentoo_ovl_guru outdated"
.Sh AUTHORS
.An Anna
.Aq Mt cyber@sysrq.in

51
pyproject.toml Normal file
View File

@ -0,0 +1,51 @@
# SPDX-License-Identifier: CC0-1.0
# SPDX-FileCopyrightText: 2024 Anna <cyber@sysrq.in>
[build-system]
requires = ["flit_core >=3.2,<4"]
build-backend = "flit_core.buildapi"
[project]
name = "find-work"
authors = [
{name = "Anna", email = "cyber@sysrq.in"},
]
dynamic = ["version", "description"]
readme = "README.md"
license = {file = "LICENSE"}
requires-python = ">=3.10"
dependencies = [
"click",
"click-aliases",
]
classifiers = [
"Development Status :: 3 - Alpha",
"Environment :: Console",
"Intended Audience :: Developers",
"License :: DFSG approved",
"Operating System :: POSIX",
"Programming Language :: Python :: 3 :: Only",
"Topic :: System :: Software Distribution",
"Topic :: Utilities",
"Typing :: Typed",
]
keywords = ["gentoo", "ebuild", "repository", "maintainer"]
[project.scripts]
find-work = "find_work.__main__:cli"
[project.urls]
Home = "https://find-work.sysrq.in"
Source = "https://git.sysrq.in/find-work"
Issues = "https://bugs.sysrq.in/enter_bug.cgi?product=Software&component=find-work"
Changelog = "https://find-work.sysrq.in/release-notes.html"
[tool.mypy]
disallow_untyped_defs = true
no_implicit_optional = true
[[tool.mypy.overrides]]
module = [
"click_aliases",
]
ignore_missing_imports = true

28
tox.ini Normal file
View File

@ -0,0 +1,28 @@
# SPDX-License-Identifier: CC0-1.0
# SPDX-FileCopyrightText: 2023-2024 Anna <cyber@sysrq.in>
[tox]
minversion = 4.0
env_list = py3{10,11,12}, lint
[testenv]
description = run the tests
deps =
mypy
commands =
mypy find_work
[testenv:lint]
description = run the linters
skip_install = true
deps =
pycodestyle
pyflakes
reuse
commands =
reuse lint
pyflakes {posargs:find_work}
pycodestyle {posargs:find_work}
[pycodestyle]
max-line-length = 100