Add cli and version.py

This commit is contained in:
Jacob Hinkle 2022-09-18 19:41:48 -04:00
parent cde9a9056c
commit cbb8180ff3
5 changed files with 49 additions and 4 deletions

View File

@ -1,8 +1,7 @@
import sqlite3 import sqlite3
from . import db from .db import init
from .version import __version__
__version__ = "0.0.1"
# Calling code will build up a large DAG then at the very last step, call # Calling code will build up a large DAG then at the very last step, call
@ -10,7 +9,7 @@ __version__ = "0.0.1"
# data by asking the user for an output dir. However, we need a database # data by asking the user for an output dir. However, we need a database
# initialized in order to build up the DAG in the first place, so here we # initialized in order to build up the DAG in the first place, so here we
# initialize an in-memory database to use until we have an output directory. # initialize an in-memory database to use until we have an output directory.
_conn = db.init(":memory:") _conn = init(":memory:")
def save_data( def save_data(

4
nancy/__main__.py Normal file
View File

@ -0,0 +1,4 @@
if __name__ == "__main__":
from . import cli
cli.main()

28
nancy/cli/__init__.py Normal file
View File

@ -0,0 +1,28 @@
import click
from ..version import __version__
from .freeze import freeze, thaw
# from https://click.palletsprojects.com/en/5.x/advanced/
class AliasedGroup(click.Group):
def get_command(self, ctx, cmd_name):
rv = click.Group.get_command(self, ctx, cmd_name)
if rv is not None:
return rv
matches = [x for x in self.list_commands(ctx) if x.startswith(cmd_name)]
if not matches:
return None
elif len(matches) == 1:
return click.Group.get_command(self, ctx, matches[0])
ctx.fail("Too many matches: %s" % ", ".join(sorted(matches)))
@click.group(f"nancy v{__version__}", cls=AliasedGroup)
def main():
pass
main.add_command(freeze)
main.add_command(thaw)

13
nancy/cli/freeze.py Normal file
View File

@ -0,0 +1,13 @@
import click
@click.command()
@click.argument("directory")
def freeze(directory):
pass
@click.command()
@click.argument("files", nargs=-1) # , help="Files or directories to thaw.")
def thaw(files):
pass

1
nancy/version.py Normal file
View File

@ -0,0 +1 @@
__version__ = "0.0.1pre"