aboutsummaryrefslogtreecommitdiffhomepage
path: root/bwrap/config.pair.go
diff options
context:
space:
mode:
authorOphestra Umiker <cat@ophivana.moe>2024-09-30 00:23:57 +0900
committerOphestra Umiker <cat@ophivana.moe>2024-09-30 00:25:15 +0900
commitba76e2919b6791c78d2c1e79cb50dbc4731a5b00 (patch)
tree81bdf965e5372ffb84052cddb48c78d698c74ea8 /bwrap/config.pair.go
parentdf29068d1683e044fddf6dd0d0ec24018d66cdc6 (diff)
bwrap: implement argument builder
Signed-off-by: Ophestra Umiker <cat@ophivana.moe>
Diffstat (limited to 'bwrap/config.pair.go')
-rw-r--r--bwrap/config.pair.go54
1 files changed, 54 insertions, 0 deletions
diff --git a/bwrap/config.pair.go b/bwrap/config.pair.go
new file mode 100644
index 00000000..b0b1001b
--- /dev/null
+++ b/bwrap/config.pair.go
@@ -0,0 +1,54 @@
+package bwrap
+
+import "strconv"
+
+const (
+ SetEnv = iota
+
+ Bind
+ BindTry
+ DevBind
+ DevBindTry
+ ROBind
+ ROBindTry
+
+ Chmod
+
+ pairC
+)
+
+var pairArgs = func() (n [pairC]string) {
+ n[SetEnv] = "--setenv"
+
+ n[Bind] = "--bind"
+ n[BindTry] = "--bind-try"
+ n[DevBind] = "--dev-bind"
+ n[DevBindTry] = "--dev-bind-try"
+ n[ROBind] = "--ro-bind"
+ n[ROBindTry] = "--ro-bind-try"
+
+ n[Chmod] = "--chmod"
+
+ return
+}()
+
+func (c *Config) pairArgs() (n [pairC][][2]string) {
+ n[SetEnv] = make([][2]string, 0, len(c.SetEnv))
+ for k, v := range c.SetEnv {
+ n[SetEnv] = append(n[SetEnv], [2]string{k, v})
+ }
+
+ n[Bind] = c.Bind
+ n[BindTry] = c.BindTry
+ n[DevBind] = c.DevBind
+ n[DevBindTry] = c.DevBindTry
+ n[ROBind] = c.ROBind
+ n[ROBindTry] = c.ROBindTry
+
+ n[Chmod] = make([][2]string, 0, len(c.Chmod))
+ for path, octal := range c.Chmod {
+ n[Chmod] = append(n[Chmod], [2]string{strconv.Itoa(int(octal)), path})
+ }
+
+ return
+}