Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
A High-performance, Generality, Humane Command Line Arguments Parser Library.
Alconna
is a powerful cli tool for parsing message chain or other raw message data. It is an overload version of CommandAnalysis
, affiliated to ArcletProject
.
Alconna
has a large number of built-in components and complex parsing functions. But do not afraid, you can use it as a simple command parser.
pip
$ pip install --upgrade arclet-alconna
$ pip install --upgrade arclet-alconna[full]
Official Document : 👉Link
Relevant Document : 📚Docs
from arclet.alconna import Alconna, Option, Subcommand, Args
cmd = Alconna(
"/pip",
Subcommand("install", Option("-U|--upgrade"), Args["pak", str]),
Option("list")
)
result = cmd.parse("/pip install numpy --upgrade") # This method returns an 'Arparma' class instance.
print(result.query('install')) # Or result.install
Output as follows:
value=None args={'pak': 'numpy'} options={'upgrade': value=Ellipsis args={}} subcommands={}
QQ Group: Link
71000~289000 msg/s
; test script: benchmarkExample of Callback Executor:
# callback.py
from arclet.alconna import Alconna, Args
alc = Alconna("callback", Args["foo", int]["bar", str])
@alc.bind()
def callback(foo: int, bar: str):
print(f"foo: {foo}")
print(f"bar: {bar}")
print(bar * foo)
if __name__ == "__main__":
alc()
$ python callback.py 3 hello
foo: 3
bar: hello
hellohellohello
Example of Type Conversion:
from arclet.alconna import Alconna, Args
from pathlib import Path
read = Alconna("read", Args["data", bytes])
@read.bind()
def cb(data: bytes):
print(type(data))
read.parse(["read", b'hello'])
read.parse("read test_fire.py")
read.parse(["read", Path("test_fire.py")])
'''
<class 'bytes'>
<class 'bytes'>
<class 'bytes'>
'''
Example of Component creation:
# component.py
from arclet.alconna import Alconna, Args, Option, Subcommand, store_true, count, append
alc = Alconna(
"component",
Args["path", str],
Option("--verbose|-v", action=count),
Option("-f", Args["flag", str], compact=True, action=append),
Subcommand("sub", Option("bar", action=store_true, default=False))
)
if __name__ == '__main__':
res = alc()
print(res.query("path"))
print(res.query("verbose.value"))
print(res.query("f.flag"))
print(res.query("sub"))
$ python component.py /home/arclet -vvvv -f1 -f2 -f3 sub bar
/home/arclet
4
['1', '2', '3']
(value=Ellipsis args={} options={'bar': (value=True args={})} subcommands={})
Example of Command Shortcut:
# shortcut.py
from arclet.alconna import Alconna, Args
alc = Alconna("eval", Args["content", str])
alc.shortcut("echo", {"command": "eval print(\\'{*}\\')"})
@alc.bind()
def cb(content: str):
eval(content, {}, {})
if __name__ == '__main__':
alc()
$ python shortcut.py eval print(\"hello world\")
hello world
$ python shortcut.py echo hello world!
hello world!
Example of Command Completion:
# completion.py
from arclet.alconna import Alconna, Args, Option
alc = Alconna("complete", Args["bar", int]) + Option("foo") + Option("fool")
if __name__ == "__main__":
alc()
$ python completion.py ?
suggest input follows:
* bar: int
* --help
* -h
* foo
* fool
Example of typing
Support:
from typing import Annotated # or typing_extensions.Annotated
from arclet.alconna import Alconna, Args
alc = Alconna("test", Args.foo[Annotated[int, lambda x: x % 2 == 0]])
alc.parse("test 2")
alc.parse("test 3")
'''
'foo': 2
ParamsUnmatched: param 3 is incorrect
'''
Example of FuzzyMatch:
# fuzzy.py
from arclet.alconna import Alconna, CommandMeta, Arg
alc = Alconna('!test_fuzzy', Arg("foo", str), meta=CommandMeta(fuzzy_match=True))
if __name__ == "__main__":
alc()
$ python fuzzy.py /test_fuzzy foo bar
/test_fuzy not matched. Are you mean "!test_fuzzy"?
Name | File |
---|---|
Calculate | calculate.py |
Execute | exec_code.py |
Request Route | endpoint.py |
Image Search | img_search.py |
PIP | pip.py |
Database Query | exec_sql.py |
Alconna is licensed under the MIT License.
FAQs
A High-performance, Generality, Humane Command Line Arguments Parser Library.
We found that arclet-alconna demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.