Skip to content

Enhancement: flag for project level variables #520

Open

Description

@thorntonrose

Describe the feature:

I suggest adding a flag for specifying project level variables.

Example CLI usage:

mage -D pkg=./foo -D tests=TestBar test

Example Magefile usage:

func Test() {
   sh.cmd("bash", "-c", fmt.Sprintf("go test -run %s %s", tests, pkg))
}

Many other build tools do this or some variant.

What problem does this feature address?

This feature addresses the problem that environment variables have to be used for user specified, project level variables.

How does this benefit users of Mage?

Mage user can specify project level variables in a way that is not shell specific, for example mage test -D tests=TestFoo instead of TESTS=TestFoo mage test.

Additional context:

None.

Activity

  1. thorntonrose commented on Mar 2, 2025

    @thorntonrose
    Author

    I would like to work on this feature.

  2. changed the title [-]Enhancement: flag for key/value pairs (properties)[/-] [+]Enhancement: flag for project level properties (key/value pairs)[/+] on Mar 2, 2025
  3. changed the title [-]Enhancement: flag for project level properties (key/value pairs)[/-] [+]Enhancement: flag for project level variables[/+] on Mar 2, 2025
  4. TwFlem commented on Apr 11, 2025

    @TwFlem

    This would be a nice way to express overrides for any underlying configuration within a mage command. It would also be a nice way to keep the interface of a command the same, but express some other execution context.

    For example, let's say I have an imaginary mage namespace for sql that has a command called syncusers that allows me to sync some external data with a user in some relational database. To keep all of the tooling consistent, let's say I also want to leverage syncusers for manual testing during development and scaffolding during test automation. To achieve this, I may want to have a setup where syncusers executes locally by default, but I may provide a -remote option for doing the real deal in CI/CD.

    So locally I may just run

    mage sql:syncusers dev

    But in CI/CD I may run

    mage sql:syncusers prod -remote

    To add to @thorntonrose's feature and benefits above, it would be nice if the interface for a mage command could match that of the interface for running a normal go binary. It would make it easier for people to port their existing binaries over to mage commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions