Skip to content

Commit

Permalink
Added docopt to CLI
Browse files Browse the repository at this point in the history
  • Loading branch information
BitterB0NG0 committed Oct 2, 2024
1 parent 787163e commit 48d5383
Show file tree
Hide file tree
Showing 14 changed files with 399 additions and 428 deletions.
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ dependencies = [
"pytest",
"Sphinx",
"sphinx_rtd_theme",
"docopt",
]

[project.urls]
Expand Down
1 change: 1 addition & 0 deletions src/pymcnp/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .ls import Ls
from .run import Run
from .inp import *

__all__ = [
"Ls",
Expand Down
2 changes: 1 addition & 1 deletion src/pymcnp/cli/_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def ERROR_INP_SYNTAX(msg: str) -> str:


def get_timestamp() -> str:
return datetime.date.today().strftime("%Y-%m-%d--%H-%M-%S")
return datetime.datetime.today().strftime("%Y-%m-%d--%H-%M-%S")


def error(msg):
Expand Down
7 changes: 3 additions & 4 deletions src/pymcnp/cli/_save.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import os.path

import pymcnp
from ..files import inp


class Save:
Expand Down Expand Up @@ -35,7 +35,7 @@ def get_save() -> dict:
if not os.path.isfile(path):
continue

inpts[alias] = (path, pymcnp.inp.Inp.from_mcnp_file(path))
inpts[alias] = (path, inp.Inp.from_mcnp_file(path))

return inpts

Expand All @@ -46,8 +46,7 @@ def set_save(inpts) -> None:
"""

output = ""
for alias, value in inpts.items():
path, inpt = value
for alias, (path, inpt) in inpts.items():
output += f"{alias} {path}\n"

with open(Save.PYMCNP_SAVE_FILE, "w") as file:
Expand Down
49 changes: 49 additions & 0 deletions src/pymcnp/cli/inp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
"""
``inp`` provides utilities for aliasing PyMCNP INP objects.
``inp`` contains the procedures for executing the ``pymcnp inp`` command. This
module underpins the CLI by simplifying commands.
"""


import sys

import docopt

from .. import files
from . import _io
from . import _save


PYMCNP_INP_DOC = f"""
Usage:
pymcnp inp ((--read <alias> <file>)|(--delete <alias>))
Options:
-r --read Read INP file and create alias.
-d --delete Delete alias.
"""


def main(argv: list[str] = sys.argv[1:]) -> None:
"""
``main`` executes the ``pymcnp inp`` command.
``main`` processes the given command line arguments, and creates or deletes
PyMCNP aliased INP objects.
Parameters:
argv: Tokenized list of CLI arguments.
"""

args = docopt.docopt(PYMCNP_INP_DOC, argv=argv)
aliases = _save.Save.get_save()

if args["--read"]:
# Adding alias to save.
aliases[args["<alias>"]] = (args["<file>"], files.inp.Inp.from_mcnp_file(args["<file>"]))
elif args["--delete"]:
# Removing alias from save.
aliases.pop(args["<alias>"])

_save.Save.set_save(aliases)
171 changes: 0 additions & 171 deletions src/pymcnp/cli/inpt.py

This file was deleted.

Loading

0 comments on commit 48d5383

Please sign in to comment.