Skip to content

Commit

Permalink
refactor: add leading underscore to private functions
Browse files Browse the repository at this point in the history
  • Loading branch information
mecaneer23 committed Dec 31, 2023
1 parent c6cecf8 commit 1a6ae5f
Showing 1 changed file with 45 additions and 45 deletions.
90 changes: 45 additions & 45 deletions src/get_args.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,42 +7,42 @@
try:
from curses import wrapper # pyright: ignore

DEFAULT_TKINTER_GUI = False
_DEFAULT_TKINTER_GUI = False
except ImportError:

def wrapper(_: Any) -> str:
return CHECKBOX_OPTIONS[1]
return _CHECKBOX_OPTIONS[1]

DEFAULT_TKINTER_GUI = True # pyright: ignore[reportConstantRedefinition]
_DEFAULT_TKINTER_GUI = True # pyright: ignore[reportConstantRedefinition]

from src.md_to_py import md_table_to_lines

DEFAULT_BULLETS: bool = False
_DEFAULT_BULLETS: bool = False
CONTROLS_BEGIN_INDEX: int = 68
CONTROLS_END_INDEX: int = 96
DEFAULT_ENUMERATE: bool = False
DEFAULT_FILENAME: Path = Path("todo.txt")
DEFAULT_HEADER: str = ""
DEFAULT_HELP_FILE: Path = Path(__file__).parent.parent.joinpath("README.md").absolute()
DEFAULT_INDENT: int = 2
DEFAULT_NO_GUI: bool = False
DEFAULT_RELATIVE_ENUMERATE: bool = False
DEFAULT_SIMPLE_BOXES: bool = False
DEFAULT_STRIKETHROUGH: bool = False
_DEFAULT_ENUMERATE: bool = False
_DEFAULT_FILENAME: Path = Path("todo.txt")
_DEFAULT_HEADER: str = ""
_DEFAULT_HELP_FILE: Path = Path(__file__).parent.parent.joinpath("README.md").absolute()
_DEFAULT_INDENT: int = 2
_DEFAULT_NO_GUI: bool = False
_DEFAULT_RELATIVE_ENUMERATE: bool = False
_DEFAULT_SIMPLE_BOXES: bool = False
_DEFAULT_STRIKETHROUGH: bool = False

CHECKBOX_OPTIONS = ("🗹", "☑")
_CHECKBOX_OPTIONS = ("🗹", "☑")


def _get_checkbox(win: Any) -> str:
try:
win.addch(0, 0, CHECKBOX_OPTIONS[0])
win.addch(0, 0, _CHECKBOX_OPTIONS[0])
win.clear()
return CHECKBOX_OPTIONS[0]
return _CHECKBOX_OPTIONS[0]
except TypeError:
return CHECKBOX_OPTIONS[1]
return _CHECKBOX_OPTIONS[1]


def get_args() -> Namespace:
def _get_args() -> Namespace:
parser = ArgumentParser(
description="Ndo is a todo list program to help you manage your todo lists",
add_help=False,
Expand All @@ -52,7 +52,7 @@ def get_args() -> Namespace:
md_table_to_lines(
CONTROLS_BEGIN_INDEX,
CONTROLS_END_INDEX,
str(DEFAULT_HELP_FILE),
str(_DEFAULT_HELP_FILE),
("<kbd>", "</kbd>"),
)
),
Expand All @@ -61,33 +61,33 @@ def get_args() -> Namespace:
"filename",
type=str,
nargs="?",
default=DEFAULT_FILENAME,
default=_DEFAULT_FILENAME,
help=f"Provide a filename to store the todo list in.\
Default is `{DEFAULT_FILENAME}`.",
Default is `{_DEFAULT_FILENAME}`.",
)
parser.add_argument(
"--bullet-display",
"-b",
action="store_true",
default=DEFAULT_BULLETS,
default=_DEFAULT_BULLETS,
help=f"Boolean: determine if Notes are displayed with\
a bullet point in front or not. Default is `{DEFAULT_BULLETS}`.",
a bullet point in front or not. Default is `{_DEFAULT_BULLETS}`.",
)
parser.add_argument(
"--enumerate",
"-e",
action="store_true",
default=DEFAULT_ENUMERATE,
default=_DEFAULT_ENUMERATE,
help=f"Boolean: determines if todos are numbered when\
printed or not. Default is `{DEFAULT_ENUMERATE}`.",
printed or not. Default is `{_DEFAULT_ENUMERATE}`.",
)
parser.add_argument(
"--tk-gui",
"-g",
action="store_true",
default=DEFAULT_TKINTER_GUI,
default=_DEFAULT_TKINTER_GUI,
help=f"Boolean: determine if curses (False) or tkinter gui\
(True) should be used. Default is `{DEFAULT_TKINTER_GUI}`.",
(True) should be used. Default is `{_DEFAULT_TKINTER_GUI}`.",
)
parser.add_argument(
"--help",
Expand All @@ -98,61 +98,61 @@ def get_args() -> Namespace:
parser.add_argument(
"--help-file",
type=str,
default=DEFAULT_HELP_FILE,
default=_DEFAULT_HELP_FILE,
help=f"Allows passing alternate file to\
specify help menu. Default is `{DEFAULT_HELP_FILE}`.",
specify help menu. Default is `{_DEFAULT_HELP_FILE}`.",
)
parser.add_argument(
"--indentation-level",
"-i",
type=int,
default=DEFAULT_INDENT,
default=_DEFAULT_INDENT,
help=f"Allows specification of indentation level. \
Default is `{DEFAULT_INDENT}`.",
Default is `{_DEFAULT_INDENT}`.",
)
parser.add_argument(
"--no-gui",
"-n",
action="store_true",
default=DEFAULT_NO_GUI,
default=_DEFAULT_NO_GUI,
help=f"Boolean: If true, do not start a curses gui,\
rather, just print out the todo list. Default is\
`{DEFAULT_NO_GUI}`.",
`{_DEFAULT_NO_GUI}`.",
)
parser.add_argument(
"--relative-enumeration",
"-r",
action="store_true",
default=DEFAULT_RELATIVE_ENUMERATE,
default=_DEFAULT_RELATIVE_ENUMERATE,
help=f"Boolean: determines if todos are numbered\
when printed. Numbers relatively rather than\
absolutely. Default is `{DEFAULT_RELATIVE_ENUMERATE}`.",
absolutely. Default is `{_DEFAULT_RELATIVE_ENUMERATE}`.",
)
parser.add_argument(
"--simple-boxes",
"-x",
action="store_true",
default=DEFAULT_SIMPLE_BOXES,
default=_DEFAULT_SIMPLE_BOXES,
help=f"Boolean: allow rendering simpler checkboxes if\
terminal doesn't support default ascii checkboxes.\
Default is `{DEFAULT_SIMPLE_BOXES}`.",
Default is `{_DEFAULT_SIMPLE_BOXES}`.",
)
parser.add_argument(
"--strikethrough",
"-s",
action="store_true",
default=DEFAULT_STRIKETHROUGH,
default=_DEFAULT_STRIKETHROUGH,
help=f"Boolean: strikethrough completed todos\
- option to disable because some terminals\
don't support strikethroughs. Default is\
`{DEFAULT_STRIKETHROUGH}`.",
`{_DEFAULT_STRIKETHROUGH}`.",
)
parser.add_argument(
"--title",
"-t",
type=str,
nargs="+",
default=DEFAULT_HEADER,
default=_DEFAULT_HEADER,
help="Allows passing alternate header.\
Default is filename.",
)
Expand All @@ -161,21 +161,21 @@ def get_args() -> Namespace:
return Namespace(**args)


def parse_filename(filename: str) -> Path:
def _parse_filename(filename: str) -> Path:
path = Path(filename)
if path.is_dir():
return path.joinpath(DEFAULT_FILENAME)
return path.joinpath(_DEFAULT_FILENAME)
return path


command_line_args = get_args()
command_line_args = _get_args()
BULLETS: bool = command_line_args.bullet_display
CHECKBOX: str = command_line_args.checkbox
ENUMERATE: bool = command_line_args.enumerate
FILENAME: Path = parse_filename(command_line_args.filename)
FILENAME: Path = _parse_filename(command_line_args.filename)
HEADER: str = (
FILENAME.as_posix()
if command_line_args.title == DEFAULT_HEADER
if command_line_args.title == _DEFAULT_HEADER
else " ".join(command_line_args.title)
)
HELP_FILE: Path = Path(command_line_args.help_file)
Expand Down

0 comments on commit 1a6ae5f

Please sign in to comment.