You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: proposals/LE-002-potfile-scripting.md
+51-9
Original file line number
Diff line number
Diff line change
@@ -14,13 +14,24 @@ Every project has specific jobs to be done. These jobs are often repetitive and
14
14
15
15
## Proposed Solution
16
16
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]`.
18
18
19
19
```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
+
}
24
35
```
25
36
26
37
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
38
49
39
50
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.
40
51
52
+
Under the hood, the default `bin` target will be lithia itself.
53
+
41
54
## Changes to the Standard Library
42
55
43
56
Adds a new module `pot.cmds`:
44
57
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`
48
60
-_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.
50
62
-_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.
51
84
52
85
Other non-final additions are internal and include:
53
86
@@ -57,6 +90,15 @@ Other non-final additions are internal and include:
57
90
58
91
-`pot [script]`, `lithia run [script]` or `lithia pot [script]`
59
92
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
+
60
102
## Acknowledgements
61
103
62
104
`npm run [script]`, `yarn [script]`, `swift run [target]` and
0 commit comments