Debian Codegraph @

docs/source/vs_arguably/global_state/README.rst

raw
1 ============
2 Global State
3 ============
4
5 Unlike Cyclopts or Typer, with ``arguably`` you directly jump into decorating functions:
6
7
8 .. code-block:: python
9
10 import arguably
11
12
13 @arguably.command
14 def some_function(required, not_required=2, *others: int, option: float = 3.14):
15 """
16 this function is on the command line!
17
18 Args:
19 required: a required argument
20 not_required: this one isn't required, since it has a default value
21 *others: all the other positional arguments go here
22 option: [-x] keyword-only args are options, short name is in brackets
23 """
24 print(f"{required=}, {not_required=}, {others=}, {option=}")
25
26
27 if __name__ == "__main__":
28 arguably.run()
29
30 With Arguably, no application object is created.
31 This immediately becomes an issue if you use a library that uses arguably on import.
32
33 Lets consider the following file:
34
35 .. code-block:: python
36
37 # library_using_arguably.py
38 import arguably
39
40
41 @arguably.command
42 def some_library_function(name):
43 print(f"{name=}")
44
45
46 if __name__ == "__main__":
47 arguably.run()
48
49 .. code-block:: console
50
51 $ python library_using_arguably.py foo
52 name='foo'
53
54 So this by itself works fine, but lets create another script that imports this library:
55
56 .. code-block:: python
57
58 import arguably
59 import library_using_arguably
60
61
62 @arguably.command
63 def my_function(name):
64 print(f"{name=}")
65
66
67 if __name__ == "__main__":
68 arguably.run()
69
70 Now, lets check the help screen:
71
72 .. code-block:: console
73
74 $ python my-script.py --help
75 usage: my-script.py [-h] command ...
76
77 positional arguments:
78 command
79 some-library-function
80 my-function
81
82 options:
83 -h, --help show this help message and exit
84
85 The two CLI applications got combined into one, making Arguably dangerous for CLIs that are also libraries.