Skip to content

Commit aca4fda

Browse files
committed
docs(proposal): LE-002 improved potfile
1 parent 1ce0c46 commit aca4fda

File tree

1 file changed

+51
-9
lines changed

1 file changed

+51
-9
lines changed

proposals/LE-002-potfile-scripting.md

+51-9
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,24 @@ Every project has specific jobs to be done. These jobs are often repetitive and
1414

1515
## Proposed Solution
1616

17-
Within the `Potfile`, new commands that execute a specific Lithia file as a script can be defined using the `pots.cmds.script` function. Additional help context can be provided on the existing command. The command can be executed using `lithia [script]` or `lithia run [script]`.
17+
Within the `Potfile`, new commands that execute a specific Lithia file as a script can be defined using the `pots.cmds.add` function. Additional help context can be provided inside a builder function. The command can be executed using `lithia [script]` or `lithia run [script]`.
1818

1919
```lithia
20-
let testCmd = cmds.script "test", "cmd/test.lithia"
21-
testCmd.summary "runs all tests"
22-
testCmd.flag "verbose", "verbose logging"
23-
testCmd.env "LITHIA_TESTS", "1"
20+
cmds.add "test", { c =>
21+
c.script "cmd/test.lithia"
22+
c.summary "runs all tests"
23+
c.env "LITHIA_TESTS", "1"
24+
c.flag "verbose", { f =>
25+
f.short "v"
26+
f.summary "verbose logging"
27+
}
28+
}
29+
30+
cmds.add "build", { c =>
31+
c.bin "docker"
32+
c.args ["build", "-t", "my-image", "."]
33+
c.summary "builds the project using docker"
34+
}
2435
```
2536

2637
Similar, the `pots.cmds.bin` function can be used to define a command that executes a binary. Under the hood `/usr/bin/env` will be used to lookup the binary. In case of `lithia` itself, the currently executed `lithia` binary will be used.
@@ -38,16 +49,38 @@ The execution of the Potfile takes place in a sandboxed environment which whitel
3849

3950
To avoid privilege escalation, scripts declared in the `Potfile` with overridden `LITHIA_TIMEOUT` or `LITHIA_EXTERNAL_DEFINITIONS`, can only restrict the environment further. They cannot allow more access to the environment.
4051

52+
Under the hood, the default `bin` target will be lithia itself.
53+
4154
## Changes to the Standard Library
4255

4356
Adds a new module `pot.cmds`:
4457

45-
- _func_ `script alias, path` - returns a `MutableCommand`.
46-
- _func_ `bin alias, path` - returns a `MutableCommand`.
47-
- _data_ `MutableCommand` - a mutable command that can be used to configure the command.
58+
- _func_ `add name, conf` - returns a `Command`.
59+
- _data_ `CommandBuilder`
4860
- _func_ `summary text` - sets the summary text for the command.
49-
- _func_ `flag name, description` - adds a flag to the command.
61+
- _func_ `flag name, conf` - adds a flag to the command.
5062
- _func_ `env name, value` - adds an environment variable to the command.
63+
- _func_ `bin name` - sets the binary to be executed.
64+
- _func_ `script path` - sets the script to be executed.
65+
- _func_ `args args` - sets the arguments to be passed to the binary.
66+
- _data_ `FlagBuilder`
67+
- _func_ `short name` - sets the short name of the flag.
68+
- _func_ `summary text` - sets the summary text for the flag.
69+
- _func_ `default value` - sets the default value for the flag.
70+
- _func_ `required bool` - sets the flag to be required.
71+
- _data_ `Command`
72+
- _let_ `name` - the name of the command.
73+
- _let_ `summary` - the summary text of the command.
74+
- _let_ `flags` - a dict of flags.
75+
- _let_ `envs` - a dict of environment variables.
76+
- _let_ `bin` - the name of the binary to be executed.
77+
- _let_ `args` - the arguments to be passed to the binary.
78+
- _data_ `Flag`
79+
- _let_ `name` - the name of the flag.
80+
- _let_ `short` - the short name of the flag.
81+
- _let_ `summary` - the summary text of the flag.
82+
- _let_ `default` - the default value of the flag.
83+
- _let_ `required` - whether the flag is required.
5184

5285
Other non-final additions are internal and include:
5386

@@ -57,6 +90,15 @@ Other non-final additions are internal and include:
5790

5891
- `pot [script]`, `lithia run [script]` or `lithia pot [script]`
5992

93+
But also regarding the api used in the `Potfile` itself, there was an alternative considered:
94+
95+
```lithia
96+
let testCmd = cmds.script "test", "cmd/test.lithia"
97+
testCmd.summary "runs all tests"
98+
testCmd.flag "verbose", "verbose logging"
99+
testCmd.env "LITHIA_TESTS", "1"
100+
```
101+
60102
## Acknowledgements
61103

62104
`npm run [script]`, `yarn [script]`, `swift run [target]` and

0 commit comments

Comments
 (0)