Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.43 KB | None | 0 0
  1. """ PyArgs
  2. """
  3.  
  4. ## Imports
  5. from __future__ import (
  6.     annotations
  7. )
  8. from typing import (
  9.     List, Callable, Optional
  10. )
  11.  
  12.  
  13. ## Constants
  14. __title__ = "PyArgs"
  15. __author__ = "Ryan Smith"
  16. __version__ = [
  17.     1, 0, 0
  18. ]
  19.  
  20.  
  21. ## Functions
  22. def Find_Abbreviation(
  23.     _str: str,
  24.     _list: List[str]
  25. ) -> Optional[str]:
  26.     """
  27.    """
  28.  
  29.     for char in _str:
  30.         char = char.lower()
  31.         if (char not in _list):
  32.             return char
  33.         char = char.upper()
  34.         if (char not in _list):
  35.             return char
  36.     return None
  37.  
  38.  
  39. ## Classes
  40. class Argument(
  41.     object
  42. ):
  43.     """
  44.    """
  45.  
  46.     # -Constructor
  47.     def __init__(
  48.         self,
  49.         identifier: str
  50.     ) -> Argument:
  51.         '''
  52.        '''
  53.  
  54.         pass
  55.  
  56.     # -Instance Methods
  57.  
  58.  
  59. class Builder(
  60.     object
  61. ):
  62.     """
  63.    """
  64.  
  65.     def __init__(
  66.         self
  67.     ):
  68.         '''
  69.        '''
  70.  
  71.         pass
  72.  
  73.  
  74. class ListParser(
  75.     object
  76. ):
  77.     """
  78.    """
  79.  
  80.     # -Constructor
  81.     def __init__(
  82.         self,
  83.         prefix: str = "-",
  84.         auto_abbrev: bool = True,
  85.         exit_on_error: bool = True
  86.     ) -> ListParser:
  87.         '''
  88.        '''
  89.  
  90.         # -Internal Variables
  91.         self._args = []
  92.         self._abbrevs = []
  93.         self._prefix = prefix
  94.         self._auto_abbrev = auto_abbrev
  95.         self._exit_on_error = exit_on_error
  96.  
  97.     # -Instance Methods
  98.     def add_argument(
  99.         self,
  100.         name: str,
  101.         output: str = None,
  102.         shorthand: str = None,
  103.         parent: Argument = None,
  104.         func: Callable = None,
  105.       **kwargs
  106.     ) -> Argument:
  107.         '''
  108.        '''
  109.  
  110.         ## Creating Abbreviation
  111.         # -User Registered
  112.         if (shorthand is not None):
  113.             if (shorthand not in self._abbrevs):
  114.                 self._abbrevs.append(shorthand)
  115.             else:
  116.                 raise SyntaxError(
  117.                     "TEMP ERROR"
  118.                 )
  119.         # -Auto-Generated
  120.         elif (
  121.             (self._auto_abbrev) and
  122.             (shorthand is None)
  123.         ):
  124.             # Find appropriate shorthand
  125.             rst = Find_Abbreviation(
  126.                 name,
  127.                 self._abbrevs
  128.             )
  129.             # Set shorthand
  130.             if (rst is not None):
  131.                 shorthand = rst
  132.                 self._abbrevs.append(rst)
  133.             # Raise warning
  134.             else:
  135.                 raise SyntaxWarning(
  136.                     "TEMP WARNING"
  137.                 )
  138.  
  139.         ## Creating Argument
  140.         arg = Argument(
  141.             name,
  142.           **kwargs
  143.         )
  144.  
  145.         ## Debug
  146.         _str = f"['{name}'"
  147.         if (shorthand is not None):
  148.             _str += f", '{shorthand}'"
  149.         _str += "]"
  150.         print(_str)
  151.         if (func is not None):
  152.             print(func)
  153.  
  154.         ## Return
  155.         self._args.append(arg)
  156.         return arg
  157.  
  158.     def build(
  159.         self,
  160.         _list: List[str]
  161.     ) -> None:
  162.         '''
  163.        '''
  164.  
  165.         pass
  166.  
  167.  
  168. class CLIParser(
  169.     ListParser
  170. ):
  171.     """
  172.    """
  173.  
  174.     # -Constructor
  175.     def __init__(
  176.         self,
  177.         description: str,
  178.         exit_on_error: bool = True
  179.     ) -> CLIParser:
  180.         '''
  181.        '''
  182.  
  183.         pass
  184.  
  185.     # -Instance Methods
  186.     def build(
  187.         self
  188.     ):
  189.         '''
  190.        '''
  191.  
  192.         from sys import argv as _args
  193.         ListParser.build(
  194.             self,
  195.             _args
  196.         )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement