Skip to content

Commit a4951b1

Browse files
blink-so[bot]f0ssel
andcommitted
remove Run convenience method from jail interface
Simplified the jail package interface by removing the Run() method: ## Changes - Removed jail.Run() convenience method from jail.go - Updated CLI to use explicit Start() -> Execute() -> Stop() pattern - Added proper defer j.Stop() for cleanup in CLI ## Rationale Keeping the interface explicit and minimal: - Start() - Initialize the jail environment - Execute() - Run command in jail (requires Start() first) - Stop() - Cleanup resources This makes the lifecycle clear and gives users full control over when initialization and cleanup happen. ## Usage Pattern Co-authored-by: f0ssel <[email protected]>
1 parent b0e7507 commit a4951b1

File tree

3 files changed

+9
-14
lines changed

3 files changed

+9
-14
lines changed

cli/cli.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,14 @@ func Run(config Config, args []string) error {
9494
return fmt.Errorf("failed to create jail: %v", err)
9595
}
9696

97-
// Run the command in the jail
98-
return j.Run(args, nil)
97+
// Start the jail
98+
if err := j.Start(); err != nil {
99+
return fmt.Errorf("failed to start jail: %v", err)
100+
}
101+
defer j.Stop()
102+
103+
// Execute the command in the jail
104+
return j.Execute(args, nil)
99105
}
100106

101107
// setupLogging configures and returns a logger based on the log level

jail

9.61 MB
Binary file not shown.

jail.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -250,17 +250,6 @@ func (j *Jail) Execute(command []string, additionalEnv map[string]string) error
250250
return nil
251251
}
252252

253-
// Run is a convenience method that combines Start() and Execute().
254-
// It starts the jail, executes the command, and automatically cleans up.
255-
func (j *Jail) Run(command []string, additionalEnv map[string]string) error {
256-
if err := j.Start(); err != nil {
257-
return err
258-
}
259-
defer j.Stop()
260-
261-
return j.Execute(command, additionalEnv)
262-
}
263-
264253
// Stop gracefully shuts down the jail and cleans up resources.
265254
func (j *Jail) Stop() error {
266255
if j.cleanedUp {
@@ -292,4 +281,4 @@ func (j *Jail) Stop() error {
292281
j.cleanedUp = true
293282
j.logger.Debug("Jail stopped successfully")
294283
return nil
295-
}
284+
}

0 commit comments

Comments
 (0)