Closed carusooo closed 1 year ago
I would like to expand upon @carusooo's idea (hello, fellow Andy 👋) by also exposing --dry-run
flag as environment variable, too. This is essential in order to build safe processes beyond changing content to know whether to affect change or not.
Looking at the code in repo-operations.go
, this should be fairly straight forward to include after setting cmd.Dir
:
Maybe this looks something like:
func executeCommandWithLogger(config *config.GitXargsConfig, repositoryDir string, repo *github.Repository, logger *logrus.Logger) error {
if len(config.Args) < 1 {
return errors.WithStackTrace(types.NoCommandSuppliedErr{})
}
cmdArgs := config.Args
cmd := exec.Command(cmdArgs[0], cmdArgs[1:]...)
cmd.Dir = repositoryDir
cmd.Env = os.Environ()
cmd.Env = append(cmd.Environ(), fmt.Sprintf("XARGS_REPO_NAME=%s", repo.GetName()))
cmd.Env = append(cmd.Environ(), fmt.Sprintf("XARGS_DRY_RUN=%s", config.DryRun))
logger.WithFields(logrus.Fields{
"Repo": repo.GetName(),
"Directory": repositoryDir,
"Command": config.Args,
}).Debug("Executing command against local clone of repo...")
stdoutStdErr, err := cmd.CombinedOutput()
git-xargs --help
usage statement```shell $ git-xargs.exe --help Usage: git-xargs.exe [--loglevel] [--github-org] [--draft] [--dry-run] [--skip-pull-requests] [--skip-archived-repos] [--repo] [--repos] [--branch-name] [--base-branch-name] [--commit-message] [--pull-request-title] [--pull-request-description] [--reviewers] [--team-reviewers] [--seconds-between-prs] [--max-pr-retries] [--seconds-to-wait-when-rate-limited] [--no-skip-ci] [--keep-cloned-repositories] [--help] command [options] [args] git-xargs is a command-line tool (CLI) for making updates across multiple Github repositories with a single command. Commands: help, h Shows a list of commands or help for one command ```
@zackproser : any particular concerns with this approach ☝️? should there be a prefix / namespace for the env vars to avoid clashing with other concerns?
@carusooo : check out https://github.com/gruntwork-io/git-xargs/pull/127 :fishsticks:
Describe the solution you'd like Set the current repo as an environment variable that can be accessed while processing. From the logs it looks like this is available at invocation time
Describe alternatives you've considered I could parse this out of the
cwd
, but that seems brittle since there's a lot of nonces to prevent collisionsI could also invoke a git command and poke at the output, that involves too much shell cruft and line noise.
Additional context
It's possible this is already implemented or could be solved simpler than I envision.