Skip to content

Commit

Permalink
Merge pull request licenses#4 from seapagan/add-table-output
Browse files Browse the repository at this point in the history
Add prettier output for the listing of licenses and languages
  • Loading branch information
seapagan authored Aug 19, 2024
2 parents d94c7fe + e94db1c commit 126ba9a
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 12 deletions.
48 changes: 37 additions & 11 deletions lice2/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
from pathlib import Path
from typing import IO, Union

from rich.console import Console
from rich.table import Table
from rich.text import Text

try:
from pkg_resources import resource_listdir, resource_stream # type: ignore
except ImportError:
Expand Down Expand Up @@ -122,7 +126,7 @@ def resource_listdir(
"ruby": ["=begin", "", "=end"],
"text": ["", "", ""],
"unix": ["", "#", ""],
"rust": ["", "//" ""],
"rust": ["", "//", ""],
}


Expand Down Expand Up @@ -403,6 +407,36 @@ def get_lang(args: argparse.Namespace) -> str:
return lang


def list_licences() -> None:
"""List available licenses and their template variables."""
table = Table(title="Available Licenses")
table.add_column("License Name")
table.add_column("Variables")
for license_name in LICENSES:
template = load_package_template(license_name)
var_list = extract_vars(template)
table.add_row(license_name, ", ".join(var_list))
# sys.stdout.write("{} : {}\n".format(license_name, ",
# ".join(var_list)))

console = Console()
console.print(table)

sys.exit(0)


def list_languages() -> None:
"""List available source code formatting languages."""
console = Console(width=80)
languages = sorted(LANGS.keys())
text = Text(", ".join(languages))
console.print(
"The following source code formatting languages are supported:\n"
)
console.print(text)
sys.exit(0)


def main() -> None:
"""Main program loop."""
args = get_args()
Expand All @@ -423,19 +457,11 @@ def main() -> None:

# list available licenses and their template variables
if args.list_licenses:
for license_name in LICENSES:
template = load_package_template(license_name)
var_list = extract_vars(template)
sys.stdout.write(
"{} : {}\n".format(license_name, ", ".join(var_list))
)
sys.exit(0)
list_licences()

# list available source formatting languages
if args.list_languages:
for lang in sorted(LANGS.keys()):
sys.stdout.write(f"{lang}\n")
sys.exit(0)
list_languages()

# create context
if args.template_path:
Expand Down
69 changes: 68 additions & 1 deletion poetry.lock

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

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ lice = "lice2:main"

[tool.poetry.dependencies]
python = "^3.9"
rich = "^13.7.1"

[tool.poetry.group.dev.dependencies]
# linting, type-checking and security checks
Expand Down
4 changes: 4 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ filelock==3.15.4 ; python_version >= "3.9" and python_version < "4.0"
identify==2.6.0 ; python_version >= "3.9" and python_version < "4.0"
importlib-metadata==8.2.0 ; python_version >= "3.9" and python_version < "3.10"
iniconfig==2.0.0 ; python_version >= "3.9" and python_version < "4.0"
markdown-it-py==3.0.0 ; python_version >= "3.9" and python_version < "4.0"
mdurl==0.1.2 ; python_version >= "3.9" and python_version < "4.0"
mock==5.1.0 ; python_version >= "3.9" and python_version < "4.0"
mypy-extensions==1.0.0 ; python_version >= "3.9" and python_version < "4.0"
mypy==1.11.1 ; python_version >= "3.9" and python_version < "4.0"
Expand All @@ -19,6 +21,7 @@ platformdirs==4.2.2 ; python_version >= "3.9" and python_version < "4.0"
pluggy==1.5.0 ; python_version >= "3.9" and python_version < "4.0"
poethepoet==0.27.0 ; python_version >= "3.9" and python_version < "4.0"
pre-commit==3.8.0 ; python_version >= "3.9" and python_version < "4.0"
pygments==2.18.0 ; python_version >= "3.9" and python_version < "4.0"
pymarkdownlnt==0.9.22 ; python_version >= "3.9" and python_version < "4.0"
pytest-cov==5.0.0 ; python_version >= "3.9" and python_version < "4.0"
pytest-mock==3.14.0 ; python_version >= "3.9" and python_version < "4.0"
Expand All @@ -27,6 +30,7 @@ pytest-reverse==1.7.0 ; python_version >= "3.9" and python_version < "4.0"
pytest-sugar==1.0.0 ; python_version >= "3.9" and python_version < "4.0"
pytest==8.3.2 ; python_version >= "3.9" and python_version < "4.0"
pyyaml==6.0.2 ; python_version >= "3.9" and python_version < "4.0"
rich==13.7.1 ; python_version >= "3.9" and python_version < "4.0"
ruff==0.6.1 ; python_version >= "3.9" and python_version < "4.0"
termcolor==2.4.0 ; python_version >= "3.9" and python_version < "4.0"
tomli==2.0.1 ; python_version >= "3.9" and python_version < "4.0"
Expand Down

0 comments on commit 126ba9a

Please sign in to comment.