Skip to content

Commit

Permalink
Improve CLI flags.
Browse files Browse the repository at this point in the history
- Add a `--version` flag.
- Print flags usage by default.
- Move version from setup.py to lib.
  • Loading branch information
knadh committed Oct 26, 2021
1 parent 4eae343 commit 8db0e98
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
13 changes: 12 additions & 1 deletion dirmaker/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
import sys

from jinja2 import Template

import yaml

__version__ = "1.0.0"

class Taxonomy:
def __init__(self, name, slug, count):
Expand Down Expand Up @@ -251,6 +251,8 @@ def main():
description="A simple static site generator for generating directory websites.",
formatter_class=argparse.ArgumentDefaultsHelpFormatter)

p.add_argument("-v", "--version", action="store_true", dest="version", help="display version")

n = p.add_argument_group("new")
n.add_argument("-n", "--new", action="store_true",
dest="new", help="initialize a new site")
Expand All @@ -268,8 +270,17 @@ def main():
dest="data", help="path to the data file")
b.add_argument("-o", "--output", action="store", type=str, default="site",
dest="output", help="path to the output directory")

if len(sys.argv) == 1:
p.print_help()
p.exit()

args = p.parse_args()

if args.version:
print("v{}".format(__version__))
quit()

if args.new:
exdir = os.path.join(os.path.dirname(__file__), "example")
if not os.path.isdir(exdir):
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python
from codecs import open
from setuptools import setup
from dirmaker import __version__

README = open("README.md").read()

Expand All @@ -12,7 +13,7 @@ def requirements():

setup(
name="dirmaker",
version="0.1.3",
version=__version__,
description="A simple static site generator for generating directory websites.",
long_description=README,
long_description_content_type="text/markdown",
Expand Down

0 comments on commit 8db0e98

Please sign in to comment.