Skip to content

Commit 01cc4d6

Browse files
authored
idk just random stuff for me to fix me git issue
1 parent ddd85bc commit 01cc4d6

File tree

6 files changed

+94
-6
lines changed

6 files changed

+94
-6
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,5 @@ but for now clone the repo
1818

1919
#### TODO
2020
[x] flags
21-
2221
[x] options
23-
24-
[] intergration with typing to allow to use them for typhints, ie `Optinal`
22+
[] intergration with typing to allow to use them for typhints, ie `Optinal`

actioneer/action.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Callable, Any, List, Dict
1+
from typing import Callable, Any, List, Dict, Union
22
from inspect import Parameter, signature
33
from .utils import identity, bool_from_str
44
from .argument import Argument
@@ -27,7 +27,8 @@ def __init__(self, func, aliases: List[str] = [], *,
2727

2828
overrides = {
2929
Parameter.empty: identity,
30-
bool: bool_from_str
30+
bool: bool_from_str,
31+
Union: union_converter
3132
}
3233

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

4950
ctxs = {name: ctx[value] for name, value in name_annots.items()}
50-
args =
51+
args = self.make_cast(args)
5152
self.func(*args, **ctxs)
5253
except Exception as e:
5354
if self.error_handler:

actioneer/typehints.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class BaseTypehint:
2+
def __init__():
3+
pass
4+
5+
def __getitem__(self, keys):
6+
self.types = keys
7+
8+
def convert(self, arg):
9+
for type in self.types:
10+
try:
11+
if type is None:
12+
return None
13+
return type(arg)
14+
except:
15+
pass
16+
17+
18+
Union = BaseTypehint()
19+
20+
21+
def a(b: Union[str, int]):
22+
pass

setup.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[metadata]
2+
description-file = README.md

setup.py

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

showcase.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import actioneer
2+
import typing
3+
4+
5+
handler = actioneer.Performer([1, True]) # inits the command handler,
6+
# the argument is preset contexts that will be passed to the command
7+
# you can subclass Perfomer and overwride the "split_args", "get_options"
8+
# and "get_flags"
9+
10+
11+
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
12+
print(" ".join(msg))
13+
print(message)
14+
print(flags)
15+
print(options)
16+
raise Exception("qwertjk")
17+
18+
# NOTE: all contexts are optional so you might set a context but it doesnt need to be set as a kwarg
19+
20+
21+
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
22+
handler.register(echo) # adds it to the command handler
23+
24+
25+
@handler.error
26+
def bruh(e, *, message: str):
27+
print(e)
28+
print(message)
29+
30+
31+
echo.invoke([""], ["bruh (the 'message', kwarg", actioneer.Flags({"test": True})])
32+
handler.run("echo hello world -test --channel 123", ["bruh"]) # there is cmd.invoke but that doesnt handle arguments, flags and options
33+
# ^ (1) ^ (2) ^ (3) ^ (4) ^ (5)
34+
# 1 - command name
35+
# 2 - command args
36+
# 3 - flag
37+
# 4 - option
38+
# 5 - extra command context's that can be set when being invoked, ie channel,
39+
# message ect

0 commit comments

Comments
 (0)