Skip to content

Commit

Permalink
idk just random stuff for me to fix me git issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Zomatree authored Aug 25, 2019
1 parent ddd85bc commit 01cc4d6
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 6 deletions.
4 changes: 1 addition & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,5 @@ but for now clone the repo

#### TODO
[x] flags

[x] options

[] intergration with typing to allow to use them for typhints, ie `Optinal`
[] intergration with typing to allow to use them for typhints, ie `Optinal`
7 changes: 4 additions & 3 deletions actioneer/action.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import Callable, Any, List, Dict
from typing import Callable, Any, List, Dict, Union
from inspect import Parameter, signature
from .utils import identity, bool_from_str
from .argument import Argument
Expand Down Expand Up @@ -27,7 +27,8 @@ def __init__(self, func, aliases: List[str] = [], *,

overrides = {
Parameter.empty: identity,
bool: bool_from_str
bool: bool_from_str,
Union: union_converter
}

def get_cast(self, param):
Expand All @@ -47,7 +48,7 @@ def invoke(self, args: List[str] = [], ctx: List[Any] = []):
if v.kind == Parameter.KEYWORD_ONLY}

ctxs = {name: ctx[value] for name, value in name_annots.items()}
args =
args = self.make_cast(args)
self.func(*args, **ctxs)
except Exception as e:
if self.error_handler:
Expand Down
22 changes: 22 additions & 0 deletions actioneer/typehints.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class BaseTypehint:
def __init__():
pass

def __getitem__(self, keys):
self.types = keys

def convert(self, arg):
for type in self.types:
try:
if type is None:
return None
return type(arg)
except:
pass


Union = BaseTypehint()


def a(b: Union[str, int]):
pass
2 changes: 2 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[metadata]
description-file = README.md
26 changes: 26 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from distutils.core import setup
setup(
name = 'actioneer', # How you named your package folder (MyLib)
packages = ['actioneer'], # Chose the same as "name"
version = '0.5', # Start with a small number and increase it with every change you make
license='MIT', # Chose a license from here: https://help.github.com/articles/licensing-a-repository
description = 'TYPE YOUR DESCRIPTION HERE', # Give a short description about your library
author = 'YOUR NAME', # Type in your name
author_email = 'your.email@domain.com', # Type in your E-Mail
url = 'https://github.com/user/reponame', # Provide either the link to your github or to your website
download_url = 'https://github.com/user/reponame/archive/v_01.tar.gz', # I explain this later on
keywords = ['SOME', 'MEANINGFULL', 'KEYWORDS'], # Keywords that define your package best
install_requires=[ # I get to this in a second
'validators',
'beautifulsoup4',
],
classifiers=[
'Development Status :: 3 - Alpha', # Chose either "3 - Alpha", "4 - Beta" or "5 - Production/Stable" as the current state of your package
'Intended Audience :: Developers', # Define that your audience are developers
'Topic :: Software Development :: Build Tools',
'License :: OSI Approved :: MIT License', # Again, pick a license
'Programming Language :: Python :: 3', #Specify which pyhton versions that you want to support
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
],
)
39 changes: 39 additions & 0 deletions showcase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import actioneer
import typing


handler = actioneer.Performer([1, True]) # inits the command handler,
# the argument is preset contexts that will be passed to the command
# you can subclass Perfomer and overwride the "split_args", "get_options"
# and "get_flags"


def echo(*msg, message: str, flags: actioneer.Flags, options: actioneer.Options): # kwargs will be treated as contexts that will be passed to the command, this system used the annotations to find what to set as what
print(" ".join(msg))
print(message)
print(flags)
print(options)
raise Exception("qwertjk")

# NOTE: all contexts are optional so you might set a context but it doesnt need to be set as a kwarg


echo = actioneer.Command(echo, flags=["test"], options={"channel": typing.Optional[int]}, performer=handler) # this will most likly be wrapped in other libs that use this
handler.register(echo) # adds it to the command handler


@handler.error
def bruh(e, *, message: str):
print(e)
print(message)


echo.invoke([""], ["bruh (the 'message', kwarg", actioneer.Flags({"test": True})])
handler.run("echo hello world -test --channel 123", ["bruh"]) # there is cmd.invoke but that doesnt handle arguments, flags and options
# ^ (1) ^ (2) ^ (3) ^ (4) ^ (5)
# 1 - command name
# 2 - command args
# 3 - flag
# 4 - option
# 5 - extra command context's that can be set when being invoked, ie channel,
# message ect

0 comments on commit 01cc4d6

Please sign in to comment.