Skip to content

Commit 3b56efe

Browse files
committed
Making keyword arguments required
1 parent fdc1114 commit 3b56efe

File tree

19 files changed

+84
-73
lines changed

19 files changed

+84
-73
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,11 +119,11 @@ Enable an Apache module:
119119
```python
120120
from uplaybook import fs, core, pyinfra
121121

122-
core.playbook_args(
122+
core.playbook_args(options=[
123123
core.Argument(name="module_name", description="Name of module"),
124124
core.Argument(name="remove", type="bool", default=False,
125125
description="Remove the module rather than install it"),
126-
)
126+
])
127127

128128
def restart_and_enable_apache():
129129
pyinfra.systemd.service(service="apache2", restarted=True, enabled=True)

docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ uPlaybook playbooks are written in Python but follow some specific conventions:
1919
- Declare desired state rather than imperatively defining steps
2020
- Tasks communicate if they changed something
2121
- Changed tasks can trigger handlers
22-
- Jinja2 templating with
22+
- Jinja2 templating of many argument values
2323
- Status output
2424

2525
To get started, see the [Getting Started Guide](getting_started.md)

docs/playbooks/basics.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ fs.cp(src="site.conf.j2", path="/etc/apache2/sites-available/site.conf").notify(
178178
Playbooks can include arguments and options for customizing the playbook run. For
179179
example:
180180

181-
core.playbook_args(
181+
core.playbook_args(options=[
182182
core.Argument(name="playbook_name",
183183
description="Name of playbook to create, creates directory of this name."),
184184
core.Argument(name="git", default=False, type="bool",
@@ -188,7 +188,7 @@ example:
188188
core.Argument(name="force", default=False, type="bool",
189189
description="Reset the playbook back to the default if it "
190190
"already exists (default is to abort if playbook already exists)."),
191-
)
191+
])
192192

193193
This set up an argument of "playbook_name" and options of "--git", "--single-file", and
194194
"--force".

docs/tutorial.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,9 @@ specified on the command-line:
173173
```python
174174
from uplaybook import pyinfra, fs, core, ARGS # <-- Need "core, ARGS" now
175175

176-
core.playbook_args(
176+
core.playbook_args(options=[
177177
core.Argument(name="module_name"),
178-
)
178+
])
179179

180180
def restart_apache():
181181
pyinfra.systemd.service(service="apache2", restarted=True)
@@ -343,7 +343,7 @@ fs.cp(dst="{{ dirname | default('/var/lib/my_project') }}/my_project.config")
343343

344344
### Keyword Arguments
345345

346-
To make playbooks more clear, it's a convention to always use the argument keyword name:
346+
To make playbooks more clear, it's required to always use the argument keyword name:
347347

348348
```python
349349
fs.cp(src="foo", dst="bar")
@@ -391,6 +391,7 @@ to the blog webserver.
391391

392392
from uplaybook import core
393393

394+
# this is needed for "--help" to work
394395
core.playbook_args()
395396

396397
[...]

examples/apt-thirdparty-install/playbook

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,13 @@ from uplaybook import fs, core, pyinfra, ARGS
1111
import sys
1212

1313
core.playbook_args(
14-
core.Argument(
15-
name="package-name", description="Name of the package to install.", default=None
16-
),
14+
options=[
15+
core.Argument(
16+
name="package-name",
17+
description="Name of the package to install.",
18+
default=None,
19+
),
20+
]
1721
)
1822

1923
packages = {

examples/install-apache-module/playbook

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,18 @@ Apache modules need to be installed, configured, and Apache restarted to
77
take effect. This does all of that.
88
"""
99

10-
from uplaybook import fs, core, pyinfra
10+
from uplaybook import fs, core, pyinfra, ARGS
1111

1212
core.playbook_args(
13-
core.Argument(name="module_name", description="Name of module"),
14-
core.Argument(
15-
name="remove",
16-
type="bool",
17-
default=False,
18-
description="Remove the module rather than install it",
19-
),
13+
options=[
14+
core.Argument(name="module_name", description="Name of module"),
15+
core.Argument(
16+
name="remove",
17+
type="bool",
18+
default=False,
19+
description="Remove the module rather than install it",
20+
),
21+
]
2022
)
2123

2224

examples/new-uplaybook/playbook

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ used as a skeleton to create new uplaybooks.
99

1010
from uplaybook import fs, core, ARGS
1111

12-
core.playbook_args(
12+
core.playbook_args(options=[
1313
core.Argument(name="playbook_name",
1414
description="Name of playbook to create, creates directory of this name."),
1515
core.Argument(name="git", default=False, type="bool",
@@ -19,7 +19,7 @@ core.playbook_args(
1919
core.Argument(name="force", default=False, type="bool",
2020
description="Reset the playbook back to the default if it already "
2121
"exists (default is to abort if playbook already exists)."),
22-
)
22+
])
2323

2424
if ARGS.git and ARGS.single_file:
2525
core.fail(msg="*** ERROR: Cannot do '--git' with '--single-file'.")

examples/new-uplaybook/playbook.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ from uplaybook import fs, core
1010

1111
# example arguments
1212
# This sets up the playbook to be called as "up playbook <NAME> [--force] [--optional=foo]"
13-
core.playbook_args(
13+
core.playbook_args(options=[
1414
core.Argument(name="name", description="Name of subdirectory"),
1515
core.Argument(name="force", default=False, type="bool", description="Reset if already exists?"),
1616
core.Argument(name="optional", default="default", description="Optional argument"),
17-
)
17+
])

tests/test_basics/args.pb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
#!/usr/bin/env -S python3 -m uplaybook.cli
22

3-
from uplaybook import fs, core
3+
from uplaybook import fs, core, ARGS
44

5-
core.playbook_args(
5+
core.playbook_args(options=[
66
core.Argument(name="release_name"),
77
core.Argument(name="arg1", default=False, type="bool"),
88
core.Argument(name="arg2", default="default"),
99
core.Argument(name="arg3", default="default"),
1010
core.Argument(name="is_owner", default=False, type="bool"),
11-
)
11+
])
1212
#eval "$UP2 args.pb" release --arg1 --arg2=value || RETCODE=$?
1313

14-
core.debug("{{ARGS}}")
14+
core.debug(msg="{{ARGS}}")
1515
assert ARGS.release_name == "release"
1616
assert ARGS.arg1 == True
1717
assert ARGS.arg2 == "value"

tests/test_basics/basics.pb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ fs.rm(path="testdir", recursive=True)
66
fs.mkdir(path="testdir")
77
with fs.cd(path="testdir"):
88
fs.cp(path="testfile")
9-
assert fs.exists("testfile")
9+
assert fs.exists(path="testfile")
1010

1111
core.run(command="date")
1212
r = core.run(command="true")
@@ -15,7 +15,7 @@ r = core.run(command="false", ignore_failure=True)
1515
assert not r
1616

1717
var = "bar"
18-
r = core.render("foo{{ var }}")
18+
r = core.render(s="foo{{ var }}")
1919
assert r == "foobar"
2020
core.debug(msg="Expanding template: {{var}}")
2121
core.print(msg="Expanding template: {{var}}")
@@ -35,5 +35,5 @@ assert not test_handler.ran
3535
core.flush_handlers()
3636
assert test_handler.ran
3737

38-
core.exit(0)
39-
core.run("false") # if control gets here, the exit above didn't work
38+
core.exit(returncode=0)
39+
core.run(command="false") # if control gets here, the exit above didn't work

0 commit comments

Comments
 (0)