Add context-aware shell helper package (fork of mage/sh)#1
Draft
Add context-aware shell helper package (fork of mage/sh)#1
Conversation
Copy all exported functions from github.com/magefile/mage/sh and add context.Context as the first parameter to every command-running function. The context is passed through to exec.CommandContext for cancellation and timeout support. Remove the dependency on github.com/magefile/mage/mg by inlining the verbose check and fatal error type. Agent-Logs-Url: https://github.com/magefile/shx/sessions/f0fda061-9670-4a20-a708-2ab74aa13234 Co-authored-by: natefinch <3185864+natefinch@users.noreply.github.com>
Agent-Logs-Url: https://github.com/magefile/shx/sessions/f0fda061-9670-4a20-a708-2ab74aa13234 Co-authored-by: natefinch <3185864+natefinch@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
natefinch
May 7, 2026 21:26
View session
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR creates a context-aware fork of
github.com/magefile/mage/shas a standalone Go package atgithub.com/magefile/shx.What changed
Every exported function that runs a command now accepts a
context.Contextas its first parameter. The context is passed through toexec.CommandContext, giving callers proper control over timeouts, cancellation, and deadlines.Key design decisions
context.Contexton all command functions —Run,RunV,RunWith,RunWithV,Output,OutputWith,Execall takectxas their first parameter. The closures returned byRunCmdandOutCmdalso accept a context.mage/mgdependency — Themg.Verbose()check is inlined (readsMAGEFILE_VERBOSEenv var directly) andmg.Fatalf()is replaced with a localfatalErrortype that implements the sameExitStatus() intinterface. This makesshxa zero-dependency package.RmandCopydon't execute commands, so they don't need a context parameter.TestContextCancellationverifies that a cancelled context properly terminates a running command.Files
cmd.gocontext.Contextsupporthelpers.goRm,Copy) — unchanged from originalcmd_test.gohelpers_test.gotestmain_test.gogo.modREADME.mdTesting
All 17 tests pass: