Skip to content

Commit

Permalink
+xlib.appargs
Browse files Browse the repository at this point in the history
  • Loading branch information
iperov committed Sep 9, 2021
1 parent 8843d87 commit 071bf80
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
3 changes: 3 additions & 0 deletions xlib/appargs/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
"""
"""
from .appargs import get_arg_bool, get_arg_str, set_arg_bool, set_arg_str
17 changes: 17 additions & 0 deletions xlib/appargs/appargs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import os

def set_arg_str(name : str, value : str):
os.environ[name] = value

def set_arg_bool(name : str, value : bool):
set_arg_str(name, '1' if value else '0')

def get_arg_str(name : str, default = None) -> str:
return os.environ.get(name, default)

def get_arg_bool(name : str, default = False) -> bool:
x = get_arg_str(name, default=None)
if x is None:
return default
return bool(int(x))

0 comments on commit 071bf80

Please sign in to comment.